Added BaseProvider class to SFU and standard methods for marshalling mcs-core errors to SFU clients

This commit is contained in:
prlanzarin 2018-07-18 16:46:19 +00:00
parent f61102940e
commit 729d81eebb
5 changed files with 52 additions and 9 deletions

View File

@ -7,8 +7,10 @@ const MCSApi = require('../mcs-core/lib/media/MCSApiStub');
const C = require('../bbb/messages/Constants');
const Logger = require('../utils/Logger');
const Messaging = require('../bbb/messages/Messaging');
const BaseProvider = require('../base/BaseProvider');
const LOG_PREFIX = "[audio]";
module.exports = class Audio {
module.exports = class Audio extends BaseProvider {
constructor(_bbbGW, _id, voiceBridge) {
this.mcs = new MCSApi();
this.bbbGW = _bbbGW;
@ -32,6 +34,7 @@ module.exports = class Audio {
this.mcs.addIceCandidate(this.audioEndpoints[connectionId], _candidate);
}
catch (err) {
this._handleError(LOG_PREFIX, err);
Logger.error("[audio] ICE candidate could not be added to media controller.", err);
}
}
@ -52,6 +55,7 @@ module.exports = class Audio {
}
}
catch (err) {
this._handleError(LOG_PREFIX, err);
Logger.error("[audio] ICE candidate could not be added to media controller.", err);
}
}
@ -190,6 +194,7 @@ module.exports = class Audio {
return callback(null, sdpAnswer);
}
catch (err) {
this._handleError(LOG_PREFIX, err);
Logger.error("[audio] MCS returned error => " + err);
return callback(err);
}
@ -217,6 +222,7 @@ module.exports = class Audio {
return;
}
catch (err) {
this._handleError(LOG_PREFIX, err);
Logger.error('[audio] MCS returned error when trying to unsubscribe', err);
return;
}
@ -246,7 +252,7 @@ module.exports = class Audio {
return Promise.resolve();
}
catch (err) {
// TODO error handling
this._handleError(LOG_PREFIX, err);
return Promise.reject();
}
};

View File

