Browse Source

Fixes a syntax error. Adds the ability to define a default value for the channel attribute last-n. Parses JSON messages from Videobridge received on the data channel. Fixes unnecessary changing of the value of the channel attribute expire from 15 to 60.

master
Lyubomir Marinov 11 years ago
parent
commit
69508d7734
3 changed files with 87 additions and 44 deletions
  1. 2
    1
      config.js
  2. 31
    7
      data_channels.js
  3. 54
    36
      libs/colibri/colibri.focus.js

+ 2
- 1
config.js View File

13
     chromeExtensionId: 'diibjkoicjeejcmhdnailmkgecihlobk', // Id of desktop streamer Chrome extension
13
     chromeExtensionId: 'diibjkoicjeejcmhdnailmkgecihlobk', // Id of desktop streamer Chrome extension
14
     minChromeExtVersion: '0.1', // Required version of Chrome extension
14
     minChromeExtVersion: '0.1', // Required version of Chrome extension
15
     enableRtpStats: false, // Enables RTP stats processing
15
     enableRtpStats: false, // Enables RTP stats processing
16
-    openSctp: true, //Toggle to enable/disable SCTP channels
16
+    openSctp: true, // Toggle to enable/disable SCTP channels
17
+//    channelLastN: -1, // The default value of the channel attribute last-n.
17
     enableRecording: false
18
     enableRecording: false
18
 };
19
 };

+ 31
- 7
data_channels.js View File

10
 
10
 
11
     dataChannel.onopen = function ()
11
     dataChannel.onopen = function ()
12
     {
12
     {
13
-        console.info("Data channel opened by the bridge !!!", dataChannel);
13
+        console.info("Data channel opened by the Videobridge!", dataChannel);
14
 
14
 
15
         // Code sample for sending string and/or binary data
15
         // Code sample for sending string and/or binary data
16
         // Sends String message to the bridge
16
         // Sends String message to the bridge
26
 
26
 
27
     dataChannel.onmessage = function (event)
27
     dataChannel.onmessage = function (event)
28
     {
28
     {
29
-        var msgData = event.data;
30
-        console.info("Got Data Channel Message:", msgData, dataChannel);
29
+        var data = event.data;
30
+
31
+        console.info("Got Data Channel Message:", data, dataChannel);
31
 
32
 
32
         // Active speaker event
33
         // Active speaker event
33
-        if (msgData.indexOf('activeSpeaker') === 0)
34
+        if (data.indexOf('activeSpeaker') === 0)
34
         {
35
         {
35
-            // Endpoint ID from the bridge
36
-            var resourceJid = msgData.split(":")[1];
36
+            // Endpoint ID from the Videobridge.
37
+            var resourceJid = data.split(":")[1];
37
 
38
 
38
             console.info(
39
             console.info(
39
                 "Data channel new active speaker event: " + resourceJid);
40
                 "Data channel new active speaker event: " + resourceJid);
40
             $(document).trigger('activespeakerchanged', [resourceJid]);
41
             $(document).trigger('activespeakerchanged', [resourceJid]);
41
         }
42
         }
43
+        else
44
+        {
45
+            // JSON
46
+            var obj;
47
+
48
+            try
49
+            {
50
+                obj = JSON.parse(data);
51
+            }
52
+            catch (e)
53
+            {
54
+                console.error(
55
+                    "Failed to parse data channel message as JSON: ",
56
+                    data,
57
+                    dataChannel);
58
+            }
59
+            if (('undefined' !== typeof(obj)) && (null !== obj))
60
+            {
61
+                // TODO Consume the JSON-formatted data channel message.
62
+                console.debug("Data channel JSON-formatted message: ", obj);
63
+            }
64
+        }
42
     };
65
     };
43
 
66
 
44
     dataChannel.onclose = function ()
67
     dataChannel.onclose = function ()
77
         var msgData = event.data;
100
         var msgData = event.data;
78
         console.info("Got My Data Channel Message:", msgData, dataChannel);
101
         console.info("Got My Data Channel Message:", msgData, dataChannel);
79
     };*/
102
     };*/
80
-}
103
+}
104
+

+ 54
- 36
libs/colibri/colibri.focus.js View File

54
      * Default channel expire value in seconds.
54
      * Default channel expire value in seconds.
55
      * @type {number}
55
      * @type {number}
56
      */
56
      */
57
-    this.channelExpire = 60;
57
+    this.channelExpire
58
+        = ('number' === typeof(config.channelExpire))
59
+            ? config.channelExpire
60
+            : 15;
58
 
61
 
59
     // media types of the conference
62
     // media types of the conference
60
     if (config.openSctp)
63
     if (config.openSctp)
61
-    {
62
         this.media = ['audio', 'video', 'data'];
64
         this.media = ['audio', 'video', 'data'];
63
-    }
64
     else
65
     else
65
-    {
66
         this.media = ['audio', 'video'];
66
         this.media = ['audio', 'video'];
67
-    }
68
 
67
 
69
     this.connection.jingle.sessions[this.sid] = this;
68
     this.connection.jingle.sessions[this.sid] = this;
70
     this.mychannel = [];
69
     this.mychannel = [];
202
     elem.c('conference', {xmlns: 'http://jitsi.org/protocol/colibri'});
201
     elem.c('conference', {xmlns: 'http://jitsi.org/protocol/colibri'});
203
 
202
 
