Explorar el Código

sdp: refactor jingle2media

using more specific selectors
tags/v0.0.2
Philipp Hancke hace 5 años
padre
commit
72c00b6a4d
Se han modificado 2 ficheros con 45 adiciones y 46 borrados
  1. 41
    42
      modules/xmpp/SDP.js
  2. 4
    4
      modules/xmpp/SDP.spec.js

+ 41
- 42
modules/xmpp/SDP.js Ver fichero

@@ -578,10 +578,11 @@ SDP.prototype.fromJingle = function(jingle) {
578 578
 
579 579
 // translate a jingle content element into an an SDP media part
580 580
 SDP.prototype.jingle2media = function(content) {
581
-    const desc = content.find('description');
581
+    const desc = content.find('>description');
582
+    const transport = content.find('>transport[xmlns="urn:xmpp:jingle:transports:ice-udp:1"]');
582 583
     let media = '';
583
-    const sctp = content.find(
584
-        '>transport>sctpmap[xmlns="urn:xmpp:jingle:transports:dtls-sctp:1"]');
584
+    const sctp = transport.find(
585
+        '>sctpmap[xmlns="urn:xmpp:jingle:transports:dtls-sctp:1"]');
585 586
 
586 587
     let tmp = { media: desc.attr('media') };
587 588
 
@@ -590,7 +591,7 @@ SDP.prototype.jingle2media = function(content) {
590 591
         // estos hack to reject an m-line.
591 592
         tmp.port = '0';
592 593
     }
593
-    if (content.find('>transport>fingerprint[xmlns="urn:xmpp:jingle:apps:dtls:0"]').length) {
594
+    if (transport.find('>fingerprint[xmlns="urn:xmpp:jingle:apps:dtls:0"]').length) {
594 595
         tmp.proto = sctp.length ? 'DTLS/SCTP' : 'RTP/SAVPF';
595 596
     } else {
596 597
         tmp.proto = 'RTP/AVPF';
@@ -610,7 +611,7 @@ SDP.prototype.jingle2media = function(content) {
610 611
     } else {
611 612
         tmp.fmt
612 613
             = desc
613
-                .find('payload-type')
614
+                .find('>payload-type')
614 615
                 .map((_, payloadType) => payloadType.getAttribute('id'))
615 616
                 .get();
616 617
         media += `${SDPUtil.buildMLine(tmp)}\r\n`;
@@ -620,17 +621,16 @@ SDP.prototype.jingle2media = function(content) {
620 621
     if (!sctp.length) {
621 622
         media += 'a=rtcp:1 IN IP4 0.0.0.0\r\n';
622 623
     }
623
-    tmp
624
-        = content.find(
625
-            '>transport[xmlns="urn:xmpp:jingle:transports:ice-udp:1"]');
626
-    if (tmp.length) {
627
-        if (tmp.attr('ufrag')) {
628
-            media += `${SDPUtil.buildICEUfrag(tmp.attr('ufrag'))}\r\n`;
624
+
625
+    // XEP-0176 ICE parameters
626
+    if (transport.length) {
627
+        if (transport.attr('ufrag')) {
628
+            media += `${SDPUtil.buildICEUfrag(transport.attr('ufrag'))}\r\n`;
629 629
         }
630
-        if (tmp.attr('pwd')) {
631
-            media += `${SDPUtil.buildICEPwd(tmp.attr('pwd'))}\r\n`;
630
+        if (transport.attr('pwd')) {
631
+            media += `${SDPUtil.buildICEPwd(transport.attr('pwd'))}\r\n`;
632 632
         }
633
-        tmp.find('>fingerprint[xmlns="urn:xmpp:jingle:apps:dtls:0"]').each((_, fingerprint) => {
633
+        transport.find('>fingerprint[xmlns="urn:xmpp:jingle:apps:dtls:0"]').each((_, fingerprint) => {
634 634
             media += `a=fingerprint:${fingerprint.getAttribute('hash')}`;
635 635
             media += ` ${$(fingerprint).text()}`;
636 636
             media += '\r\n';
@@ -639,6 +639,26 @@ SDP.prototype.jingle2media = function(content) {
639 639
             }
640 640
         });
641 641
     }
642
+
643
+    // XEP-0176 ICE candidates
644
+    transport.find('>candidate')
645
+        .each((_, candidate) => {
646
+            let protocol = candidate.getAttribute('protocol');
647
+
648
+            protocol
649
+                = typeof protocol === 'string' ? protocol.toLowerCase() : '';
650
+
651
+            if ((this.removeTcpCandidates
652
+                    && (protocol === 'tcp' || protocol === 'ssltcp'))
653
+                || (this.removeUdpCandidates && protocol === 'udp')) {
654
+                return;
655
+            } else if (this.failICE) {
656
+                candidate.setAttribute('ip', '1.1.1.1');
657
+            }
658
+
659
+            media += SDPUtil.candidateFromJingle(candidate);
660
+        });
661
+
642 662
     switch (content.attr('senders')) {
643 663
     case 'initiator':
644 664
         media += 'a=sendonly\r\n';
@@ -659,17 +679,17 @@ SDP.prototype.jingle2media = function(content) {
659 679
     // see http://code.google.com/p/libjingle/issues/detail?id=309 -- no spec
660 680
     // though
661 681
     // and http://mail.jabber.org/pipermail/jingle/2011-December/001761.html
662
-    if (desc.find('rtcp-mux').length) {
682
+    if (desc.find('>rtcp-mux').length) {
663 683
         media += 'a=rtcp-mux\r\n';
664 684
     }
665 685
 
666
-    desc.find('payload-type').each((_, payloadType) => {
686
+    desc.find('>payload-type').each((_, payloadType) => {
667 687
         media += `${SDPUtil.buildRTPMap(payloadType)}\r\n`;
668 688
         if ($(payloadType).find('>parameter').length) {
669 689
             media += `a=fmtp:${payloadType.getAttribute('id')} `;
670 690
             media
671 691
                 += $(payloadType)
672
-                    .find('parameter')
692
+                    .find('>parameter')
673 693
                     .map((__, parameter) => {
674 694
                         const name = parameter.getAttribute('name');
675 695
 
@@ -699,30 +719,9 @@ SDP.prototype.jingle2media = function(content) {
699 719
                 hdrExt.getAttribute('uri')}\r\n`;
700 720
     });
701 721
 
702
-    content
703
-        .find(
704
-            '>transport[xmlns="urn:xmpp:jingle:transports:ice-udp:1"]'
705
-                + '>candidate')
706
-        .each((_, transport) => {
707
-            let protocol = transport.getAttribute('protocol');
708
-
709
-            protocol
710
-                = typeof protocol === 'string' ? protocol.toLowerCase() : '';
711
-
712
-            if ((this.removeTcpCandidates
713
-                    && (protocol === 'tcp' || protocol === 'ssltcp'))
714
-                || (this.removeUdpCandidates && protocol === 'udp')) {
715
-                return;
716
-            } else if (this.failICE) {
717
-                transport.setAttribute('ip', '1.1.1.1');
718
-            }
719
-
720
-            media += SDPUtil.candidateFromJingle(transport);
721
-        });
722
-
723 722
     // XEP-0339 handle ssrc-group attributes
724
-    content
725
-        .find('description>ssrc-group[xmlns="urn:xmpp:jingle:apps:rtp:ssma:0"]')
723
+    desc
724
+        .find('>ssrc-group[xmlns="urn:xmpp:jingle:apps:rtp:ssma:0"]')
726 725
         .each((_, ssrcGroup) => {
727 726
             const semantics = ssrcGroup.getAttribute('semantics');
728 727
             const ssrcs
@@ -737,8 +736,8 @@ SDP.prototype.jingle2media = function(content) {
737 736
         });
738 737
 
739 738
     tmp
740
-        = content.find(
741
-            'description>source[xmlns="urn:xmpp:jingle:apps:rtp:ssma:0"]');
739
+        = desc.find(
740
+            '>source[xmlns="urn:xmpp:jingle:apps:rtp:ssma:0"]');
742 741
     tmp.each((_, source) => {
743 742
         const ssrc = source.getAttribute('ssrc');
744 743
 

+ 4
- 4
modules/xmpp/SDP.spec.js Ver fichero

@@ -183,6 +183,8 @@ a=ice-ufrag:someufrag
183 183
 a=ice-pwd:somepwd
184 184
 a=fingerprint:sha-256 09:B1:51:0F:85:4C:80:19:A1:AF:81:73:47:EE:ED:3D:00:3A:84:C7:76:C1:4E:34:BE:56:F6:42:AD:15:D5:D7
185 185
 a=setup:actpass
186
+a=candidate:1 1 udp 2130706431 10.0.0.1 10000 typ host generation 0
187
+a=candidate:2 1 udp 1694498815 10.0.0.2 10000 typ srflx raddr 10.0.0.1 rport 10000 generation 0
186 188
 a=sendrecv
187 189
 a=mid:audio
188 190
 a=rtcp-mux
@@ -195,8 +197,6 @@ a=rtpmap:126 telephone-event/8000
195 197
 a=fmtp:126 0-15
196 198
 a=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level
197 199
 a=extmap:5 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01
198
-a=candidate:1 1 udp 2130706431 10.0.0.1 10000 typ host generation 0
199
-a=candidate:2 1 udp 1694498815 10.0.0.2 10000 typ srflx raddr 10.0.0.1 rport 10000 generation 0
200 200
 a=ssrc:4039389863 cname:mixed
201 201
 a=ssrc:4039389863 label:mixedlabelaudio0
202 202
 a=ssrc:4039389863 msid:mixedmslabel mixedlabelaudio0
@@ -208,6 +208,8 @@ a=ice-ufrag:someufrag
208 208
 a=ice-pwd:somepwd
209 209
 a=fingerprint:sha-256 09:B1:51:0F:85:4C:80:19:A1:AF:81:73:47:EE:ED:3D:00:3A:84:C7:76:C1:4E:34:BE:56:F6:42:AD:15:D5:D7
210 210
 a=setup:actpass
211
+a=candidate:1 1 udp 2130706431 10.0.0.1 10000 typ host generation 0
212
+a=candidate:2 1 udp 1694498815 10.0.0.2 10000 typ srflx raddr 10.0.0.1 rport 10000 generation 0
211 213
 a=sendrecv
212 214
 a=mid:video
213 215
 a=rtcp-mux
@@ -225,8 +227,6 @@ a=rtcp-fb:96 nack
225 227
 a=rtcp-fb:96 nack pli
226 228
 a=extmap:3 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
227 229
 a=extmap:5 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01
228
-a=candidate:1 1 udp 2130706431 10.0.0.1 10000 typ host generation 0
229
-a=candidate:2 1 udp 1694498815 10.0.0.2 10000 typ srflx raddr 10.0.0.1 rport 10000 generation 0
230 230
 a=ssrc:3758540092 cname:mixed
231 231
 a=ssrc:3758540092 label:mixedlabelvideo0
232 232
 a=ssrc:3758540092 msid:mixedmslabel mixedlabelvideo0

Loading…
Cancelar
Guardar