Browse Source

ref: remove JingleSession from ChatRoom

dev1
paweldomas 9 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
     this._init(options);
47
     this._init(options);
48
     this.componentsVersions = new ComponentsVersions(this);
48
     this.componentsVersions = new ComponentsVersions(this);
49
     this.participants = {};
49
     this.participants = {};
50
+    /**
51
+     * Jingle Session instance
52
+     * @type {JingleSessionPC}
53
+     */
54
+    this.jingleSession = null;
50
     this.lastDominantSpeaker = null;
55
     this.lastDominantSpeaker = null;
51
     this.dtmfManager = null;
56
     this.dtmfManager = null;
52
     this.somebodySupportsDTMF = false;
57
     this.somebodySupportsDTMF = false;
181
             // ChatRoom instance.
186
             // ChatRoom instance.
182
             this.getParticipants().forEach(
187
             this.getParticipants().forEach(
183
                 participant => this.onMemberLeft(participant.getJid()));
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
             newTrack.ssrcHandler);
527
             newTrack.ssrcHandler);
518
     }
528
     }
519
     // Now replace the stream at the lower levels
529
     // Now replace the stream at the lower levels
520
-    return this.room.replaceStream (oldTrack, newTrack)
530
+    return this._doReplaceTrack(oldTrack, newTrack)
521
         .then(() => {
531
         .then(() => {
522
             if (oldTrack) {
532
             if (oldTrack) {
523
                 this.onTrackRemoved(oldTrack);
533
                 this.onTrackRemoved(oldTrack);
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
  * Operations related to creating a new track
565
  * Operations related to creating a new track
537
  * @param {JitsiLocalTrack} newTrack the new track being created
566
  * @param {JitsiLocalTrack} newTrack the new track being created
590
     this.eventEmitter.emit(JitsiConferenceEvents.TRACK_ADDED, newTrack);
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
  * Get role of the local user.
679
  * Get role of the local user.
595
  * @returns {string} user role: 'moderator' or 'none'
680
  * @returns {string} user role: 'moderator' or 'none'
875
     }
960
     }
876
 
961
 
877
     // Accept incoming call
962
     // Accept incoming call
878
-    this.room.setJingleSession(jingleSession);
963
+    this.jingleSession = jingleSession;
879
     this.room.connectionTimes["session.initiate"] = now;
964
     this.room.connectionTimes["session.initiate"] = now;
880
     // Log "session.restart"
965
     // Log "session.restart"
881
     if (this.wasStopped) {
966
     if (this.wasStopped) {
927
              * In order to solve issues like the above one here we have to
1012
              * In order to solve issues like the above one here we have to
928
              * generate the ssrc information for the track .
1013
              * generate the ssrc information for the track .
929
              */
1014
              */
930
-            localTrack._setSSRC(
931
-                this.room.generateNewStreamSSRCInfo());
1015
+            localTrack._setSSRC(this._generateNewStreamSSRCInfo());
932
             ssrcInfo = {
1016
             ssrcInfo = {
933
                 mtype: localTrack.getType(),
1017
                 mtype: localTrack.getType(),
934
                 type: "addMuted",
1018
                 type: "addMuted",
937
             };
1021
             };
938
         }
1022
         }
939
         try {
1023
         try {
940
-            this.room.addStream(
1024
+            this.addLocalWebRTCStream(
941
                 localTrack.getOriginalStream(), function () {}, function () {},
1025
                 localTrack.getOriginalStream(), function () {}, function () {},
942
-                ssrcInfo, true);
1026
+                ssrcInfo, true /* don't modify SSRCs */);
943
         } catch(e) {
1027
         } catch(e) {
944
             GlobalOnErrorHandler.callErrorHandler(e);
1028
             GlobalOnErrorHandler.callErrorHandler(e);
945
             logger.error(e);
1029
             logger.error(e);
986
         this.statistics.stopCallStats();
1070
         this.statistics.stopCallStats();
987
     }
1071
     }
988
     // Current JingleSession is invalid so set it to null on the room
1072
     // Current JingleSession is invalid so set it to null on the room
989
-    this.room.setJingleSession(null);
1073
+    this.jingleSession = null;
990
     // Let the RTC service do any cleanups
1074
     // Let the RTC service do any cleanups
991
     this.rtc.onCallEnded();
1075
     this.rtc.onCallEnded();
992
     // PeerConnection has been closed which means that SSRCs stored in
1076
     // PeerConnection has been closed which means that SSRCs stored in
1160
  * for its session.
1244
  * for its session.
1161
  */
1245
  */
1162
 JitsiConference.prototype.getConnectionState = function () {
1246
 JitsiConference.prototype.getConnectionState = function () {
1163
-    if(this.room)
1164
-        return this.room.getConnectionState();
1247
+    if(this.jingleSession)
1248
+        return this.jingleSession.getIceConnectionState();
1165
     return null;
1249
     return null;
1166
 };
1250
 };
1167
 
1251
 

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

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

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

81
         this.moderator = new Moderator(this.roomjid, this.xmpp, this.eventEmitter,
81
         this.moderator = new Moderator(this.roomjid, this.xmpp, this.eventEmitter,
82
             {connection: this.xmpp.options, conference: this.options});
82
             {connection: this.xmpp.options, conference: this.options});
83
         this.initPresenceMap();
83
         this.initPresenceMap();
84
-        this.session = null;
85
         this.lastPresences = {};
84
         this.lastPresences = {};
86
         this.phoneNumber = null;
85
         this.phoneNumber = null;
87
         this.phonePin = null;
86
         this.phonePin = null;
705
         return null;
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
     setVideoMute (mute, callback) {
707
     setVideoMute (mute, callback) {
781
         this.sendVideoInfoPresence(mute);
708
         this.sendVideoInfoPresence(mute);
782
         if(callback)
709
         if(callback)
926
         return this.phonePin;
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
      * Mutes remote participant.
857
      * Mutes remote participant.
940
      * @param jid of the participant
858
      * @param jid of the participant
982
      * rejected.
900
      * rejected.
983
      */
901
      */
984
     leave () {
902
     leave () {
985
-        this._dispose();
986
         return new Promise((resolve, reject) => {
903
         return new Promise((resolve, reject) => {
987
             let timeout = setTimeout(() => onMucLeft(true), 5000);
904
             let timeout = setTimeout(() => onMucLeft(true), 5000);
988
             let eventEmitter = this.eventEmitter;
905
             let eventEmitter = this.eventEmitter;
1001
             this.doLeave();
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
         return true;
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
     onMute(iq) {
109
     onMute(iq) {
118
         const from = iq.getAttribute('from');
110
         const from = iq.getAttribute('from');
119
         const room = this.rooms[Strophe.getBareJidFromJid(from)];
111
         const room = this.rooms[Strophe.getBareJidFromJid(from)];

Loading…
Cancel
Save