Browse Source

allow association between stream and participant jid

j8
Philipp Hancke 12 years ago
parent
commit
f701381ffb
2 changed files with 57 additions and 1 deletions
  1. 53
    1
      app.js
  2. 4
    0
      libs/strophejingle.bundle.js

+ 53
- 1
app.js View File

@@ -7,6 +7,7 @@ var RTCPeerConnection = null;
7 7
 var nickname = null;
8 8
 var sharedKey = '';
9 9
 var roomUrl = null;
10
+var ssrc2jid = {};
10 11
 
11 12
 window.onbeforeunload = closePageWarning;
12 13
 
@@ -114,12 +115,31 @@ $(document).bind('remotestreamadded.jingle', function (event, data, sid) {
114 115
         }
115 116
     }
116 117
     var sess = connection.jingle.sessions[sid];
118
+
119
+    // look up an associated JID for a stream id
120
+    if (data.stream.id.indexOf('mixedmslabel') == -1) {
121
+        var ssrclines = SDPUtil.find_lines(sess.peerconnection.remoteDescription.sdp, 'a=ssrc');
122
+        ssrclines = ssrclines.filter(function (line) {
123
+            return line.indexOf('mslabel:' + data.stream.label) != -1; 
124
+        })
125
+        if (ssrclines.length) {
126
+            thessrc = ssrclines[0].substring(7).split(' ')[0];
127
+            // ok to overwrite the one from focus? might save work in colibri.js
128
+            console.log('associated jid', ssrc2jid[thessrc], data.peerjid);
129
+            if (ssrc2jid[thessrc]) {
130
+                data.peerjid = ssrc2jid[thessrc];
131
+            }
132
+        }
133
+    }
134
+
117 135
     var vid = document.createElement('video');
118 136
     // FIXME: the span should not be created here but on muc join
119 137
     var span = document.createElement('span');
120 138
     if (data.peerjid) {
121 139
         // FIXME: how to name this span? data.peerjid is not set for jingle clients
122 140
         span.id = 'participant_' + Strophe.getResourceFromJid(data.peerjid);
141
+    } else if (data.stream.id != 'mixedmslabel') {
142
+        console.warn('can not associate stream', data.stream.id, 'with a participant');
123 143
     }
124 144
     span.className = 'videocontainer';
125 145
     var id = 'remoteVideo_' + sid + '_' + data.stream.id;
@@ -191,6 +211,29 @@ $(document).bind('callterminated.jingle', function (event, sid, reason) {
191 211
     // FIXME
192 212
 });
193 213
 
214
+$(document).bind('setLocalDescription.jingle', function (event, sid) {
215
+    // put our ssrcs into presence so other clients can identify our stream
216
+    var sess = connection.jingle.sessions[sid];
217
+    var newssrcs = {};
218
+    var localSDP = new SDP(sess.peerconnection.localDescription.sdp);
219
+    localSDP.media.forEach(function (media) {
220
+        var type = SDPUtil.parse_mline(media.split('\r\n')[0]).media;
221
+        var ssrc = SDPUtil.find_line(media, 'a=ssrc:').substring(7).split(' ')[0];
222
+        // assumes a single local ssrc
223
+        newssrcs[type] = ssrc;
224
+    });
225
+    console.log('new ssrcs', newssrcs);
226
+    // just blast off presence for everything -- TODO: optimize
227
+    var pres = $pres({to: connection.emuc.myroomjid });
228
+    pres.c('x', {xmlns: 'http://jabber.org/protocol/muc'}).up();
229
+
230
+    pres.c('media', {xmlns: 'http://estos.de/ns/mjs'});
231
+    Object.keys(newssrcs).forEach(function (mtype) {
232
+        pres.c('source', {type: mtype, ssrc: newssrcs[mtype]}).up();
233
+    });
234
+    pres.up();
235
+    connection.send(pres);
236
+});
194 237
 
