瀏覽代碼

reverse o/a roles of focus. closes #33

j8
Philipp Hancke 12 年之前
父節點
當前提交
34bd87ce1d
共有 1 個檔案被更改,包括 107 行新增39 行删除
  1. 107
    39
      libs/colibri.js

+ 107
- 39
libs/colibri.js 查看文件

109
         });
109
         });
110
         $(document).trigger('remotestreamadded.jingle', [event, self.sid]);
110
         $(document).trigger('remotestreamadded.jingle', [event, self.sid]);
111
     };
111
     };
112
+    this.peerconnection.onicecandidate = function (event) {
113
+        //console.log('focus onicecandidate', self.confid, new Date().getTime(), event.candidate);
114
+        if (!event.candidate) {
115
+            console.log('end of candidates');
116
+            return;
117
+        }
118
+        if (self.confid === 0) {
119
+            self.drip_container.push(event.candidate);
120
+        } else {
121
+            self.sendIceCandidate(event.candidate);
122
+        }
123
+    };
124
+    this._makeConference();
125
+    /*
112
     this.peerconnection.createOffer(
126
     this.peerconnection.createOffer(
113
         function (offer) {
127
         function (offer) {
114
             self.peerconnection.setLocalDescription(
128
             self.peerconnection.setLocalDescription(
128
             console.warn(error);
142
             console.warn(error);
129
         }
143
         }
130
     );
144
     );
131
-    this.peerconnection.onicecandidate = function (event) {
132
-        //console.log('focus onicecandidate', self.confid, new Date().getTime(), event.candidate);
133
-        if (!event.candidate) {
134
-            console.log('end of candidates');
135
-            return;
136
-        }
137
-        if (self.confid === 0) {
138
-            self.drip_container.push(event.candidate);
139
-        } else {
140
-            self.sendIceCandidate(candidate);
141
-        }
142
-    };
145
+    */
143
 };
146
 };
144
 
147
 
