Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

allow association between stream and participant jid

Philipp Hanckef701381ffb46
diff --git a/app.js b/app.js
index c0b545360d..5b72408792 100644
--- a/app.js
+++ b/app.js
@@ -7,6 +7,7 @@ var RTCPeerConnection = null;
var nickname = null;
var sharedKey = '';
var roomUrl = null;
+var ssrc2jid = {};
window.onbeforeunload = closePageWarning;
@@ -114,12 +115,31 @@ $(document).bind('remotestreamadded.jingle', function (event, data, sid) {
}
}
var sess = connection.jingle.sessions[sid];
+
+ // look up an associated JID for a stream id
+ if (data.stream.id.indexOf('mixedmslabel') == -1) {
+ var ssrclines = SDPUtil.find_lines(sess.peerconnection.remoteDescription.sdp, 'a=ssrc');
+ ssrclines = ssrclines.filter(function (line) {
+ return line.indexOf('mslabel:' + data.stream.label) != -1;
+ })
+ if (ssrclines.length) {
+ thessrc = ssrclines[0].substring(7).split(' ')[0];
+ // ok to overwrite the one from focus? might save work in colibri.js
+ console.log('associated jid', ssrc2jid[thessrc], data.peerjid);
+ if (ssrc2jid[thessrc]) {
+ data.peerjid = ssrc2jid[thessrc];
+ }
+ }
+ }
+
var vid = document.createElement('video');
// FIXME: the span should not be created here but on muc join
var span = document.createElement('span');
if (data.peerjid) {
// FIXME: how to name this span? data.peerjid is not set for jingle clients
span.id = 'participant_' + Strophe.getResourceFromJid(data.peerjid);
+ } else if (data.stream.id != 'mixedmslabel') {
+ console.warn('can not associate stream', data.stream.id, 'with a participant');
}
span.className = 'videocontainer';
var id = 'remoteVideo_' + sid + '_' + data.stream.id;
@@ -191,6 +211,29 @@ $(document).bind('callterminated.jingle', function (event, sid, reason) {
// FIXME
});
+$(document).bind('setLocalDescription.jingle', function (event, sid) {
+ // put our ssrcs into presence so other clients can identify our stream
+ var sess = connection.jingle.sessions[sid];
+ var newssrcs = {};
+ var localSDP = new SDP(sess.peerconnection.localDescription.sdp);
+ localSDP.media.forEach(function (media) {
+ var type = SDPUtil.parse_mline(media.split('\r\n')[0]).media;
+ var ssrc = SDPUtil.find_line(media, 'a=ssrc:').substring(7).split(' ')[0];
+ // assumes a single local ssrc
+ newssrcs[type] = ssrc;
+ });
+ console.log('new ssrcs', newssrcs);
+ // just blast off presence for everything -- TODO: optimize
+ var pres = $pres({to: connection.emuc.myroomjid });
+ pres.c('x', {xmlns: 'http://jabber.org/protocol/muc'}).up();
+
+ pres.c('media', {xmlns: 'http://estos.de/ns/mjs'});
+ Object.keys(newssrcs).forEach(function (mtype) {
+ pres.c('source', {type: mtype, ssrc: newssrcs[mtype]}).up();
+ });
+ pres.up();
+ connection.send(pres);
+});
$(document).bind('joined.muc', function (event, jid, info) {
updateRoomUrl(window.location.href);
@@ -203,7 +246,7 @@ $(document).bind('joined.muc', function (event, jid, info) {
}
});
-$(document).bind('entered.muc', function (event, jid, info) {
+$(document).bind('entered.muc', function (event, jid, info, pres) {
console.log('entered', jid, info);
console.log(focus);
@@ -220,6 +263,10 @@ $(document).bind('entered.muc', function (event, jid, info) {
else if (sharedKey) {
updateLockButton();
}
+ $(pres).find('>media[xmlns="http://estos.de/ns/mjs"]>source').each(function (idx, ssrc) {
+ //console.log(jid, 'assoc ssrc', ssrc.getAttribute('type'), ssrc.getAttribute('ssrc'));
+ ssrc2jid[ssrc.getAttribute('ssrc')] = jid;
+ });
});
$(document).bind('left.muc', function (event, jid) {
@@ -265,6 +312,11 @@ $(document).bind('passwordrequired.muc', function (event, jid) {
}
}
});
+$(document).bind('presence.muc', function (event, jid, info, pres) {
+ $(pres).find('>media[xmlns="http://estos.de/ns/mjs"]>source').each(function (idx, ssrc) {
+ //console.log(jid, 'assoc ssrc', ssrc.getAttribute('type'), ssrc.getAttribute('ssrc'));
+ ssrc2jid[ssrc.getAttribute('ssrc')] = jid;
+ });
});
function toggleVideo() {
diff --git a/libs/strophejingle.bundle.js b/libs/strophejingle.bundle.js
index cbb9165a22..f15ae2260c 100644
--- a/libs/strophejingle.bundle.js
+++ b/libs/strophejingle.bundle.js
@@ -1530,6 +1530,7 @@ JingleSession.prototype.accept = function () {
this.peerconnection.setLocalDescription(new RTCSessionDescription({type: 'answer', sdp: sdp}),
function () {
//console.log('setLocalDescription success');
+ $(document).trigger('setLocalDescription.jingle', [self.sid]);
},
function (e) {
console.error('setLocalDescription failed', e);
@@ -1753,6 +1754,7 @@ JingleSession.prototype.createdOffer = function (sdp) {
sdp.sdp = this.localSDP.raw;
this.peerconnection.setLocalDescription(sdp,
function () {
+ $(document).trigger('setLocalDescription.jingle', [self.sid]);
//console.log('setLocalDescription success');
},
function (e) {
@@ -1978,6 +1980,7 @@ JingleSession.prototype.createdAnswer = function (sdp, provisional) {
sdp.sdp = this.localSDP.raw;
this.peerconnection.setLocalDescription(sdp,
function () {
+ $(document).trigger('setLocalDescription.jingle', [self.sid]);
//console.log('setLocalDescription success');
},
function (e) {
@@ -2138,6 +2141,7 @@ JingleSession.prototype.modifySources = function() {
self.peerconnection.setLocalDescription(modifiedAnswer,
function() {
//console.log('modified setLocalDescription ok');
+ $(document).trigger('setLocalDescription.jingle', [self.sid]);
},
function(error) {
console.log('modified setLocalDescription failed');