Browse Source

update colibri.js version

master
Philipp Hancke 11 years ago
parent
commit
dc2bf41fff
1 changed files with 39 additions and 10 deletions
  1. 39
    10
      libs/colibri.js

+ 39
- 10
libs/colibri.js View File

53
     // ssrc lines to be removed on next update
53
     // ssrc lines to be removed on next update
54
     this.removessrc = [];
54
     this.removessrc = [];
55
 
55
 
56
+    // container for candidates from the focus
57
+    // gathered before confid is known
58
+    this.drip_container = [];
59
+
56
     // silly wait flag
60
     // silly wait flag
57
     this.wait = true;
61
     this.wait = true;
58
 }
62
 }
105
         });
109
         });
106
         $(document).trigger('remotestreamadded.jingle', [event, self.sid]);
110
         $(document).trigger('remotestreamadded.jingle', [event, self.sid]);
107
     };
111
     };
108
-    this.peerconnection.onicecandidate = function (event) {
109
-        self.sendIceCandidate(event.candidate);
110
-    };
111
     this.peerconnection.createOffer(
112
     this.peerconnection.createOffer(
112
         function (offer) {
113
         function (offer) {
113
             self.peerconnection.setLocalDescription(
114
             self.peerconnection.setLocalDescription(
116
                     // success
117
                     // success
117
                     $(document).trigger('setLocalDescription.jingle', [self.sid]);
118
                     $(document).trigger('setLocalDescription.jingle', [self.sid]);
118
                     // FIXME: could call _makeConference here and trickle candidates later
119
                     // FIXME: could call _makeConference here and trickle candidates later
120
+                    self._makeConference();
119
                 },
121
                 },
120
                 function (error) {
122
                 function (error) {
121
                     console.log('setLocalDescription failed', error);
123
                     console.log('setLocalDescription failed', error);
127
         }
129
         }
128
     );
130
     );
129
     this.peerconnection.onicecandidate = function (event) {
131
     this.peerconnection.onicecandidate = function (event) {
132
+        //console.log('focus onicecandidate', self.confid, new Date().getTime(), event.candidate);
130
         if (!event.candidate) {
133
         if (!event.candidate) {
131
             console.log('end of candidates');
134
             console.log('end of candidates');
132
-            self._makeConference();
133
             return;
135
             return;
134
         }
136
         }
137
+        if (self.confid === 0) {
138
+            self.drip_container.push(event.candidate);
139
+        } else {
140
+            self.sendIceCandidate(candidate);
141
+        }
135
     };
142
     };
136
 };
143
 };
137
 
144
 
176
 // callback when a conference was created
183
 // callback when a conference was created
177
 ColibriFocus.prototype.createdConference = function (result) {
184
 ColibriFocus.prototype.createdConference = function (result) {
178
     console.log('created a conference on the bridge');
185
     console.log('created a conference on the bridge');
186
+    var self = this;
179
     var tmp;
187
     var tmp;
180
 
188
 
181
     this.confid = $(result).find('>conference').attr('id');
189
     this.confid = $(result).find('>conference').attr('id');
197
     localSDP.removeSessionLines('a=group:');
205
     localSDP.removeSessionLines('a=group:');
198
     localSDP.removeSessionLines('a=msid-semantic:');
206
     localSDP.removeSessionLines('a=msid-semantic:');
199
 
207
 
208
+    if (this.drip_container.length) {
209
+        this.sendIceCandidates(this.drip_container);
210
+        this.drip_container = [];
211
+    }
212
+
200
     // establish our channel with the bridge
213
     // establish our channel with the bridge
201
     // static answer taken from chrome M31, should be replaced by a 
214
     // static answer taken from chrome M31, should be replaced by a 
202
     // dynamic one that is based on our offer FIXME
215
     // dynamic one that is based on our offer FIXME
275
     }
288
     }
276
     bridgeSDP.raw = bridgeSDP.session + bridgeSDP.media.join('');
289
     bridgeSDP.raw = bridgeSDP.session + bridgeSDP.media.join('');
277
 
290
 
278
-    var self = this;
279
     this.peerconnection.setRemoteDescription(
291
     this.peerconnection.setRemoteDescription(
280
         new RTCSessionDescription({type: 'answer', sdp: bridgeSDP.raw}),
292
         new RTCSessionDescription({type: 'answer', sdp: bridgeSDP.raw}),
281
         function () {
293
         function () {
638
         console.log('end of candidates');
650
         console.log('end of candidates');
639
         return;
651
         return;
640
     }
652
     }
653
+    this.sendIceCandidates([candidate]);
654
+};
655
+
656
+// sort and send multiple candidates
657
+ColibriFocus.prototype.sendIceCandidates = function (candidates) {
658
+    var self = this;
641
     var mycands = $iq({to: this.bridgejid, type: 'set'});
659
     var mycands = $iq({to: this.bridgejid, type: 'set'});
642
     mycands.c('conference', {xmlns: 'http://jitsi.org/protocol/colibri', id: this.confid});
660
     mycands.c('conference', {xmlns: 'http://jitsi.org/protocol/colibri', id: this.confid});
643
-    mycands.c('content', {name: candidate.sdpMid });
644
-    mycands.c('channel', {id: $(this.mychannel[candidate.sdpMLineIndex]).attr('id')});
645
-    mycands.c('transport', {xmlns: 'urn:xmpp:jingle:transports:ice-udp:1'});
646
-    tmp = SDPUtil.candidateToJingle(candidate.candidate);
647
-    mycands.c('candidate', tmp).up();
661
+    // FIXME: multi-candidate logic is taken from strophe.jingle, should be refactored there
662
+    var localSDP = new SDP(this.peerconnection.localDescription.sdp);
663
+    for (var mid = 0; mid < localSDP.media.length; mid++) {
664
+        var cands = candidates.filter(function (el) { return el.sdpMLineIndex == mid; });
665
+        if (cands.length > 0) {
666
+            mycands.c('content', {name: cands[0].sdpMid });
667
+            mycands.c('channel', {id: $(this.mychannel[cands[0].sdpMLineIndex]).attr('id')});
668
+            mycands.c('transport', {xmlns: 'urn:xmpp:jingle:transports:ice-udp:1'});
669
+            for (var i = 0; i < cands.length; i++) {
670
+                mycands.c('candidate', SDPUtil.candidateToJingle(cands[i].candidate)).up();
671
+            }
672
+            mycands.up(); // transport
673
+            mycands.up(); // channel
674
+            mycands.up(); // content
675
+        }
676
+    }
648
     this.connection.sendIQ(mycands,
677
     this.connection.sendIQ(mycands,
649
         function (res) {
678
         function (res) {
650
             console.log('got result');
679
             console.log('got result');

Loading…
Cancel
Save