Added kurento screensharing viewer stop logic

This commit is contained in:
prlanzarin 2017-11-06 14:23:48 +00:00
parent 9175400c2e
commit c04e3da068
2 changed files with 54 additions and 26 deletions

View File

@ -99,9 +99,16 @@ module.exports = class ConnectionManager {
webSocket.on('close', function() {
console.log('Connection ' + connectionId + ' closed');
if (self._screenshareSessions[sessionId] && self._screenshareSessions[sessionId].id == connectionId) { // if presenter // FIXME (this conditional was added to prevent screenshare stop when an iOS user quits)
console.log(webSocket.presenter);
if (webSocket.presenter && self._screenshareSessions[sessionId]) { // if presenter // FIXME (this conditional was added to prevent screenshare stop when an iOS user quits)
console.log(" [CM] Stopping presenter " + sessionId);
self._stopSession(sessionId);
}
if (webSocket.viewer && typeof webSocket.session !== 'undefined') {
console.log(" [CM] Stopping viewer " + webSocket.viewerId);
webSocket.session._stopViewer(webSocket.viewerId);
}
});
webSocket.on('message', function(_message) {
@ -111,6 +118,7 @@ module.exports = class ConnectionManager {
sessionId = message.voiceBridge;
if(self._screenshareSessions[sessionId]) {
session = self._screenshareSessions[sessionId];
webSocket.session = session;
}
switch (message.id) {
@ -119,6 +127,7 @@ module.exports = class ConnectionManager {
// Checking if there's already a Screenshare session started
// because we shouldn't overwrite it
webSocket.presenter = true;
if (!self._screenshareSessions[message.voiceBridge]) {
self._screenshareSessions[message.voiceBridge] = {}
@ -159,6 +168,10 @@ module.exports = class ConnectionManager {
case 'viewer':
console.log("[viewer] Session output \n " + session);
webSocket.viewer = true;
webSocket.viewerId = message.callerName;
if (message.sdpOffer && message.voiceBridge) {
if (session) {
session._startViewer(webSocket, message.voiceBridge, message.sdpOffer, message.callerName, self._screenshareSessions[message.voiceBridge]._presenterEndpoint);
@ -182,6 +195,7 @@ module.exports = class ConnectionManager {
case 'onIceCandidate':
if (session) {
console.log(" [CM] What the fluff is happening");
session._onIceCandidate(message.candidate);
} else {
console.log(" [iceCandidate] Why is there no session on ICE CANDIDATE?");

View File

@ -53,6 +53,7 @@ module.exports = class Screenshare {
let candidate = kurento.getComplexType('IceCandidate')(_candidate);
if (this._presenterEndpoint) {
console.log(" [screenshare] Adding ICE candidate to presenter");
this._presenterEndpoint.addIceCandidate(candidate);
}
else {
@ -107,8 +108,7 @@ module.exports = class Screenshare {
// ICE NEGOTIATION WITH THE ENDPOINT
self._viewersEndpoint[callerName].on('OnIceCandidate', function(event) {
let candidate = kurento.getComplexType('IceCandidate')(event.candidate);
ws.sendMessage({ id : 'iceCandidate', candidate : candidate });
let candidate = kurento.getComplexType('IceCandidate')(event.candidate); ws.sendMessage({ id : 'iceCandidate', candidate : candidate });
});
sdp = h264_sdp.transform(sdp);
@ -244,7 +244,6 @@ module.exports = class Screenshare {
} else {
console.log(" [webRtcEndpoint] PLEASE DONT TRY STOPPING THINGS TWICE");
}
if (this._ffmpegRtpEndpoint) {
MediaController.releaseMediaElement(this._ffmpegRtpEndpoint.id);
this._ffmpegRtpEndpoint = null;
@ -280,6 +279,7 @@ module.exports = class Screenshare {
}
_onRtpMediaFlowing(meetingId, rtpParams) {
console.log(" [screenshare] Media FLOWING for meeting => " + meetingId);
let self = this;
let strm = Messaging.generateStartTranscoderRequestMessage(meetingId, meetingId, rtpParams);
@ -302,7 +302,8 @@ module.exports = class Screenshare {
};
_stopRtmpBroadcast (meetingId) {
var self = this;
console.log(" [screenshare] _stopRtmpBroadcast for meeting => " + meetingId);
let self = this;
if(self._meetingId === meetingId) {
// TODO correctly assemble this timestamp
let timestamp = now.format('hhmmss');
@ -313,6 +314,7 @@ module.exports = class Screenshare {
}
_startRtmpBroadcast (meetingId, output) {
console.log(" [screenshare] _startRtmpBroadcast for meeting => " + meetingId);
var self = this;
if(self._meetingId === meetingId) {
// TODO correctly assemble this timestamp
@ -329,5 +331,17 @@ module.exports = class Screenshare {
console.log(" [screenshare] TODO RTP NOT_FLOWING");
};
_stopViewer(id) {
let viewer = this._viewersEndpoint[id];
console.log(' [stop] Releasing endpoints for ' + id);
if (viewer) {
MediaController.releaseMediaElement(viewer.id);
this._viewersEndpoint[viewer.id] = null;
} else {
console.log(" [webRtcEndpoint] PLEASE DONT TRY STOPPING THINGS TWICE");
}
delete this._viewersCandidatesQueue[id];
};
};