@ -10,7 +10,6 @@
const BigBlueButtonGW = require('../bbb/pubsub/bbb-gw');
const C = require('../bbb/messages/Constants');
const Logger = require('../utils/Logger');
const isRecordedStream = require('../utils/Utils.js').isRecordedStream;
module.exports = class BaseManager {
constructor (connectionChannel, additionalChannels = [], logPrefix = C.BASE_MANAGER_PREFIX) {

View File

@ -0,0 +1,17 @@
"use strict";
const C = require('../bbb/messages/Constants');
const Logger = require('../utils/Logger');
const EventEmitter = require('events').EventEmitter;
module.exports = class BaseProvider extends EventEmitter {
constructor () {
super();
}
_handleError (logPrefix, error) {
Logger.debug(logPrefix, "Handling error", error.code, error.message);
Logger.trace(logPrefix, error.stack);
}
};

View File

@ -14,22 +14,23 @@ const moment = require('moment');
const h264_sdp = require('../h264-sdp');
const now = moment();
const MCSApi = require('../mcs-core/lib/media/MCSApiStub');
const Logger = require('../utils/Logger');
const BaseProvider = require('../base/BaseProvider');
const config = require('config');
const kurentoIp = config.get('kurentoIp');
const localIpAddress = config.get('localIpAddress');
const FORCE_H264 = config.get('screenshare-force-h264');
const PREFERRED_H264_PROFILE = config.get('screenshare-preferred-h264-profile');
const EventEmitter = require('events').EventEmitter;
const Logger = require('../utils/Logger');
const SHOULD_RECORD = config.get('recordScreenSharing');
const KEYFRAME_INTERVAL = config.get('screenshareKeyframeInterval');
const LOG_PREFIX = "[screenshare]";
// Global MCS endpoints mapping. These hashes maps IDs generated by the mcs-core
// lib to the ones generate in the ScreenshareManager
var sharedScreens = {};
var rtpEndpoints = {};
module.exports = class Screenshare extends EventEmitter {
module.exports = class Screenshare extends BaseProvider {
constructor(id, bbbgw, voiceBridge, caller = 'caller', vh, vw, meetingId) {
super();
this.mcs = new MCSApi();
@ -69,6 +70,7 @@ module.exports = class Screenshare extends EventEmitter {
await this.flushCandidatesQueue(this._presenterEndpoint, this._presenterCandidatesQueue);
await this.mcs.addIceCandidate(this._presenterEndpoint, candidate);
} catch (err) {
this._handleError(LOG_PREFIX, err);
Logger.error("[screenshare] ICE candidate could not be added to media controller.", err);
}
} else {
@ -82,6 +84,7 @@ module.exports = class Screenshare extends EventEmitter {
await this.flushCandidatesQueue(endpoint, this._viewersCandidatesQueue[callerName]);
await this.mcs.addIceCandidate(endpoint, candidate);
} catch (err) {
this._handleError(LOG_PREFIX, err);
Logger.error("[screenshare] Viewer ICE candidate could not be added to media controller.", err);
}
} else {
@ -107,6 +110,7 @@ module.exports = class Screenshare extends EventEmitter {
queue = [];
resolve();
}).catch((err) => {
this._handleError(LOG_PREFIX, err);
Logger.error("[screenshare] ICE candidate could not be added to media controller.", err);
reject();
});
@ -172,6 +176,7 @@ module.exports = class Screenshare extends EventEmitter {
serverState (event) {
switch (event && event.eventTag) {
case C.MEDIA_SERVER_OFFLINE:
this._handleError(LOG_PREFIX, err);
Logger.error("[screenshare] Screenshare provider received MEDIA_SERVER_OFFLINE event");
this.emit(C.MEDIA_SERVER_OFFLINE, event);
break;
@ -193,6 +198,7 @@ module.exports = class Screenshare extends EventEmitter {
this.sendStartShareEvent();
resolve(this.recording);
} catch (err) {
this._handleError(LOG_PREFIX, err);
Logger.error("[screenshare] Error on start recording with message", err);
reject(err);
}
@ -239,6 +245,7 @@ module.exports = class Screenshare extends EventEmitter {
}
catch (error) {
this._handleError(LOG_PREFIX, error);
Logger.error("[screenshare] MCS Join returned error =>", error);
return reject (error);
}
@ -250,6 +257,7 @@ module.exports = class Screenshare extends EventEmitter {
return resolve(sdpAnswer);
}
catch (err) {
this._handleError(LOG_PREFIX, err);
return reject(err);
}
}
@ -260,6 +268,7 @@ module.exports = class Screenshare extends EventEmitter {
return resolve(sdpAnswer);
}
catch (err) {
this._handleError(LOG_PREFIX, err);
return reject(err);
}
}
@ -301,6 +310,7 @@ module.exports = class Screenshare extends EventEmitter {
return resolve(presenterSdpAnswer);
}
catch (err) {
this._handleError(LOG_PREFIX, err);
Logger.error("[screenshare] MCS publish returned error =>", err);
return reject(err);
}
@ -332,6 +342,7 @@ module.exports = class Screenshare extends EventEmitter {
return resolve(sdpAnswer);
}
catch (err) {
this._handleError(LOG_PREFIX, err);
Logger.error("[screenshare] MCS publish returned error =>", err);
return reject(err);
}
@ -357,6 +368,7 @@ module.exports = class Screenshare extends EventEmitter {
return resolve();
}
catch (err) {
this._handleError(LOG_PREFIX, err);
Logger.error('[screenshare] MCS returned an error when trying to leave =>', err);
return resolve();
}
@ -397,6 +409,7 @@ module.exports = class Screenshare extends EventEmitter {
}
}
catch (err) {
this._handleError(LOG_PREFIX, err);
Logger.error(err);
resolve();
}
@ -479,6 +492,7 @@ module.exports = class Screenshare extends EventEmitter {
return;
}
catch (err) {
this._handleError(LOG_PREFIX, err);
Logger.error('[screenshare] MCS returned error when trying to unsubscribe', err);
return;
}

View File

@ -7,13 +7,14 @@ const C = require('../bbb/messages/Constants');
const Logger = require('../utils/Logger');
const Messaging = require('../bbb/messages/Messaging');
const h264_sdp = require('../h264-sdp');
const BaseProvider = require('../base/BaseProvider');
const FORCE_H264 = config.get('webcam-force-h264');
const EventEmitter = require('events').EventEmitter;
const SHOULD_RECORD = config.get('recordWebcams');
const LOG_PREFIX = "[video]";
var sharedWebcams = {};
module.exports = class Video extends EventEmitter {
module.exports = class Video extends BaseProvider {
constructor(_bbbGW, _meetingId, _id, _shared, _connectionId) {
super();
this.mcs = new MCSApi();
@ -53,6 +54,7 @@ module.exports = class Video extends EventEmitter {
await this.mcs.addIceCandidate(this.mediaId, _candidate);
}
catch (err) {
this._handleError(LOG_PREFIX, err);
Logger.error("[video] ICE candidate could not be added to media controller.", err);
}
}
@ -72,6 +74,7 @@ module.exports = class Video extends EventEmitter {
this.candidatesQueue = [];
resolve();
}).catch((err) => {
this._handleError(LOG_PREFIX, err);
Logger.error("[video] ICE candidate could not be added to media controller.", err);
reject();
});
@ -207,6 +210,7 @@ module.exports = class Video extends EventEmitter {
resolve(this.recording);
}
catch (err) {
this._handleError(LOG_PREFIX, err);
Logger.error("[video] Error on start recording with message", err);
reject(err);
}
@ -251,6 +255,7 @@ module.exports = class Video extends EventEmitter {
return resolve(sdpAnswer);
}
catch (err) {
this._handleError(LOG_PREFIX, err);
Logger.error("[video] MCS returned error => ", err);
return reject(err);
}
@ -273,6 +278,7 @@ module.exports = class Video extends EventEmitter {
}
}
catch (err) {
this._handleError(LOG_PREFIX, err);
return reject(err);
}
});
@ -299,6 +305,7 @@ module.exports = class Video extends EventEmitter {
}
}
catch (err) {
this._handleError(LOG_PREFIX, err);
Logger.error("[video] MCS returned error on pause procedure with message", err);
}
}
@ -338,7 +345,7 @@ module.exports = class Video extends EventEmitter {
resolve();
}
catch (err) {
// TODO error handling
this._handleError(LOG_PREFIX, err);
reject();
}
});