Some refactor to screenshare start procedures

This commit is contained in:
prlanzarin 2018-06-04 15:29:30 +00:00
parent 556b2c006b
commit 0ffe7e9dfb
2 changed files with 90 additions and 80 deletions

View File

@ -20,7 +20,7 @@ module.exports = class ScreenshareManager extends BaseManager {
this._iceQueues = {};
}
_onMessage(message) {
async _onMessage(message) {
Logger.debug(this._logPrefix, 'Received message [' + message.id + '] from connection', message.connectionId);
const sessionId = message.voiceBridge;
@ -42,21 +42,10 @@ module.exports = class ScreenshareManager extends BaseManager {
this._sessions[sessionId] = session;
}
// starts presenter by sending sessionID, websocket and sdpoffer
// async start (sessionId, connectionId, sdpOffer, callerName, role, callback) {
session.start(sessionId, connectionId, sdpOffer, callerName, role, (error, sdpAnswer) => {
Logger.info(this._logPrefix, "Started presenter ", sessionId, " for connection", connectionId);
if (error) {
this._bbbGW.publish(JSON.stringify({
connectionId: connectionId,
type: C.SCREENSHARE_APP,
role: role,
id : 'startResponse',
response : 'rejected',
message : error
}), C.FROM_SCREENSHARE);
return error;
}
// starts screenshare peer with role by sending sessionID, websocket and sdpoffer
try {
const sdpAnswer = await session.start(sessionId, connectionId, sdpOffer, callerName, role)
Logger.info(this._logPrefix, "Started peer", sessionId, " for connection", connectionId);
// Empty ice queue after starting session
if (iceQueue) {
@ -79,8 +68,19 @@ module.exports = class ScreenshareManager extends BaseManager {
this._stopSession(sessionId);
});
Logger.info(this._logPrefix, "Sending presenterResponse to presenter", sessionId, "for connection", session._id);
});
Logger.info(this._logPrefix, "Sending startResponse to peer", sessionId, "for connection", session._id);
}
catch (err) {
Logger.error(this._logPrefix, err);
this._bbbGW.publish(JSON.stringify({
connectionId: connectionId,
type: C.SCREENSHARE_APP,
role: role,
id : 'startResponse',
response : 'rejected',
message : error
}), C.FROM_SCREENSHARE);
}
break;
case 'stop':

View File

@ -203,36 +203,55 @@ module.exports = class Screenshare extends EventEmitter {
this._BigBlueButtonGW.publish(req, C.TO_AKKA_APPS);
}
async start (sessionId, connectionId, sdpOffer, callerName, role, callback) {
// Force H264 on Firefox and Chrome
if (FORCE_H264) {
sdpOffer = h264_sdp.transform(sdpOffer);
}
// Start the recording process
if (SHOULD_RECORD && role === C.SEND_ROLE) {
this.sendGetRecordingStatusRequestMessage(callerName);
}
Logger.info("[screenshare] Starting session", this._voiceBridge + '-' + role);
if (!this.userId) {
try {
this.userId = await this.mcs.join(this._meetingId, 'SFU', {});
Logger.info("[screenshare] MCS Join for", this._id, "returned", this.userId);
start (sessionId, connectionId, sdpOffer, callerName, role) {
return new Promise(async (resolve, reject) => {
// Force H264 on Firefox and Chrome
if (FORCE_H264) {
sdpOffer = h264_sdp.transform(sdpOffer);
}
catch (error) {
Logger.error("[screenshare] MCS Join returned error =>", error);
return callback(error);
// Start the recording process
if (SHOULD_RECORD && role === C.SEND_ROLE) {
this.sendGetRecordingStatusRequestMessage(callerName);
}
}
if (role === C.RECV_ROLE) {
this._startViewer(connectionId, this._voiceBridge, sdpOffer, callerName, this._presenterEndpoint, callback)
return;
}
Logger.info("[screenshare] Starting session", this._voiceBridge + '-' + role);
if (!this.userId) {
try {
this.userId = await this.mcs.join(this._meetingId, 'SFU', {});
Logger.info("[screenshare] MCS Join for", this._id, "returned", this.userId);
if (role === C.SEND_ROLE) {
}
catch (error) {
Logger.error("[screenshare] MCS Join returned error =>", error);
return reject (error);
}
}
if (role === C.RECV_ROLE) {
try {
const sdpAnswer = await this._startViewer(connectionId, this._voiceBridge, sdpOffer, callerName, this._presenterEndpoint)
return resolve(sdpAnswer);
}
catch (err) {
return reject(err);
}
}
if (role === C.SEND_ROLE) {
try {
const sdpAnswer = await this._startPresenter(sdpOffer);
return resolve(sdpAnswer);
}
catch (err) {
return reject(err);
}
}
});
}
_startPresenter (sdpOffer) {
return new Promise(async (resolve, reject) => {
try {
const retSource = await this.mcs.publish(this.userId, this._meetingId, 'WebRtcEndpoint', {descriptor: sdpOffer});
@ -263,57 +282,48 @@ module.exports = class Screenshare extends EventEmitter {
Logger.info("[screenshare] MCS subscribe for user", this.userId, "returned", this._ffmpegEndpoint);
return callback(null, presenterSdpAnswer);
return resolve(presenterSdpAnswer);
}
catch (err) {
Logger.error("[screenshare] MCS publish returned error =>", err);
return callback(err);
return reject(err);
}
finally {
this.mcs.once('ServerState' + this._presenterEndpoint, this.serverState.bind(this));
}
}
});
}
async _startViewer(connectionId, voiceBridge, sdpOffer, callerName, presenterEndpoint, callback) {
Logger.info("[screenshare] Starting viewer", callerName, "for voiceBridge", this._voiceBridge);
// TODO refactor the callback handling
let _callback = function(){};
let sdpAnswer;
_startViewer(connectionId, voiceBridge, sdpOffer, callerName, presenterEndpoint) {
return new Promise(async (resolve, reject) => {
Logger.info("[screenshare] Starting viewer", callerName, "for voiceBridge", this._voiceBridge);
let sdpAnswer;
if (FORCE_H264) {
sdpOffer = h264_sdp.transform(sdpOffer);
}
if (FORCE_H264) {
sdpOffer = h264_sdp.transform(sdpOffer);
}
this._viewersCandidatesQueue[callerName] = [];
this._viewersCandidatesQueue[callerName] = [];
try {
const retSource = await this.mcs.subscribe(this.userId, sharedScreens[voiceBridge], 'WebRtcEndpoint', {descriptor: sdpOffer});
try {
const retSource = await this.mcs.subscribe(this.userId, sharedScreens[voiceBridge], 'WebRtcEndpoint', {descriptor: sdpOffer});
this._viewersEndpoint[callerName] = retSource.sessionId;
sdpAnswer = retSource.answer;
await this.flushCandidatesQueue(this._viewersEndpoint[callerName], this._viewersCandidatesQueue[callerName]);
this._viewersEndpoint[callerName] = retSource.sessionId;
sdpAnswer = retSource.answer;
await this.flushCandidatesQueue(this._viewersEndpoint[callerName], this._viewersCandidatesQueue[callerName]);
this.mcs.on('MediaEvent' + this._viewersEndpoint[callerName], (event) => {
this.mediaStateWebRtc(event, connectionId);
});
this.mcs.on('MediaEvent' + this._viewersEndpoint[callerName], (event) => {
this.mediaStateWebRtc(event, connectionId);
});
this._BigBlueButtonGW.publish(JSON.stringify({
connectionId: connectionId,
id: "startResponse",
type: C.SCREENSHARE_APP,
role: C.RECV_ROLE,
sdpAnswer: sdpAnswer,
response: "accepted"
}), C.FROM_SCREENSHARE);
Logger.info("[screenshare] MCS subscribe returned for user", this.userId, "returned", this._viewersEndpoint[callerName], "at callername", callerName);
}
catch (err) {
Logger.error("[screenshare] MCS publish returned error =>", err);
return _callback(err);
}
Logger.info("[screenshare] MCS subscribe returned for user", this.userId, "returned", this._viewersEndpoint[callerName], "at callername", callerName);
return resolve(sdpAnswer);
}
catch (err) {
Logger.error("[screenshare] MCS publish returned error =>", err);
return reject(err);
}
});
}
stop () {