Browse Source

ref: remove JingleSession from ChatRoom

dev1
paweldomas 8 years ago
parent
commit
63a1c1ac3c
4 changed files with 97 additions and 113 deletions
  1. 93
    9
      JitsiConference.js
  2. 4
    4
      modules/RTC/JitsiLocalTrack.js
  3. 0
    92
      modules/xmpp/ChatRoom.js
  4. 0
    8
      modules/xmpp/strophe.emuc.js

+ 93
- 9
JitsiConference.js View File

@@ -47,6 +47,11 @@ function JitsiConference(options) {
47 47
     this._init(options);
48 48
     this.componentsVersions = new ComponentsVersions(this);
49 49
     this.participants = {};
50
+    /**
51
+     * Jingle Session instance
52
+     * @type {JingleSessionPC}
53
+     */
54
+    this.jingleSession = null;
50 55
     this.lastDominantSpeaker = null;
51 56
     this.dtmfManager = null;
52 57
     this.somebodySupportsDTMF = false;
@@ -181,6 +186,11 @@ JitsiConference.prototype.leave = function () {
181 186
             // ChatRoom instance.
182 187
             this.getParticipants().forEach(
183 188
                 participant => this.onMemberLeft(participant.getJid()));
189
+            // Close the JingleSession
190
+            if (this.jingleSession) {
191
+                this.jingleSession.close();
192
+                this.jingleSession = null;
193
+            }
184 194
         });
185 195
     }
186 196
 
@@ -517,7 +527,7 @@ JitsiConference.prototype.replaceTrack = function (oldTrack, newTrack) {
517 527
             newTrack.ssrcHandler);
518 528
     }
519 529
     // Now replace the stream at the lower levels