195 238
 $(document).bind('joined.muc', function (event, jid, info) {
196 239
     updateRoomUrl(window.location.href);
@@ -203,7 +246,7 @@ $(document).bind('joined.muc', function (event, jid, info) {
203 246
     }
204 247
 });
205 248
 
206
-$(document).bind('entered.muc', function (event, jid, info) {
249
+$(document).bind('entered.muc', function (event, jid, info, pres) {
207 250
     console.log('entered', jid, info);
208 251
     console.log(focus);
209 252
 
@@ -220,6 +263,10 @@ $(document).bind('entered.muc', function (event, jid, info) {
220 263
     else if (sharedKey) {
221 264
         updateLockButton();
222 265
     }
266
+    $(pres).find('>media[xmlns="http://estos.de/ns/mjs"]>source').each(function (idx, ssrc) {
267
+        //console.log(jid, 'assoc ssrc', ssrc.getAttribute('type'), ssrc.getAttribute('ssrc'));
268
+        ssrc2jid[ssrc.getAttribute('ssrc')] = jid;
269
+    });
223 270
 });
224 271
 
225 272
 $(document).bind('left.muc', function (event, jid) {
@@ -265,6 +312,11 @@ $(document).bind('passwordrequired.muc', function (event, jid) {
265 312
                     }
266 313
                 }
267 314
             });
315
+$(document).bind('presence.muc', function (event, jid, info, pres) {
316
+    $(pres).find('>media[xmlns="http://estos.de/ns/mjs"]>source').each(function (idx, ssrc) {
317
+        //console.log(jid, 'assoc ssrc', ssrc.getAttribute('type'), ssrc.getAttribute('ssrc'));
318
+        ssrc2jid[ssrc.getAttribute('ssrc')] = jid;
319
+    });
268 320
 });
269 321
 
270 322
 function toggleVideo() {

+ 4
- 0
libs/strophejingle.bundle.js View File

@@ -1530,6 +1530,7 @@ JingleSession.prototype.accept = function () {
1530 1530
     this.peerconnection.setLocalDescription(new RTCSessionDescription({type: 'answer', sdp: sdp}),
1531 1531
         function () {
1532 1532
             //console.log('setLocalDescription success');
1533
+            $(document).trigger('setLocalDescription.jingle', [self.sid]);
1533 1534
         },
1534 1535
         function (e) {
1535 1536
             console.error('setLocalDescription failed', e);
@@ -1753,6 +1754,7 @@ JingleSession.prototype.createdOffer = function (sdp) {
1753 1754
     sdp.sdp = this.localSDP.raw;
1754 1755
     this.peerconnection.setLocalDescription(sdp, 
1755 1756
         function () {
1757
+            $(document).trigger('setLocalDescription.jingle', [self.sid]);
1756 1758
             //console.log('setLocalDescription success');
1757 1759
         },
1758 1760
         function (e) {
@@ -1978,6 +1980,7 @@ JingleSession.prototype.createdAnswer = function (sdp, provisional) {
1978 1980
     sdp.sdp = this.localSDP.raw;
1979 1981
     this.peerconnection.setLocalDescription(sdp,
1980 1982
         function () {
1983
+            $(document).trigger('setLocalDescription.jingle', [self.sid]);
1981 1984
             //console.log('setLocalDescription success');
1982 1985
         },
1983 1986
         function (e) {
@@ -2138,6 +2141,7 @@ JingleSession.prototype.modifySources = function() {
2138 2141
                     self.peerconnection.setLocalDescription(modifiedAnswer,
2139 2142
                         function() {
2140 2143
                             //console.log('modified setLocalDescription ok');
2144
+                            $(document).trigger('setLocalDescription.jingle', [self.sid]);
2141 2145
                         },
2142 2146
                         function(error) {
2143 2147
                             console.log('modified setLocalDescription failed');

Loading…
Cancel
Save