Просмотр исходного кода

Merge pull request #562 from jitsi/fix_no_tracks

fix(JSPC): local tracks not advertised
dev1
Saúl Ibarra Corretgé 8 лет назад
Родитель
Сommit
5cddc707e5
1 измененных файлов: 54 добавлений и 50 удалений
  1. 54
    50
      modules/xmpp/JingleSessionPC.js

+ 54
- 50
modules/xmpp/JingleSessionPC.js Просмотреть файл

@@ -736,12 +736,22 @@ export default class JingleSessionPC extends JingleSession {
736 736
                 this.peerconnection.addTrack(localTrack);
737 737
             }
738 738
             this.peerconnection.createOffer(
739
-                sdp => {
740
-                    this.sendSessionInitiate(
741
-                        sdp,
742
-                        finishedCallback,
743
-                        finishedCallback
744
-                    );
739
+                offerSdp => {
740
+                    this.peerconnection.setLocalDescription(
741
+                        offerSdp,
742
+                        () => {
743
+                            // NOTE that the offer is obtained from
744
+                            // the localDescription getter as it needs to go
745
+                            // though the transformation chain.
746
+                            this.sendSessionInitiate(
747
+                                this.peerconnection.localDescription.sdp);
748
+                            finishedCallback();
749
+                        },
750
+                        error => {
751
+                            logger.error(
752
+                                'Failed to set local SDP', error, offerSdp);
753
+                            finishedCallback(error);
754
+                        });
745 755
                 },
746 756
                 error => {
747 757
                     logger.error(
@@ -766,53 +776,38 @@ export default class JingleSessionPC extends JingleSession {
766 776
 
767 777
     /**
768 778
      * Sends 'session-initiate' to the remote peer.
769
-     * @param {object} sdp the local session description object as defined by
770
-     * the WebRTC standard.
771
-     * @param {function} success executed when the operation succeeds.
772
-     * @param {function(error)} failure executed when the operation fails with
773
-     * an error passed as an argument.
779
+     *
780
+     * NOTE this method is synchronous and we're not waiting for the RESULT
781
+     * response which would delay the startup process.
782
+     *
783
+     * @param {string} offerSdp  - The local session description which will be
784
+     * used to generate an offer.
774 785
      * @private
775 786
      */
776
-    sendSessionInitiate(sdp, success, failure) {
777
-        logger.log('createdOffer', sdp);
778
-        const sendJingle = () => {
779
-            let init = $iq({
780
-                to: this.peerjid,
781
-                type: 'set'
782
-            }).c('jingle', {
783
-                xmlns: 'urn:xmpp:jingle:1',
784
-                action: 'session-initiate',
785
-                initiator: this.initiator,
786
-                sid: this.sid
787
-            });
788
-            const localSDP = new SDP(this.peerconnection.localDescription.sdp);
789
-
790
-            localSDP.toJingle(
791
-                init,
792
-                this.initiator === this.me ? 'initiator' : 'responder');
793
-            init = init.tree();
794
-            logger.info('Session-initiate: ', init);
795
-            this.connection.sendIQ(init,
796
-                () => {
797
-                    logger.info('Got RESULT for "session-initiate"');
798
-                },
799
-                error => {
800
-                    logger.error('"session-initiate" error', error);
801
-                },
802
-                IQ_TIMEOUT);
803
-
804
-            // NOTE the callback is executed immediately as we don't want to
805
-            // wait for the XMPP response which would delay the startup process.
806
-            success();
807
-        };
787
+    sendSessionInitiate(offerSdp) {
788
+        let init = $iq({
789
+            to: this.peerjid,
790
+            type: 'set'
791
+        }).c('jingle', {
792
+            xmlns: 'urn:xmpp:jingle:1',
793
+            action: 'session-initiate',
794
+            initiator: this.initiator,
795
+            sid: this.sid
796
+        });
808 797
 
809
-        this.peerconnection.setLocalDescription(
810
-            sdp, sendJingle,
798
+        new SDP(offerSdp).toJingle(
799
+            init,
800
+            this.initiator === this.me ? 'initiator' : 'responder');
801
+        init = init.tree();
802
+        logger.info('Session-initiate: ', init);
803
+        this.connection.sendIQ(init,
804
+            () => {
805
+                logger.info('Got RESULT for "session-initiate"');
806
+            },
811 807
             error => {
812
-                logger.error('session-init setLocalDescription failed', error);
813
-                failure(error);
814
-            }
815
-        );
808
+                logger.error('"session-initiate" error', error);
809
+            },
810
+            IQ_TIMEOUT);
816 811
     }
817 812
 
818 813
     /**
@@ -1534,7 +1529,16 @@ export default class JingleSessionPC extends JingleSession {
1534 1529
             this.peerconnection.setRemoteDescription(
1535 1530
                 remoteDescription,
1536 1531
                 () => {
1537
-                    resolve();
1532
+                    // In case when the answer is being set for the first time,
1533
+                    // full sRD/sLD cycle is required to have the local
1534
+                    // description updated and SSRCs synchronized correctly.
1535
+                    // Otherwise SSRCs for streams added after invite, but
1536
+                    // before the answer was accepted will not be detected.
1537
+                    // The reason for that is that renegotiate can not be called
1538
+                    // when adding tracks and they will not be reflected in
1539
+                    // the local SDP.
1540
+                    this._initiatorRenegotiate(
1541
+                        remoteDescription, resolve, reject);
1538 1542
                 },
1539 1543
                 error => reject(`setRemoteDescription failed: ${error}`)
1540 1544
             );

Загрузка…
Отмена
Сохранить