Better diferentiate ICE from different sessions in bbb-webrtc-sfu
This commit is contained in:
parent
21cc28561b
commit
3fb91aa8b6
@ -31,35 +31,34 @@ var _onMessage = function (_message) {
|
||||
let role = message.role? message.role : 'any';
|
||||
let cameraId = message.cameraId;
|
||||
let shared = false;
|
||||
let iceQueue = {};
|
||||
let iceQueues = {};
|
||||
let iceQueue;
|
||||
|
||||
if (message.role == 'share') {
|
||||
if (typeof message.cameraId === 'undefined' || !message.cameraId) {
|
||||
console.log(" [VideoManager] Undefined message.cameraId for session ", sessionId);
|
||||
return;
|
||||
}
|
||||
|
||||
if (message.role === 'share') {
|
||||
shared = true;
|
||||
cameraId += '-shared';
|
||||
}
|
||||
|
||||
if (!sessions[sessionId]) {
|
||||
sessions[sessionId] = {};
|
||||
}
|
||||
|
||||
switch (role) {
|
||||
case 'share':
|
||||
if (message.cameraId && typeof sessions[sessionId][message.cameraId+'-shared'] !== 'undefined' && sessions[sessionId][message.cameraId+'-shared']) {
|
||||
video = sessions[sessionId][message.cameraId+'-shared'];
|
||||
}
|
||||
break;
|
||||
case 'viewer':
|
||||
if (message.cameraId && sessions[sessionId][message.cameraId]) {
|
||||
video = sessions[sessionId][message.cameraId];
|
||||
}
|
||||
case 'any':
|
||||
if (message.cameraId && typeof sessions[sessionId][message.cameraId+'-shared'] !== 'undefined' && sessions[sessionId][message.cameraId+'-shared']) {
|
||||
video = sessions[sessionId][message.cameraId+'-shared'];
|
||||
}
|
||||
else if (message.cameraId && sessions[sessionId][message.cameraId]) {
|
||||
video = sessions[sessionId][message.cameraId];
|
||||
}
|
||||
if (!iceQueues[sessionId]) {
|
||||
iceQueues[sessionId] = {};
|
||||
}
|
||||
|
||||
break;
|
||||
if (typeof sessions[sessionId][cameraId] !== 'undefined' && sessions[sessionId][cameraId]) {
|
||||
video = sessions[sessionId][cameraId];
|
||||
}
|
||||
|
||||
if (typeof iceQueues[sessionId][cameraId] !== 'undefined' &&
|
||||
iceQueues[sessionId][cameraId]) {
|
||||
iceQueue = iceQueues[sessionId][cameraId] ;
|
||||
}
|
||||
|
||||
switch (message.id) {
|
||||
@ -69,22 +68,14 @@ var _onMessage = function (_message) {
|
||||
video = new Video(bbbGW, message.cameraId, shared, message.connectionId);
|
||||
|
||||
// Empty ice queue after starting video
|
||||
if (iceQueue[message.cameraId]) {
|
||||
if (iceQueue) {
|
||||
let candidate;
|
||||
while(candidate = iceQueue[message.cameraId].pop()) {
|
||||
while(candidate = iceQueue.pop()) {
|
||||
video.onIceCandidate(cand);
|
||||
}
|
||||
}
|
||||
|
||||
switch (role) {
|
||||
case 'share':
|
||||
sessions[sessionId][message.cameraId+'-shared']= video;
|
||||
break;
|
||||
case 'viewer':
|
||||
sessions[sessionId][message.cameraId] = video;
|
||||
break;
|
||||
default: console.log(" [VideoManager] Unknown role? ", role);
|
||||
}
|
||||
sessions[sessionId][cameraId] = video;
|
||||
|
||||
video.start(message.sdpOffer, (error, sdpAnswer) => {
|
||||
if (error) {
|
||||
@ -115,7 +106,7 @@ var _onMessage = function (_message) {
|
||||
console.log('[' + message.id + '] connection ' + sessionId + " with message => " + JSON.stringify(message, null, 2));
|
||||
|
||||
if (video) {
|
||||
stopVideo(sessionId, role, cameraId);
|
||||
stopVideo(sessionId, role, message.cameraId);
|
||||
} else {
|
||||
console.log(" [stop] Why is there no video on STOP?");
|
||||
}
|
||||
@ -126,12 +117,13 @@ var _onMessage = function (_message) {
|
||||
if (video) {
|
||||
video.onIceCandidate(message.candidate);
|
||||
} else {
|
||||
console.log(" [iceCandidate] Queueing ice candidate for later in video " + message.cameraId);
|
||||
|
||||
if (!iceQueue[message.cameraId]) {
|
||||
iceQueue[message.cameraId] = [];
|
||||
console.log(" [iceCandidate] Queueing ice candidate for later in video " + cameraId);
|
||||
if (typeof iceQueue === 'undefined' || !iceQueue) {
|
||||
iceQueues[sessionId][cameraId] = [];
|
||||
iceQueue = iceQueues[sessionId][cameraId];
|
||||
}
|
||||
iceQueue[message.cameraId].push(message.candidate);
|
||||
|
||||
iceQueue.push(message.candidate);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -23,6 +23,7 @@ module.exports = class Video {
|
||||
this.role = this.shared? 'share' : 'view'
|
||||
this.webRtcEndpoint = null;
|
||||
this.mediaId = null;
|
||||
this.iceQueue = null;
|
||||
|
||||
this.candidatesQueue = [];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user