520
-    return this.room.replaceStream (oldTrack, newTrack)
530
+    return this._doReplaceTrack(oldTrack, newTrack)
521 531
         .then(() => {
522 532
             if (oldTrack) {
523 533
                 this.onTrackRemoved(oldTrack);
@@ -532,6 +542,25 @@ JitsiConference.prototype.replaceTrack = function (oldTrack, newTrack) {
532 542
         });
533 543
 };
534 544
 
545
+/**
546
+ * Replaces the tracks at the lower level by going through the Jingle session
547
+ * and WebRTC peer connection. The method will resolve immediately if there is
548
+ * currently no JingleSession started.
549
+ * @param {JitsiLocalTrack|null} oldTrack the track to be removed during
550
+ * the process or <tt>null</t> if the method should act as "add track"
551
+ * @param {JitsiLocalTrackn|null} newTrack the new track to be added or
552
+ * <tt>null</tt> if the method should act as "remove track"
553
+ * @return {Promise}
554
+ * @private
555
+ */
556
+JitsiConference.prototype._doReplaceTrack = function (oldTrack, newTrack) {
557
+    if (this.jingleSession) {
558
+        return this.jingleSession.replaceStream(oldTrack, newTrack);
559
+    } else {
560
+        return Promise.resolve();
561
+    }
562
+};
563
+
535 564
 /**
536 565
  * Operations related to creating a new track
537 566
  * @param {JitsiLocalTrack} newTrack the new track being created
@@ -590,6 +619,62 @@ JitsiConference.prototype._setupNewTrack = function (newTrack) {
590 619
     this.eventEmitter.emit(JitsiConferenceEvents.TRACK_ADDED, newTrack);
591 620
 };
592 621
 
622
+/**
623
+ * Adds loca WebRTC stream to the conference.
624
+ * @param {MediaStream} stream new stream that will be added.
625
+ * @param {function} callback callback executed after successful stream addition.
626
+ * @param {function(error)} errorCallback callback executed if stream addition fail.
627
+ * @param {object} ssrcInfo object with information about the SSRCs associated with the
628
+ * stream.
629
+ * @param {boolean} [dontModifySources] if true _modifySources won't be called.
630
+ * Used for streams added before the call start.
631
+ */
632
+JitsiConference.prototype.addLocalWebRTCStream
633
+    = function (stream, callback, errorCallback, ssrcInfo, dontModifySources) {
634
+    if(this.jingleSession) {
635
+        this.jingleSession.addStream(
636
+            stream, callback, errorCallback, ssrcInfo, dontModifySources);
637
+    } else {
638
+        // We are done immediately
639
+        logger.warn("Add local MediaStream - no JingleSession started yet");
640
+        callback();
641
+    }
642
+};
643
+
644
+/**
645
+ * Remove local WebRTC media stream.
646
+ * @param {MediaStream} stream the stream that will be removed.
647
+ * @param {function} callback callback executed after successful stream removal.
648
+ * @param {function} errorCallback callback executed if stream removal fail.
649
+ * @param {object} ssrcInfo object with information about the SSRCs associated
650
+ * with the stream.
651
+ */
652
+JitsiConference.prototype.removeLocalWebRTCStream
653
+    = function (stream, callback, errorCallback, ssrcInfo) {
654
+    if(this.jingleSession) {
655
+        this.jingleSession.removeStream(
656
+            stream, callback, errorCallback, ssrcInfo);
657
+    } else {
658
+        // We are done immediately
659
+        logger.warn("Remove local MediaStream - no JingleSession started yet");
660
+        callback();
661
+    }
662
+};
663
+
664
+/**
665
+ * Generate ssrc info object for a stream with the following properties:
666
+ * - ssrcs - Array of the ssrcs associated with the stream.
667
+ * - groups - Array of the groups associated with the stream.
668
+ */
669
+JitsiConference.prototype._generateNewStreamSSRCInfo = function () {
670
+    if(!this.jingleSession) {
671
+        logger.warn("The call haven't been started. " +
672
+            "Cannot generate ssrc info at the moment!");
673
+        return null;
674
+    }
675
+    return this.jingleSession.generateNewStreamSSRCInfo();
676
+};
677
+
593 678
 /**
594 679
  * Get role of the local user.
595 680
  * @returns {string} user role: 'moderator' or 'none'
@@ -875,7 +960,7 @@ function (jingleSession, jingleOffer, now) {
875 960
     }
876 961
 
877 962
     // Accept incoming call
878
-    this.room.setJingleSession(jingleSession);
963
+    this.jingleSession = jingleSession;
879 964
     this.room.connectionTimes["session.initiate"] = now;
880 965
     // Log "session.restart"
881 966
     if (this.wasStopped) {
@@ -927,8 +1012,7 @@ function (jingleSession, jingleOffer, now) {
927 1012
              * In order to solve issues like the above one here we have to
928 1013
              * generate the ssrc information for the track .
929 1014
              */
930
-            localTrack._setSSRC(
931
-                this.room.generateNewStreamSSRCInfo());
1015
+            localTrack._setSSRC(this._generateNewStreamSSRCInfo());
932 1016
             ssrcInfo = {
933 1017
                 mtype: localTrack.getType(),
934 1018
                 type: "addMuted",
@@ -937,9 +1021,9 @@ function (jingleSession, jingleOffer, now) {
937 1021
             };
938 1022
         }
939 1023
         try {
940
-            this.room.addStream(
1024
+            this.addLocalWebRTCStream(
941 1025
                 localTrack.getOriginalStream(), function () {}, function () {},
942
-                ssrcInfo, true);
1026
+                ssrcInfo, true /* don't modify SSRCs */);
943 1027
         } catch(e) {
944 1028
             GlobalOnErrorHandler.callErrorHandler(e);
945 1029
             logger.error(e);
@@ -986,7 +1070,7 @@ JitsiConference.prototype.onCallEnded
986 1070
         this.statistics.stopCallStats();
987 1071
     }
988 1072
     // Current JingleSession is invalid so set it to null on the room
989
-    this.room.setJingleSession(null);
1073
+    this.jingleSession = null;
990 1074
     // Let the RTC service do any cleanups
991 1075
     this.rtc.onCallEnded();
992 1076
     // PeerConnection has been closed which means that SSRCs stored in
@@ -1160,8 +1244,8 @@ JitsiConference.prototype.getPhonePin = function () {
1160 1244
  * for its session.
1161 1245
  */
1162 1246
 JitsiConference.prototype.getConnectionState = function () {
1163
-    if(this.room)
1164
-        return this.room.getConnectionState();
1247
+    if(this.jingleSession)
1248
+        return this.jingleSession.getIceConnectionState();
1165 1249
     return null;
1166 1250
 };
1167 1251
 

+ 4
- 4
modules/RTC/JitsiLocalTrack.js View File

@@ -363,14 +363,14 @@ JitsiLocalTrack.prototype._setMute = function (mute) {
363 363
  * @returns {Promise}
364 364
  */
365 365
 JitsiLocalTrack.prototype._addStreamToConferenceAsUnmute = function () {
366
-    if (!this.conference || !this.conference.room) {
366
+    if (!this.conference) {
367 367
         return Promise.resolve();
368 368
     }
369 369
 
370 370
     var self = this;
371 371
 
372 372
     return new Promise(function(resolve, reject) {
373
-        self.conference.room.addStream(
373
+        self.conference.addLocalWebRTCStream(
374 374
             self.stream,
375 375
             resolve,
376 376
             (error) => reject(new Error(error)),
@@ -391,12 +391,12 @@ JitsiLocalTrack.prototype._addStreamToConferenceAsUnmute = function () {
391 391
  */
392 392
 JitsiLocalTrack.prototype._removeStreamFromConferenceAsMute =
393 393
 function (successCallback, errorCallback) {
394
-    if (!this.conference || !this.conference.room) {
394
+    if (!this.conference) {
395 395
         successCallback();
396 396
         return;
397 397
     }
398 398
 
399
-    this.conference.room.removeStream(
399
+    this.conference.removeLocalWebRTCStream(
400 400
         this.stream,
401 401
         successCallback,
402 402
         (error) => errorCallback(new Error(error)),

+ 0
- 92
modules/xmpp/ChatRoom.js View File

@@ -81,7 +81,6 @@ export default class ChatRoom extends Listenable {
81 81
         this.moderator = new Moderator(this.roomjid, this.xmpp, this.eventEmitter,
82 82
             {connection: this.xmpp.options, conference: this.options});
83 83
         this.initPresenceMap();
84
-        this.session = null;
85 84
         this.lastPresences = {};
86 85
         this.phoneNumber = null;
87 86
         this.phonePin = null;
@@ -705,78 +704,6 @@ export default class ChatRoom extends Listenable {
705 704
         return null;
706 705
     }
707 706
 
708
-    setJingleSession (session){
709
-        this.session = session;
710
-    }
711
-
712
-    /**
713
-     * Replaces oldStream with newStream and performs a single offer/answer
714
-     *  cycle after both operations are done.  Either oldStream or newStream
715
-     *  can be null; replacing a valid 'oldStream' with a null 'newStream'
716
-     *  effectively just removes 'oldStream'
717
-     * @param oldStream the current stream in use to be replaced
718
-     * @param newStream the new stream to use
719
-     * @returns {Promise}
720
-     */
721
-    replaceStream (oldStream, newStream) {
722
-        if (this.session) {
723
-            return this.session.replaceStream(oldStream, newStream);
724
-        }
725
-        return Promise.resolve();
726
-    }
727
-
728
-    /**
729
-     * Remove stream.
730
-     * @param stream stream that will be removed.
731
-     * @param callback callback executed after successful stream removal.
732
-     * @param errorCallback callback executed if stream removal fail.
733
-     * @param ssrcInfo object with information about the SSRCs associated with the
734
-     * stream.
735
-     */
736
-    removeStream (stream, callback, errorCallback, ssrcInfo) {
737
-        if(!this.session) {
738
-            callback();
739
-            return;
740
-        }
741
-        this.session.removeStream(stream, callback, errorCallback, ssrcInfo);
742
-    }
743
-
744
-    /**
745
-     * Adds stream.
746
-     * @param stream new stream that will be added.
747
-     * @param callback callback executed after successful stream addition.
748
-     * @param errorCallback callback executed if stream addition fail.
749
-     * @param ssrcInfo object with information about the SSRCs associated with the
750
-     * stream.
751
-     * @param dontModifySources {boolean} if true _modifySources won't be called.
752
-     * Used for streams added before the call start.
753
-     */
754
-    addStream (stream, callback, errorCallback, ssrcInfo, dontModifySources) {
755
-        if(this.session) {
756
-            // FIXME: will block switchInProgress on true value in case of exception
757
-            this.session.addStream(stream, callback, errorCallback, ssrcInfo,
758
-                dontModifySources);
759
-        } else {
760
-            // We are done immediately
761
-            logger.warn("No conference handler or conference not started yet");
762
-            callback();
763
-        }
764
-    }
765
-
766
-    /**
767
-     * Generate ssrc info object for a stream with the following properties:
768
-     * - ssrcs - Array of the ssrcs associated with the stream.
769
-     * - groups - Array of the groups associated with the stream.
770
-     */
771
-    generateNewStreamSSRCInfo () {
772
-        if(!this.session) {
773
-            logger.warn("The call haven't been started. " +
774
-                "Cannot generate ssrc info at the moment!");
775
-            return null;
776
-        }
777
-        return this.session.generateNewStreamSSRCInfo();
778
-    }
779
-
780 707
     setVideoMute (mute, callback) {
781 708
         this.sendVideoInfoPresence(mute);
782 709
         if(callback)
@@ -926,15 +853,6 @@ export default class ChatRoom extends Listenable {
926 853
         return this.phonePin;
927 854
     }
928 855
 
929
-    /**
930
-     * Returns the connection state for the current session.
931
-     */
932
-    getConnectionState () {
933
-        if(!this.session)
934
-            return null;
935
-        return this.session.getIceConnectionState();
936
-    }
937
-
938 856
     /**
939 857
      * Mutes remote participant.
940 858
      * @param jid of the participant
@@ -982,7 +900,6 @@ export default class ChatRoom extends Listenable {
982 900
      * rejected.
983 901
      */
984 902
     leave () {
985
-        this._dispose();
986 903
         return new Promise((resolve, reject) => {
987 904
             let timeout = setTimeout(() => onMucLeft(true), 5000);
988 905
             let eventEmitter = this.eventEmitter;
@@ -1001,13 +918,4 @@ export default class ChatRoom extends Listenable {
1001 918
             this.doLeave();
1002 919
         });
1003 920
     }
1004
-
1005
-    /**
1006
-     * Disposes the conference, closes the jingle session.
1007
-     */
1008
-    _dispose () {
1009
-        if (this.session) {
1010
-            this.session.close();
1011
-        }
1012
-    }
1013 921
 }

+ 0
- 8
modules/xmpp/strophe.emuc.js View File

@@ -106,14 +106,6 @@ class MucConnectionPlugin extends ConnectionPluginListenable {
106 106
         return true;
107 107
     }
108 108
 
109
-    setJingleSession (from, session) {
110
-        const room = this.rooms[Strophe.getBareJidFromJid(from)];
111
-        if(!room)
112
-            return;
113
-
114
-        room.setJingleSession(session);
115
-    }
116
-
117 109
     onMute(iq) {
118 110
         const from = iq.getAttribute('from');
119 111
         const room = this.rooms[Strophe.getBareJidFromJid(from)];

Loading…
Cancel
Save