Quellcode durchsuchen

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 vor 11 Jahren
Ursprung
Commit
69508d7734
3 geänderte Dateien mit 87 neuen und 44 gelöschten Zeilen
  1. 2
    1
      config.js
  2. 31
    7
      data_channels.js
  3. 54
    36
      libs/colibri/colibri.focus.js

+ 2
- 1
config.js Datei anzeigen

@@ -13,6 +13,7 @@ var config = {
13 13
     chromeExtensionId: 'diibjkoicjeejcmhdnailmkgecihlobk', // Id of desktop streamer Chrome extension
14 14
     minChromeExtVersion: '0.1', // Required version of Chrome extension
15 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 18
     enableRecording: false
18 19
 };

+ 31
- 7
data_channels.js Datei anzeigen

@@ -10,7 +10,7 @@ function onDataChannel(event)
10 10
 
11 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 15
         // Code sample for sending string and/or binary data
16 16
         // Sends String message to the bridge
@@ -26,19 +26,42 @@ function onDataChannel(event)
26 26
 
27 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 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 39
             console.info(
39 40
                 "Data channel new active speaker event: " + resourceJid);
40 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 67
     dataChannel.onclose = function ()
@@ -77,4 +100,5 @@ function bindDataChannelListener(peerConnection)
77 100
         var msgData = event.data;
78 101
         console.info("Got My Data Channel Message:", msgData, dataChannel);
79 102
     };*/
80
-}
103
+}
104
+

+ 54
- 36
libs/colibri/colibri.focus.js Datei anzeigen

@@ -54,17 +54,16 @@ function ColibriFocus(connection, bridgejid) {
54 54
      * Default channel expire value in seconds.
55 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 62
     // media types of the conference
60 63
     if (config.openSctp)
61
-    {
62 64
         this.media = ['audio', 'video', 'data'];
63
-    }
64 65
     else
65
-    {
66 66
         this.media = ['audio', 'video'];
67
-    }
68 67
 
69 68
     this.connection.jingle.sessions[this.sid] = this;
70 69
     this.mychannel = [];
@@ -202,29 +201,38 @@ ColibriFocus.prototype._makeConference = function () {
202 201
     elem.c('conference', {xmlns: 'http://jitsi.org/protocol/colibri'});
203 202
 
204 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 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 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 237
         elem.up(); // end of content
230 238
     });
@@ -233,7 +241,7 @@ ColibriFocus.prototype._makeConference = function () {
233 241
     localSDP.media.forEach(function (media, channel) {
234 242
         var name = SDPUtil.parse_mline(media.split('\r\n')[0]).media;
235 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 246
         // FIXME: should reuse code from .toJingle
239 247
         var mline = SDPUtil.parse_mline(media.split('\r\n')[0]);
@@ -247,7 +255,7 @@ ColibriFocus.prototype._makeConference = function () {
247 255
 
248 256
         elem.up(); // end of channel
249 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 260
         elem.up(); // end of content
253 261
     });
@@ -662,24 +670,33 @@ ColibriFocus.prototype.addNewParticipant = function (peer) {
662 670
     var localSDP = new SDP(this.peerconnection.localDescription.sdp);
663 671
     localSDP.media.forEach(function (media, channel) {
664 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 676
                 initiator: 'true',
670 677
                 expire: self.channelExpire,
671 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 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 700
         elem.up(); // end of channel/sctpconnection
684 701
         elem.up(); // end of content
685 702
     });
@@ -1186,4 +1203,5 @@ ColibriFocus.prototype.setRTCPTerminationStrategy = function (strategyFQN) {
1186 1203
             console.error('got error', err);
1187 1204
         }
1188 1205
     );
1206
+};
1189 1207
 

Laden…
Abbrechen
Speichern