UNPKG

@techteamer/janus-api

Version:
70 lines (69 loc) 3.24 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const JanusPlugin_js_1 = __importDefault(require("../JanusPlugin.js")); const SdpHelper_js_1 = __importDefault(require("../SdpHelper.js")); class RecordPlayJanusPlugin extends JanusPlugin_js_1.default { constructor(logger, filterDirectCandidates = false) { super(logger); this.filterDirectCandidates = !!filterDirectCandidates; this.janusEchoBody = { audio: true, video: true }; this.pluginName = 'janus.plugin.recordplay'; this.sdpHelper = new SdpHelper_js_1.default(this.logger); } configure(videoBitrateMax = 1024 * 1024, videoKeyframeInterval = 15000) { return this.transaction('message', { body: { request: 'configure', 'video-bitrate-max': videoBitrateMax, 'video-keyframe-interval': videoKeyframeInterval } }, 'success').catch((err) => { this.logger.error('RecordPlayJanusPlugin, cannot configure', err); throw err; }); } onmessage(data, json) { if (data && data.recordplay === 'event' && data.result === 'done') { // okay, so the recording has ended this.janus.destroyPlugin(this).catch((err) => { this.logger.error('RecordPlayJanusPlugin, destroyPlugin error in onmessage', err); }); } else { this.logger.error('RecordPlayJanusPlugin got unknown message', data, json); } } consume(data) { if (data.type === 'message') { const sendData = { jsep: data.message.jsep, body: { request: 'record', name: 'hello' } }; this.transaction('message', sendData, 'event').then((ret) => { const { json, data } = ret; if (!data || !data.result || !data.result.id) { this.logger.error('RecordPlayJanusPlugin, no recording id in the transaction reply', ret); return; } this.emit('recordingId', data.result.id); if (!json || !json.jsep) { this.logger.error('RecordPlayJanusPlugin, no jsep in the transaction reply', ret); return; } const jsep = json.jsep; if (this.filterDirectCandidates && jsep.sdp) { jsep.sdp = this.sdpHelper.filterDirectCandidates(jsep.sdp); } this.emit('jsep', jsep); }); } else if (data.type === 'candidate') { if (this.filterDirectCandidates && data.message.candidate && this.sdpHelper.isDirectCandidate(data.message.candidate)) { return; } this.transaction('trickle', { candidate: data.message }); } else if (data.type === 'stop') { const sendData = { body: { request: 'stop' } }; this.transaction('message', sendData, 'event'); } else { this.logger.error('RecordPlayJanusPlugin unknown data type', data); } } } exports.default = RecordPlayJanusPlugin;