Преглед на файлове

Adopts XEP-0343 for DTLS/SCTP Jingle signaling.

j8
paweldomas преди 11 години
родител
ревизия
be42629a63
променени са 3 файла, в които са добавени 42 реда и са изтрити 32 реда
  1. 2
    2
      libs/colibri/colibri.focus.js
  2. 34
    28
      libs/strophe/strophe.jingle.sdp.js
  3. 6
    2
      libs/strophe/strophe.jingle.sdp.util.js

+ 2
- 2
libs/colibri/colibri.focus.js Целия файл

@@ -423,7 +423,7 @@ ColibriFocus.prototype.createdConference = function (result) {
423 423
                                 else
424 424
                                 {
425 425
                                     var sctpmap = SDPUtil.find_line(media, 'a=sctpmap:' + mline.fmt[0]);
426
-                                    var sctpPort = SDPUtil.parse_sctpmap(sctpmap);
426
+                                    var sctpPort = SDPUtil.parse_sctpmap(sctpmap)[0];
427 427
                                     elem.c("sctpconnection",
428 428
                                         {
429 429
                                             initiator: 'true',
@@ -712,7 +712,7 @@ ColibriFocus.prototype.updateChannel = function (remoteSDP, participant) {
712 712
             change.c('sctpconnection', {
713 713
                 endpoint: $(this.channels[participant][channel]).attr('endpoint'),
714 714
                 expire: self.channelExpire,
715
-                port: SDPUtil.parse_sctpmap(sctpmap)
715
+                port: SDPUtil.parse_sctpmap(sctpmap)[0]
716 716
             });
717 717
         }
718 718
         // now add transport

+ 34
- 28
libs/strophe/strophe.jingle.sdp.js Целия файл

@@ -179,24 +179,6 @@ SDP.prototype.toJingle = function (elem, thecreator) {
179 179
                 bundle.splice(bundle.indexOf(mid), 1);
180 180
             }
181 181
         }
182
-        // Sctp
183
-        if (SDPUtil.find_line(this.media[i], 'a=sctpmap:').length)
184
-        {
185
-            for (j = 0; j < mline.fmt.length; j++)
186
-            {
187
-                var sctpmap = SDPUtil.find_line(
188
-                    this.media[i], 'a=sctpmap:' + mline.fmt[j]);
189
-                if (sctpmap)
190
-                {
191
-                    elem.c('sctp',
192
-                        {
193
-                            xmlns: 'http://jitsi.org/ns/sctp',
194
-                            port : SDPUtil.parse_sctpmap(sctpmap)
195
-                        });
196
-                    elem.up();
197
-                }
198
-            }
199
-        }
200 182
 
201 183
         if (SDPUtil.find_line(this.media[i], 'a=rtpmap:').length)
202 184
         {
@@ -327,6 +309,26 @@ SDP.prototype.TransportToJingle = function (mediaindex, elem) {
327 309
     var self = this;
328 310
     elem.c('transport');
329 311
 
312
+    // XEP-0343 DTLS/SCTP
313
+    if (SDPUtil.find_line(this.media[mediaindex], 'a=sctpmap:').length)
314
+    {
315
+        var sctpmap = SDPUtil.find_line(
316
+            this.media[i], 'a=sctpmap:', self.session);
317
+        if (sctpmap)
318
+        {
319
+            var sctpAttrs = SDPUtil.parse_sctpmap(sctpmap);
320
+            elem.c('sctpmap',
321
+                {
322
+                    xmlns: 'urn:xmpp:jingle:transports:dtls-sctp:1',
323
+                    number: sctpAttrs[0], /* SCTP port */
324
+                    protocol: sctpAttrs[1], /* protocol */
325
+                });
326
+            // Optional stream count attribute
327
+            if (sctpAttrs.length > 2)
328
+                elem.attrs({ streams: sctpAttrs[2]});
329
+            elem.up();
330
+        }
331
+    }
330 332
     // XEP-0320
331 333
     var fingerprints = SDPUtil.find_lines(this.media[mediaindex], 'a=fingerprint:', this.session);
332 334
     fingerprints.forEach(function(line) {
@@ -461,11 +463,8 @@ SDP.prototype.jingle2media = function (content) {
461 463
         ssrc = desc.attr('ssrc'),
462 464
         self = this,
463 465
         tmp;
464
-    var sctp = null;
465
-    if (!desc.length)
466
-    {
467
-        sctp = content.find('sctp');
468
-    }
466
+    var sctp = content.find(
467
+        '>transport>sctpmap[xmlns="urn:xmpp:jingle:transports:dtls-sctp:1"]');
469 468
 
470 469
     tmp = { media: desc.attr('media') };
471 470
     tmp.port = '1';
@@ -474,14 +473,14 @@ SDP.prototype.jingle2media = function (content) {
474 473
         tmp.port = '0';
475 474
     }
476 475
     if (content.find('>transport>fingerprint').length || desc.find('encryption').length) {
477
-        if (sctp)
476
+        if (sctp.length)
478 477
             tmp.proto = 'DTLS/SCTP';
479 478
         else
480 479
             tmp.proto = 'RTP/SAVPF';
481 480
     } else {
482 481
         tmp.proto = 'RTP/AVPF';
483 482
     }
484
-    if (!sctp)
483
+    if (!sctp.length)
485 484
     {
486 485
         tmp.fmt = desc.find('payload-type').map(
487 486
             function () { return this.getAttribute('id'); }).get();
@@ -489,12 +488,19 @@ SDP.prototype.jingle2media = function (content) {
489 488
     }
490 489
     else
491 490
     {
492
-        media += 'm=application 1 DTLS/SCTP ' + sctp.attr('port') + '\r\n';
493
-        media += 'a=sctpmap:' + sctp.attr('port') + ' webrtc-datachannel\r\n';
491
+        media += 'm=application 1 DTLS/SCTP ' + sctp.attr('number') + '\r\n';
492
+        media += 'a=sctpmap:' + sctp.attr('number') +
493
+            ' ' + sctp.attr('protocol');
494
+
495
+        var streamCount = sctp.attr('streams');
496
+        if (streamCount)
497
+            media += ' ' + streamCount + '\r\n';
498
+        else
499
+            media += '\r\n';
494 500
     }
495 501
 
496 502
     media += 'c=IN IP4 0.0.0.0\r\n';
497
-    if (!sctp)
503
+    if (!sctp.length)
498 504
         media += 'a=rtcp:1 IN IP4 0.0.0.0\r\n';
499 505
     tmp = content.find('>transport[xmlns="urn:xmpp:jingle:transports:ice-udp:1"]');
500 506
     if (tmp.length) {

+ 6
- 2
libs/strophe/strophe.jingle.sdp.util.js Целия файл

@@ -93,12 +93,16 @@ SDPUtil = {
93 93
     /**
94 94
      * Parses SDP line "a=sctpmap:..." and extracts SCTP port from it.
95 95
      * @param line eg. "a=sctpmap:5000 webrtc-datachannel"
96
-     * @returns SCTP port number
96
+     * @returns [SCTP port number, protocol, streams]
97 97
      */
98 98
     parse_sctpmap: function (line)
99 99
     {
100 100
         var parts = line.substring(10).split(' ');
101
-        return parts[0];// SCTP port
101
+        var sctpPort = parts[0];
102
+        var protocol = parts[1];
103
+        // Stream count is optional
104
+        var streamCount = parts.length > 2 ? parts[2] : null;
105
+        return [sctpPort, protocol, streamCount];// SCTP port
102 106
     },
103 107
     build_rtpmap: function (el) {
104 108
         var line = 'a=rtpmap:' + el.getAttribute('id') + ' ' + el.getAttribute('name') + '/' + el.getAttribute('clockrate');

Loading…
Отказ
Запис