145
 ColibriFocus.prototype._makeConference = function () {
148
 ColibriFocus.prototype._makeConference = function () {
147
     var elem = $iq({to: this.bridgejid, type: 'get'});
150
     var elem = $iq({to: this.bridgejid, type: 'get'});
148
     elem.c('conference', {xmlns: 'http://jitsi.org/protocol/colibri'});
151
     elem.c('conference', {xmlns: 'http://jitsi.org/protocol/colibri'});
149
 
152
 
153
+    var stream = this.connection.jingle.localStream;
154
+    var types = [];
155
+    if (connection.jingle.localStream.getAudioTracks().length > 0) {
156
+        types.push('audio');
157
+    }
158
+    if (connection.jingle.localStream.getVideoTracks().length > 0) {
159
+        types.push('video');
160
+    }
161
+    types.forEach(function (name) {
162
+        elem.c('content', {name: name});
163
+        elem.c('channel', {initiator: 'true', expire: '15'}).up();
164
+        for (var j = 0; j < self.peers.length; j++) {
165
+            elem.c('channel', {initiator: 'true', expire:'15' }).up();
166
+        }
167
+        elem.up(); // end of content
168
+    });
169
+    /*
150
     var localSDP = new SDP(this.peerconnection.localDescription.sdp);
170
     var localSDP = new SDP(this.peerconnection.localDescription.sdp);
151
     localSDP.media.forEach(function (media, channel) {
171
     localSDP.media.forEach(function (media, channel) {
152
         var name = SDPUtil.parse_mline(media.split('\r\n')[0]).media; 
172
         var name = SDPUtil.parse_mline(media.split('\r\n')[0]).media; 
169
         }
189
         }
170
         elem.up(); // end of content
190
         elem.up(); // end of content
171
     });
191
     });
192
+    */
172
 
193
 
173
     this.connection.sendIQ(elem,
194
     this.connection.sendIQ(elem,
174
         function (result) {
195
         function (result) {
200
             this.channels[j].push(tmp[j]);
221
             this.channels[j].push(tmp[j]);
201
         }
222
         }
202
     }
223
     }
203
-    console.log('remote channels', this.channels);
204
-    var localSDP = new SDP(this.peerconnection.localDescription.sdp);
205
-    localSDP.removeSessionLines('a=group:');
206
-    localSDP.removeSessionLines('a=msid-semantic:');
207
 
224
 
208
-    if (this.drip_container.length) {
209
-        this.sendIceCandidates(this.drip_container);
210
-        this.drip_container = [];
211
-    }
225
+    console.log('remote channels', this.channels);
212
 
226
 
213
-    // establish our channel with the bridge
214
-    // static answer taken from chrome M31, should be replaced by a 
215
-    // dynamic one that is based on our offer FIXME
216
-    var bridgeSDP = new SDP("");
217
-    // var bridgeSDP = new SDP('v=0\r\no=- 5151055458874951233 2 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\nm=audio 1 RTP/SAVPF 111 103 104 0 8 106 105 13 126\r\nc=IN IP4 0.0.0.0\r\na=rtcp:1 IN IP4 0.0.0.0\r\na=mid:audio\r\na=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level\r\na=sendrecv\r\na=rtpmap:111 opus/48000/2\r\na=fmtp:111 minptime=10\r\na=rtpmap:103 ISAC/16000\r\na=rtpmap:104 ISAC/32000\r\na=rtpmap:0 PCMU/8000\r\na=rtpmap:8 PCMA/8000\r\na=rtpmap:106 CN/32000\r\na=rtpmap:105 CN/16000\r\na=rtpmap:13 CN/8000\r\na=rtpmap:126 telephone-event/8000\r\na=maxptime:60\r\nm=video 1 RTP/SAVPF 100 116 117\r\nc=IN IP4 0.0.0.0\r\na=rtcp:1 IN IP4 0.0.0.0\r\na=mid:video\r\na=extmap:2 urn:ietf:params:rtp-hdrext:toffset\r\na=extmap:3 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time\r\na=sendrecv\r\na=rtpmap:100 VP8/90000\r\na=rtcp-fb:100 ccm fir\r\na=rtcp-fb:100 nack\r\na=rtcp-fb:100 goog-remb\r\na=rtpmap:116 red/90000\r\na=rtpmap:117 ulpfec/90000\r\n');
218
-    // only do what's in the offer
219
-    bridgeSDP.session = localSDP.session;
220
-    bridgeSDP.media.length = localSDP.media.length;
227
+    var bridgeSDP = new SDP('v=0\r\no=- 5151055458874951233 2 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\nm=audio 1 RTP/SAVPF 111 103 104 0 8 106 105 13 126\r\nc=IN IP4 0.0.0.0\r\na=rtcp:1 IN IP4 0.0.0.0\r\na=mid:audio\r\na=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level\r\na=sendrecv\r\na=rtpmap:111 opus/48000/2\r\na=fmtp:111 minptime=10\r\na=rtpmap:103 ISAC/16000\r\na=rtpmap:104 ISAC/32000\r\na=rtpmap:0 PCMU/8000\r\na=rtpmap:8 PCMA/8000\r\na=rtpmap:106 CN/32000\r\na=rtpmap:105 CN/16000\r\na=rtpmap:13 CN/8000\r\na=rtpmap:126 telephone-event/8000\r\na=maxptime:60\r\nm=video 1 RTP/SAVPF 100 116 117\r\nc=IN IP4 0.0.0.0\r\na=rtcp:1 IN IP4 0.0.0.0\r\na=mid:video\r\na=extmap:2 urn:ietf:params:rtp-hdrext:toffset\r\na=extmap:3 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time\r\na=sendrecv\r\na=rtpmap:100 VP8/90000\r\na=rtcp-fb:100 ccm fir\r\na=rtcp-fb:100 nack\r\na=rtcp-fb:100 goog-remb\r\na=rtpmap:116 red/90000\r\na=rtpmap:117 ulpfec/90000\r\n');
228
+    bridgeSDP.media.length = this.mychannel.length;
221
     var channel;
229
     var channel;
230
+    /*
222
     for (channel = 0; channel < bridgeSDP.media.length; channel++) {
231
     for (channel = 0; channel < bridgeSDP.media.length; channel++) {
223
         bridgeSDP.media[channel] = '';
232
         bridgeSDP.media[channel] = '';
224
         // unchanged lines
233
         // unchanged lines
249
         }
258
         }
250
         // FIXME: changed lines -- a=sendrecv direction, a=setup direction
259
         // FIXME: changed lines -- a=sendrecv direction, a=setup direction
251
     }
260
     }
252
-    // get the mixed ssrc
261
+    */
253
     for (channel = 0; channel < bridgeSDP.media.length; channel++) {
262
     for (channel = 0; channel < bridgeSDP.media.length; channel++) {
263
+        // get the mixed ssrc
254
         tmp = $(this.mychannel[channel]).find('>source[xmlns="urn:xmpp:jingle:apps:rtp:ssma:0"]');
264
         tmp = $(this.mychannel[channel]).find('>source[xmlns="urn:xmpp:jingle:apps:rtp:ssma:0"]');
255
         // FIXME: check rtp-level-relay-type
265
         // FIXME: check rtp-level-relay-type
256
         if (tmp.length) {
266
         if (tmp.length) {
278
             tmp = tmp.find('>fingerprint');
288
             tmp = tmp.find('>fingerprint');
279
             if (tmp.length) {
289
             if (tmp.length) {
280
                 bridgeSDP.media[channel] += 'a=fingerprint:' + tmp.attr('hash') + ' ' + tmp.text() + '\r\n';
290
                 bridgeSDP.media[channel] += 'a=fingerprint:' + tmp.attr('hash') + ' ' + tmp.text() + '\r\n';
281
-                if (tmp.attr('setup')) {
282
-                    bridgeSDP.media[channel] += 'a=setup:' + tmp.attr('setup') + '\r\n';
283
-                } else {
284
-                    bridgeSDP.media[channel] += 'a=setup:active\r\n';
285
-                }
291
+                bridgeSDP.media[channel] += 'a=setup:actpass\r\n'; // offer so always actpass
286
             }
292
             }
287
         }
293
         }
288
     }
294
     }
289
     bridgeSDP.raw = bridgeSDP.session + bridgeSDP.media.join('');
295
     bridgeSDP.raw = bridgeSDP.session + bridgeSDP.media.join('');
290
 
296
 
291
     this.peerconnection.setRemoteDescription(
297
     this.peerconnection.setRemoteDescription(
292
-        new RTCSessionDescription({type: 'answer', sdp: bridgeSDP.raw}),
298
+        new RTCSessionDescription({type: 'offer', sdp: bridgeSDP.raw}),
293
         function () {
299
         function () {
294
             console.log('setRemoteDescription success');
300
             console.log('setRemoteDescription success');
301
+            self.peerconnection.createAnswer(
302
+                function (answer) {
303
+                    self.peerconnection.setLocalDescription(answer,
304
+                        function () {
305
+                            console.log('setLocalDescription succeded.');
306
+                            // make sure our presence is updated
307
+                            $(document).trigger('setLocalDescription.jingle', [self.sid]);
308
+                            var elem = $iq({to: self.bridgejid, type: 'get'});
309
+                            elem.c('conference', {xmlns: 'http://jitsi.org/protocol/colibri', id: self.confid});
310
+                            var localSDP = new SDP(self.peerconnection.localDescription.sdp);
311
+                            localSDP.media.forEach(function (media, channel) {
312
+                                var name = SDPUtil.parse_mline(media.split('\r\n')[0]).media; 
313
+                                elem.c('content', {name: name});
314
+                                elem.c('channel', {
315
+                                    initiator: 'true', 
316
+                                    expire: '15',
317
+                                    id: self.mychannel[channel].attr('id')
318
+                                });
319
+
320
+                                // FIXME: should reuse code from .toJingle
321
+                                var mline = SDPUtil.parse_mline(media.split('\r\n')[0]);
322
+                                for (var j = 0; j < mline.fmt.length; j++) {
323
+                                    var rtpmap = SDPUtil.find_line(media, 'a=rtpmap:' + mline.fmt[j]);
324
+                                    elem.c('payload-type', SDPUtil.parse_rtpmap(rtpmap));
325
+                                    elem.up();
326
+                                }
327
+
328
+                                localSDP.TransportToJingle(channel, elem);
329
+
330
+                                elem.up(); // end of channel
331
+                                for (j = 0; j < self.peers.length; j++) {
332
+                                    elem.c('channel', {initiator: 'true', expire:'15' }).up();
333
+                                }
334
+                                elem.up(); // end of content
335
+                            });
336
+
337
+                            self.connection.sendIQ(elem,
338
+                                function (result) {
339
+                                    // ...
340
+                                },
341
+                                function (error) {
342
+                                    console.warn(error);
343
+                                }
344
+                            );
345
+
346
+                            // now initiate sessions
347
+                            for (var i = 0; i < numparticipants; i++) {
348
+                                self.initiate(self.peers[i], true);
349
+                            }
350
+                        },
351
+                        function (error) {
352
+                            console.warn('setLocalDescription failed.', error);
353
+                        }
354
+                    );
355
+                },
356
+                function (error) {
357
+                    console.warn('createAnswer failed.', error);
358
+                }
359
+            );
360
+            /*
295
             for (var i = 0; i < numparticipants; i++) {
361
             for (var i = 0; i < numparticipants; i++) {
296
                 self.initiate(self.peers[i], true);
362
                 self.initiate(self.peers[i], true);
297
             }
363
             }
364
+            */
298
         },
365
         },
299
         function (error) {
366
         function (error) {
300
-            console.log('setRemoteDescription failed');
367
+            console.log('setRemoteDescription failed.', error);
301
         }
368
         }
302
     );
369
     );
303
 
370
 
674
             mycands.up(); // content
741
             mycands.up(); // content
675
         }
742
         }