204
     this.media.forEach(function (name) {
203
     this.media.forEach(function (name) {
205
-        var isData = name === 'data';
206
-        var channel = isData ? 'sctpconnection' : 'channel';
204
+        var elemName;
205
+        var elemAttrs = { initiator: 'true', expire: self.channelExpire };
206
+
207
+        if ('data' === name)
208
+        {
209
+            elemName = 'sctpconnection';
210
+            elemAttrs['port'] = 5000;
211
+        }
212
+        else
213
+        {
214
+            elemName = 'channel';
215
+            if ('video' === name)
216
+            {
217
+                // last-n
218
+                var lastN = config.channelLastN;
219
+                if ('undefined' !== typeof(lastN))
220
+                    elemAttrs['last-n'] = lastN;
221
+            }
222
+        }
207
 
223
 
208
         elem.c('content', {name: name});
224
         elem.c('content', {name: name});
209
 
225
 
210
-        elem.c(channel, {
211
-            initiator: 'true',
212
-            expire: '15',
213
-            endpoint: self.myMucResource
214
-        });
215
-        if (isData)
216
-            elem.attrs({port:  5000});
217
-        elem.up();// end of channel
226
+        elem.c(elemName, elemAttrs);
227
+        elem.attrs({ endpoint: self.myMucResource });
228
+        elem.up();// end of channel/sctpconnection
218
 
229
 
219
         for (var j = 0; j < self.peers.length; j++) {
230
         for (var j = 0; j < self.peers.length; j++) {
220
-            elem.c(channel, {
221
-                initiator: 'true',
222
-                expire: '15',
223
-                endpoint: self.peers[j].substr(1 + self.peers[j].lastIndexOf('/'))
224
-            });
225
-            if (isData)
226
-                elem.attrs({port: 5000});
227
-            elem.up(); // end of channel
231
+            var peer = self.peers[j];
232
+
233
+            elem.c(elemName, elemAttrs);
234
+            elem.attrs({ endpoint: peer.substr(1 + peer.lastIndexOf('/')) });
235
+            elem.up(); // end of channel/sctpconnection
228
         }
236
         }
229
         elem.up(); // end of content
237
         elem.up(); // end of content
230
     });
238
     });
233
     localSDP.media.forEach(function (media, channel) {
241
     localSDP.media.forEach(function (media, channel) {
234
         var name = SDPUtil.parse_mline(media.split('\r\n')[0]).media;
242
         var name = SDPUtil.parse_mline(media.split('\r\n')[0]).media;
235
         elem.c('content', {name: name});
243
         elem.c('content', {name: name});
236
-        elem.c('channel', {initiator: 'false', expire: '15'});
244
+        elem.c('channel', {initiator: 'false', expire: self.channelExpire});
237
 
245
 
238
         // FIXME: should reuse code from .toJingle
246
         // FIXME: should reuse code from .toJingle
239
         var mline = SDPUtil.parse_mline(media.split('\r\n')[0]);
247
         var mline = SDPUtil.parse_mline(media.split('\r\n')[0]);
247
 
255
 
248
         elem.up(); // end of channel
256
         elem.up(); // end of channel
249
         for (j = 0; j < self.peers.length; j++) {
257
         for (j = 0; j < self.peers.length; j++) {
250
-            elem.c('channel', {initiator: 'true', expire:'15' }).up();
258
+            elem.c('channel', {initiator: 'true', expire: self.channelExpire }).up();
251
         }
259
         }
252
         elem.up(); // end of content
260
         elem.up(); // end of content
253
     });
261
     });
662
     var localSDP = new SDP(this.peerconnection.localDescription.sdp);
670
     var localSDP = new SDP(this.peerconnection.localDescription.sdp);
663
     localSDP.media.forEach(function (media, channel) {
671
     localSDP.media.forEach(function (media, channel) {
664
         var name = SDPUtil.parse_mid(SDPUtil.find_line(media, 'a=mid:'));
672
         var name = SDPUtil.parse_mid(SDPUtil.find_line(media, 'a=mid:'));
665
-        elem.c('content', {name: name});
666
-        if (name !== 'data')
667
-        {
668
-            elem.c('channel', {
673
+        var elemName;
674
+        var elemAttrs
675
+            = {
669
                 initiator: 'true',
676
                 initiator: 'true',
670
                 expire: self.channelExpire,
677
                 expire: self.channelExpire,
671
                 endpoint: peer.substr(1 + peer.lastIndexOf('/'))
678
                 endpoint: peer.substr(1 + peer.lastIndexOf('/'))
672
-            });
679
+            };
680
+
681
+        if ('data' == name)
682
+        {
683
+            elemName = 'sctpconnection';
684
+            elemAttrs['port'] = 5000;
673
         }
685
         }
674
         else
686
         else
675
         {
687
         {
676
-            elem.c('sctpconnection', {
677
-                endpoint: peer.substr(1 + peer.lastIndexOf('/')),
678
-                initiator: 'true',
679
-                expire: self.channelExpire,
680
-                port: 5000
681
-            });
688
+            elemName = 'channel';
689
+            if ('video' === name)
690
+            {
691
+                // last-n
692
+                var lastN = config.channelLastN;
693
+                if ('undefined' !== typeof(lastN))
694
+                    elemAttrs['last-n'] = lastN;
695
+            }
682
         }
696
         }
697
+
698
+        elem.c('content', {name: name});
699
+        elem.c(elemName, elemAttrs);
683
         elem.up(); // end of channel/sctpconnection
700
         elem.up(); // end of channel/sctpconnection
684
         elem.up(); // end of content
701
         elem.up(); // end of content
685
     });
702
     });
1186
             console.error('got error', err);
1203
             console.error('got error', err);
1187
         }
1204
         }
1188
     );
1205
     );
1206
+};
1189
 
1207
 

Loading…
Cancel
Save