diff --git a/labs/bbb-webrtc-sfu/lib/base/BaseProvider.js b/labs/bbb-webrtc-sfu/lib/base/BaseProvider.js index 45dcfe1c33035e6098a44284ff4a0297747ff1e4..0d7bf23b3a102587fafab99a11fab4c2278e8fba 100644 --- a/labs/bbb-webrtc-sfu/lib/base/BaseProvider.js +++ b/labs/bbb-webrtc-sfu/lib/base/BaseProvider.js @@ -4,6 +4,7 @@ const C = require('../bbb/messages/Constants'); const Logger = require('../utils/Logger'); const EventEmitter = require('events').EventEmitter; const errors = require('../base/errors'); +const config = require('config'); module.exports = class BaseProvider extends EventEmitter { constructor () { @@ -53,4 +54,12 @@ module.exports = class BaseProvider extends EventEmitter { } = error; return type && id && role && streamId && code && reason; } + + getRecordingPath (room, subPath, recordingName) { + const format = config.get('recordingFormat'); + const basePath = config.get('recordingBasePath'); + const timestamp = (new Date()).getTime(); + + return `${basePath}/${subPath}/${room}/${recordingName}-${timestamp}.${format}` + } }; diff --git a/labs/bbb-webrtc-sfu/lib/mcs-core/lib/media/MCSApiStub.js b/labs/bbb-webrtc-sfu/lib/mcs-core/lib/media/MCSApiStub.js index c6b48ebdd6d0bd35221ada291280962009fc2202..1c3d5befeadcb0279532a83dc08e27d4b960d227 100644 --- a/labs/bbb-webrtc-sfu/lib/mcs-core/lib/media/MCSApiStub.js +++ b/labs/bbb-webrtc-sfu/lib/mcs-core/lib/media/MCSApiStub.js @@ -92,13 +92,13 @@ module.exports = class MCSApiStub extends EventEmitter { } } - async startRecording(userId, mediaId, recordingName) { + async startRecording(userId, mediaId, recordingPath) { try { - const answer = await this._mediaController.startRecording(userId, mediaId, recordingName); + const answer = await this._mediaController.startRecording(userId, mediaId, recordingPath); return (answer); } catch (error) { - throw (this._handleError(error, 'startRecording', { userId, mediaId, recordingName })); + throw (this._handleError(error, 'startRecording', { userId, mediaId, recordingPath})); } } diff --git a/labs/bbb-webrtc-sfu/lib/mcs-core/lib/media/MediaController.js b/labs/bbb-webrtc-sfu/lib/mcs-core/lib/media/MediaController.js index 70bc2c61fb5a9fa03b12de4276b40c37050b5ca2..1f3332e6798085374865c7843c3ddcc3c3488e87 100644 --- a/labs/bbb-webrtc-sfu/lib/mcs-core/lib/media/MediaController.js +++ b/labs/bbb-webrtc-sfu/lib/mcs-core/lib/media/MediaController.js @@ -107,15 +107,11 @@ module.exports = class MediaController { Logger.info("[mcs-controller] PublishAndSubscribe return a SDP session with ID", session.id); resolve({userId, sessionId}); + session.sessionStarted(); } catch (err) { reject(this._handleError(err)); } - finally { - if (typeof err === 'undefined' && session) { - session.sessionStarted(); - } - } }); } @@ -215,29 +211,28 @@ module.exports = class MediaController { } } - async startRecording (userId, sourceId, recordingName) { - Logger.info("[mcs-controller] startRecording ", sourceId); - try { - const user = await this.getUserMCS(userId); - const sourceSession = this.getMediaSession(sourceId); + startRecording (userId, sourceId, recordingPath) { - const session = await user.addRecording(recordingName); - const answer = await user.startSession(session.id); - await sourceSession.connect(session._mediaElement); + return new Promise(async (resolve, reject) => { + try { + Logger.info("[mcs-controller] startRecording ", sourceId); + const user = await this.getUserMCS(userId); + const sourceSession = this.getMediaSession(sourceId); - sourceSession.subscribedSessions.push(session.id); - this._mediaSessions[session.id] = session; + const session = await user.addRecording(recordingPath); + const answer = await user.startSession(session.id); + await sourceSession.connect(session._mediaElement); - return Promise.resolve(answer); - } - catch (err) { - return Promise.reject(this._handleError(err)); - } - finally { - if (typeof err === 'undefined' && session) { + sourceSession.subscribedSessions.push(session.id); + this._mediaSessions[session.id] = session; + + resolve(answer); session.sessionStarted(); } - } + catch (err) { + reject(this._handleError(err)); + } + }); } async stopRecording (userId, sourceId, recId) { diff --git a/labs/bbb-webrtc-sfu/lib/mcs-core/lib/model/RecordingSession.js b/labs/bbb-webrtc-sfu/lib/mcs-core/lib/model/RecordingSession.js index a9bea76d3757af905b5c230a4ac4da59329bc0ac..b358f70ec0a51c73c97267f2a5b42fa888a98d94 100644 --- a/labs/bbb-webrtc-sfu/lib/mcs-core/lib/model/RecordingSession.js +++ b/labs/bbb-webrtc-sfu/lib/mcs-core/lib/model/RecordingSession.js @@ -9,9 +9,9 @@ const config = require('config'); const MediaSession = require('./MediaSession'); module.exports = class RecordingSession extends MediaSession { - constructor(emitter, room, recordingName) { - let uri = RecordingSession.getRecordingPath(room, 'medium', recordingName); - let options = { + constructor(emitter, room, recordingPath) { + const uri = recordingPath; + const options = { mediaProfile: config.get('recordingMediaProfile'), uri: uri, stopOnEndOfStream: true @@ -21,23 +21,6 @@ module.exports = class RecordingSession extends MediaSession { this.filename = uri; } - static getRecordingPath (room, profile, recordingName) { - const format = config.get('recordingFormat'); - const basePath = config.get('recordingBasePath'); - const timestamp = (new Date()).getTime(); - - let isScreenshare = (name) => { - return name.match(/^[0-9]+-SCREENSHARE$/); - }; - - if (isScreenshare(recordingName)) { - return `${basePath}/screenshare/${room}/${recordingName}-${timestamp}.${format}` - } else { - return `${basePath}/recordings/${room}/${profile}-${recordingName}-${timestamp}.${format}`; - } - - } - async process () { const answer = await this._MediaServer.startRecording(this._mediaElement); return Promise.resolve({ recordingId: this.id, filename: this.filename, meetingId: this.room }); diff --git a/labs/bbb-webrtc-sfu/lib/mcs-core/lib/model/SfuUser.js b/labs/bbb-webrtc-sfu/lib/mcs-core/lib/model/SfuUser.js index a7f4dda5134c05eff8cb4912695529c32cfae147..2d1f917a296e76ea77febbf2444aa5f38459ae26 100644 --- a/labs/bbb-webrtc-sfu/lib/mcs-core/lib/model/SfuUser.js +++ b/labs/bbb-webrtc-sfu/lib/mcs-core/lib/model/SfuUser.js @@ -66,8 +66,9 @@ module.exports = class SfuUser extends User { return session; } - addRecording (recordingName) { - const session = new RecordingSession(this.emitter, this.roomId, recordingName); + addRecording (recordingPath) { + try { + const session = new RecordingSession(this.emitter, this.roomId, recordingPath); this.emitter.emit(C.EVENT.NEW_SESSION+this.id, session.id); session.emitter.once(C.EVENT.MEDIA_SESSION_STOPPED, (sessId) => { @@ -81,6 +82,10 @@ module.exports = class SfuUser extends User { Logger.info("[mcs-sfu-user] Added new recording session", session.id, "to user", this.id); return session; + } + catch (err) { + this._handleError(err); + } } diff --git a/labs/bbb-webrtc-sfu/lib/screenshare/screenshare.js b/labs/bbb-webrtc-sfu/lib/screenshare/screenshare.js index f9e71e626d44bbf70bea0ec9efe758e92c7221b7..f2eaa8cc957533ac649516f195c1612846a281ce 100644 --- a/labs/bbb-webrtc-sfu/lib/screenshare/screenshare.js +++ b/labs/bbb-webrtc-sfu/lib/screenshare/screenshare.js @@ -53,6 +53,7 @@ module.exports = class Screenshare extends BaseProvider { this._rtmpBroadcastStarted = false; this.recording = {}; this.isRecorded = false; + this._recordingSubPath = 'screenshare'; this._BigBlueButtonGW.on(C.RECORDING_STATUS_REPLY_MESSAGE_2x+meetingId, (payload) => { Logger.info("[Screenshare] RecordingStatusReply ", payload.recorded); @@ -192,7 +193,8 @@ module.exports = class Screenshare extends BaseProvider { async startRecording() { return new Promise(async (resolve, reject) => { try { - this.recording = await this.mcs.startRecording(this.mcsUserId, this._presenterEndpoint, this._voiceBridge); + const recordingPath = this.getRecordingPath(this._meetingId, this._recordingSubPath, this._voiceBridge); + this.recording = await this.mcs.startRecording(this.mcsUserId, this._presenterEndpoint, recordingPath); this.mcs.on('MediaEvent' + this.recording.recordingId, this.recordingState.bind(this)); this.sendStartShareEvent(); resolve(this.recording); diff --git a/labs/bbb-webrtc-sfu/lib/video/video.js b/labs/bbb-webrtc-sfu/lib/video/video.js index 21ee09befbfab73cdf2cb1c8b22215445ca5a118..9250d86d90774f12d12590a6f0526ffe9b28171e 100644 --- a/labs/bbb-webrtc-sfu/lib/video/video.js +++ b/labs/bbb-webrtc-sfu/lib/video/video.js @@ -31,6 +31,8 @@ module.exports = class Video extends BaseProvider { this.status = C.MEDIA_STOPPED; this.recording = {}; this.isRecorded = false; + this._recordingSubPath = 'recordings'; + this._cameraProfile = 'medium'; this.candidatesQueue = []; this.notFlowingTimeout = null; @@ -197,7 +199,9 @@ module.exports = class Video extends BaseProvider { async startRecording() { return new Promise(async (resolve, reject) => { try { - this.recording = await this.mcs.startRecording(this.userId, this.mediaId, this.id); + const recordingName = this._cameraProfile + '-' + this.id; + const recordingPath = this.getRecordingPath(this.meetingId, this._recordingSubPath, recordingName); + this.recording = await this.mcs.startRecording(this.userId, this.mediaId, recordingPath); this.mcs.on('MediaEvent' + this.recording.recordingId, this.recordingState.bind(this)); this.sendStartShareEvent(); resolve(this.recording);