676
     }
743
     }
744
+    console.log('send cands', candidates);
677
     this.connection.sendIQ(mycands,
745
     this.connection.sendIQ(mycands,
678
         function (res) {
746
         function (res) {
679
             console.log('got result');
747
             console.log('got result');
769
     this.removessrc = [];
837
     this.removessrc = [];
770
 
838
 
771
     sdp.raw = sdp.session + sdp.media.join('');
839
     sdp.raw = sdp.session + sdp.media.join('');
772
-    /*
773
-     * this seems to create a number of problems...
774
     this.peerconnection.setRemoteDescription(
840
     this.peerconnection.setRemoteDescription(
775
         new RTCSessionDescription({type: 'offer', sdp: sdp.raw }),
841
         new RTCSessionDescription({type: 'offer', sdp: sdp.raw }),
776
         function () {
842
         function () {
803
             console.log('setModifiedRemoteDescription failed');
869
             console.log('setModifiedRemoteDescription failed');
804
         }
870
         }
805
     );
871
     );
806
-    */
872
+    /*
873
+     * now that we have a passive focus, this way is bad again! :-)
807
     this.peerconnection.createOffer(
874
     this.peerconnection.createOffer(
808
         function (modifiedOffer) {
875
         function (modifiedOffer) {
809
             console.log('created (un)modified offer');
876
             console.log('created (un)modified offer');
830
             console.log('creating (un)modified offerfailed');
897
             console.log('creating (un)modified offerfailed');
831
         }
898
         }
832
     );
899
     );
900
+    */
833
 };
901
 };
834
 
902
 
835
 
903
 

Loading…
取消
儲存