Browse Source

Merge remote-tracking branch 'upstream/master' into ds-error-handle

master
damencho 9 years ago
parent
commit
f412f40438

+ 27
- 16
JitsiConference.js View File

@@ -12,6 +12,7 @@ var JitsiParticipant = require("./JitsiParticipant");
12 12
 var Statistics = require("./modules/statistics/statistics");
13 13
 var JitsiDTMFManager = require('./modules/DTMF/JitsiDTMFManager');
14 14
 var JitsiTrackEvents = require("./JitsiTrackEvents");
15
+var JitsiTrackErrors = require("./JitsiTrackErrors");
15 16
 var Settings = require("./modules/settings/Settings");
16 17
 
17 18
 /**
@@ -298,6 +299,10 @@ JitsiConference.prototype.setSubject = function (subject) {
298 299
  * and there is already another video track in the conference.
299 300
  */
300 301
 JitsiConference.prototype.addTrack = function (track) {
302
+    if(track.disposed)
303
+    {
304
+        throw new Error(JitsiTrackErrors.TRACK_IS_DISPOSED);
305
+    }
301 306
     if (track.isVideoTrack()) {
302 307
         if (this.rtc.getLocalVideoStream()) {
303 308
             throw new Error("cannot add second video track to the conference");
@@ -336,12 +341,9 @@ JitsiConference.prototype.addTrack = function (track) {
336 341
             }
337 342
 
338 343
             track.muteHandler = this._fireMuteChangeEvent.bind(this, track);
339
-            track.stopHandler = this.removeTrack.bind(this, track);
340 344
             track.audioLevelHandler = this._fireAudioLevelChangeEvent.bind(this);
341 345
             track.addEventListener(JitsiTrackEvents.TRACK_MUTE_CHANGED,
342 346
                                    track.muteHandler);
343
-            track.addEventListener(JitsiTrackEvents.TRACK_STOPPED,
344
-                                   track.stopHandler);
345 347
             track.addEventListener(JitsiTrackEvents.TRACK_AUDIO_LEVEL_CHANGED,
346 348
                                    track.audioLevelHandler);
347 349
             //FIXME: This dependacy is not necessary. This is quick fix.
@@ -382,6 +384,10 @@ JitsiConference.prototype._fireMuteChangeEvent = function (track) {
382 384
  * @returns {Promise}
383 385
  */
384 386
 JitsiConference.prototype.removeTrack = function (track) {
387
+    if(track.disposed)
388
+    {
389
+        throw new Error(JitsiTrackErrors.TRACK_IS_DISPOSED);
390
+    }
385 391
     if(!this.room){
386 392
         if(this.rtc) {
387 393
             this.rtc.removeLocalStream(track);
@@ -397,8 +403,6 @@ JitsiConference.prototype.removeTrack = function (track) {
397 403
             this.rtc.removeLocalStream(track);
398 404
             track.removeEventListener(JitsiTrackEvents.TRACK_MUTE_CHANGED,
399 405
                 track.muteHandler);
400
-            track.removeEventListener(JitsiTrackEvents.TRACK_STOPPED,
401
-                track.stopHandler);
402 406
             track.removeEventListener(JitsiTrackEvents.TRACK_AUDIO_LEVEL_CHANGED,
403 407
                 track.audioLevelHandler);
404 408
             this.room.removeListener(XMPPEvents.SENDRECV_STREAMS_CHANGED,
@@ -582,17 +586,6 @@ JitsiConference.prototype.onTrackAdded = function (track) {
582 586
     participant._tracks.push(track);
583 587
 
584 588
     var emitter = this.eventEmitter;
585
-    track.addEventListener(
586
-        JitsiTrackEvents.TRACK_STOPPED,
587
-        function () {
588
-            // remove track from JitsiParticipant
589
-            var pos = participant._tracks.indexOf(track);
590
-            if (pos > -1) {
591
-                participant._tracks.splice(pos, 1);
592
-            }
593
-            emitter.emit(JitsiConferenceEvents.TRACK_REMOVED, track);
594
-        }
595
-    );
596 589
     track.addEventListener(
597 590
         JitsiTrackEvents.TRACK_MUTE_CHANGED,
598 591
         function () {
@@ -870,6 +863,24 @@ function setupListeners(conference) {
870 863
             }
871 864
         }
872 865
     );
866
+    conference.room.addListener(XMPPEvents.REMOTE_STREAM_REMOVED,
867
+        function (streamId) {
868
+            var participants = conference.getParticipants();
869
+            for(var j = 0; j < participants.length; j++) {
870
+                var participant = participants[j];
871
+                var tracks = participant.getTracks();
872
+                for(var i = 0; i < tracks.length; i++) {
873
+                    if(tracks[i] && tracks[i].stream &&
874
+                        RTC.getStreamID(tracks[i].stream) == streamId){
875
+                        var track = participant._tracks.splice(i, 1)[0];
876
+                        conference.eventEmitter.emit(
877
+                            JitsiConferenceEvents.TRACK_REMOVED, track);
878
+                        return;
879
+                    }
880
+                }
881
+            }
882
+        }
883
+    );
873 884
     conference.rtc.addListener(RTCEvents.FAKE_VIDEO_TRACK_CREATED,
874 885
         function (track) {
875 886
             conference.onTrackAdded(track);

+ 1
- 1
JitsiMeetJS.js View File

@@ -92,7 +92,7 @@ var LibJitsiMeet = {
92 92
                             Statistics.startLocalStats(mStream,
93 93
                                 track.setAudioLevel.bind(track));
94 94
                             track.addEventListener(
95
-                                JitsiTrackEvents.TRACK_STOPPED,
95
+                                JitsiTrackEvents.LOCAL_TRACK_STOPPED,
96 96
                                 function(){
97 97
                                     Statistics.stopLocalStats(mStream);
98 98
                                 });

+ 2
- 1
JitsiTrackErrors.js View File

@@ -31,5 +31,6 @@ module.exports = {
31 31
         "gum.chrome_extension_installation_error",
32 32
     CHROME_EXTENSION_USER_CANCELED:
33 33
         "gum.chrome_extension_user_canceled",
34
-    GENERAL: "gum.general"
34
+    GENERAL: "gum.general",
35
+    TRACK_IS_DISPOSED: "track.track_is_disposed"
35 36
 };

+ 1
- 1
JitsiTrackEvents.js View File

@@ -10,7 +10,7 @@ var JitsiTrackEvents = {
10 10
     /**
11 11
      * The media track was removed to the conference.
12 12
      */
13
-    TRACK_STOPPED: "track.stopped",
13
+    LOCAL_TRACK_STOPPED: "track.stopped",
14 14
     /**
15 15
      * The video type("camera" or "desktop") of the track was changed.
16 16
      */

+ 5
- 1
doc/API.md View File

@@ -107,6 +107,10 @@ JitsiMeetJS.setLogLevel(JitsiMeetJS.logLevels.ERROR);
107 107
         - CONNECTION_DISCONNECTED - indicates that we are disconnected.
108 108
         - WRONG_STATE - indicates that the user has performed action that can't be executed because the connection is in wrong state.
109 109
 
110
+    3. tracks
111
+        - LOCAL_TRACK_STOPPED - indicates that a local track was stopped. This
112
+        event can be fired when ```dispose()``` method is called or for other reasons.
113
+
110 114
 * ```JitsiMeetJS.errors``` - JS object that contains all errors used by the API. You can use that object to check the reported errors from the API
111 115
     We have two error types - connection and conference. You can access the events with the following code ```JitsiMeetJS.errors.<error_type>.<error_name>```.
112 116
     For example if you want to use the conference event that is fired when somebody leave conference you can use the following code - ```JitsiMeetJS.errors.conference.PASSWORD_REQUIRED```.
@@ -320,7 +324,7 @@ We have the following methods for controling the tracks:
320 324
 
321 325
 6. detach(container) - removes the track from the container.
322 326
 
323
-7. stop() - stop sending the track to the other participants in the conference. Returns Promise.
327
+7. dispose() - disposes the track. If the track is added to a conference the track will be removed. Returns Promise.
324 328
 
325 329
    Note: This method is implemented only for the local tracks.
326 330
 

+ 4
- 4
doc/example/example.js View File

@@ -32,7 +32,7 @@ function onLocalTracks(tracks)
32 32
             function () {
33 33
                 console.log("local track muted");
34 34
             });
35
-        localTracks[i].addEventListener(JitsiMeetJS.events.track.TRACK_STOPPED,
35
+        localTracks[i].addEventListener(JitsiMeetJS.events.track.LOCAL_TRACK_STOPPED,
36 36
             function () {
37 37
                 console.log("local track stoped");
38 38
             });
@@ -67,7 +67,7 @@ function onRemoteTrack(track) {
67 67
         function () {
68 68
             console.log("remote track muted");
69 69
         });
70
-    track.addEventListener(JitsiMeetJS.events.track.TRACK_STOPPED,
70
+    track.addEventListener(JitsiMeetJS.events.track.LOCAL_TRACK_STOPPED,
71 71
         function () {
72 72
             console.log("remote track stoped");
73 73
         });
@@ -159,7 +159,7 @@ var isVideo = true;
159 159
 function switchVideo() {
160 160
     isVideo = !isVideo;
161 161
     if(localTracks[1]) {
162
-        localTracks[1].stop();
162
+        localTracks[1].dispose();
163 163
         localTracks.pop();
164 164
     }
165 165
     JitsiMeetJS.createLocalTracks({devices: isVideo? ["video"] : ["desktop"]}).
@@ -169,7 +169,7 @@ function switchVideo() {
169 169
                 function () {
170 170
                     console.log("local track muted");
171 171
                 });
172
-            localTracks[1].addEventListener(JitsiMeetJS.events.track.TRACK_STOPPED,
172
+            localTracks[1].addEventListener(JitsiMeetJS.events.track.LOCAL_TRACK_STOPPED,
173 173
                 function () {
174 174
                     console.log("local track stoped");
175 175
                 });

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

@@ -17,13 +17,14 @@ function JitsiLocalTrack(stream, videoType,
17 17
     this.deviceId = deviceId;
18 18
     this.startMuted = false;
19 19
     this.ssrc = null;
20
+    this.disposed = false;
20 21
     //FIXME: This dependacy is not necessary.
21 22
     this.conference = null;
22 23
     JitsiTrack.call(this, null, stream,
23 24
         function () {
24 25
             if(!this.dontFireRemoveEvent)
25 26
                 this.eventEmitter.emit(
26
-                    JitsiTrackEvents.TRACK_STOPPED);
27
+                    JitsiTrackEvents.LOCAL_TRACK_STOPPED);
27 28
             this.dontFireRemoveEvent = false;
28 29
         }.bind(this));
29 30
     this.initialMSID = this.getMSID();
@@ -130,7 +131,7 @@ JitsiLocalTrack.prototype._setMute = function (mute) {
130 131
  * NOTE: Works for local tracks only.
131 132
  * @returns {Promise}
132 133
  */
133
-JitsiLocalTrack.prototype.stop = function () {
134
+JitsiLocalTrack.prototype.dispose = function () {
134 135
     var promise = Promise.resolve();
135 136
 
136 137
     if (this.conference){
@@ -141,6 +142,7 @@ JitsiLocalTrack.prototype.stop = function () {
141 142
         RTCUtils.stopMediaStream(this.stream);
142 143
         this.detach();
143 144
     }
145
+    this.disposed = true;
144 146
 
145 147
     return promise;
146 148
 };

+ 2
- 4
modules/RTC/JitsiRemoteTrack.js View File

@@ -12,9 +12,7 @@ var JitsiTrackEvents = require("../../JitsiTrackEvents");
12 12
  */
13 13
 function JitsiRemoteTrack(RTC, data, sid, ssrc) {
14 14
     JitsiTrack.call(this, RTC, data.stream,
15
-        function () {
16
-            this.eventEmitter.emit(JitsiTrackEvents.TRACK_STOPPED);
17
-        }.bind(this), data.jitsiTrackType);
15
+        function () {}, data.jitsiTrackType);
18 16
     this.rtc = RTC;
19 17
     this.sid = sid;
20 18
     this.stream = data.stream;
@@ -89,6 +87,6 @@ JitsiRemoteTrack.prototype._setVideoType = function (type) {
89 87
     this.eventEmitter.emit(JitsiTrackEvents.TRACK_VIDEOTYPE_CHANGED, type);
90 88
 }
91 89
 
92
-delete JitsiRemoteTrack.prototype.stop;
90
+delete JitsiRemoteTrack.prototype.dispose;
93 91
 
94 92
 module.exports = JitsiRemoteTrack;

+ 2
- 2
modules/RTC/JitsiTrack.js View File

@@ -220,10 +220,10 @@ JitsiTrack.prototype.detach = function (container) {
220 220
 }
221 221
 
222 222
 /**
223
- * Stops sending the media track. And removes it from the HTML.
223
+ * Dispose sending the media track. And removes it from the HTML.
224 224
  * NOTE: Works for local tracks only.
225 225
  */
226
-JitsiTrack.prototype.stop = function () {
226
+JitsiTrack.prototype.dispose = function () {
227 227
 }
228 228
 
229 229
 /**

+ 24
- 3
modules/xmpp/JingleSessionPC.js View File

@@ -128,9 +128,16 @@ JingleSessionPC.prototype.doInitialize = function () {
128 128
     };
129 129
     this.peerconnection.onremovestream = function (event) {
130 130
         // Remove the stream from remoteStreams
131
-        // FIXME: remotestreamremoved.jingle not defined anywhere(unused)
132
-
133
-        $(document).trigger('remotestreamremoved.jingle', [event, self.sid]);
131
+        if (event.stream.id !== 'default') {
132
+            logger.log("REMOTE STREAM REMOVED: ", event.stream , event.stream.id);
133
+            self.remoteStreamRemoved(event);
134
+        } else {
135
+            // This is a recvonly stream. Clients that implement Unified Plan,
136
+            // such as Firefox use recvonly "streams/channels/tracks" for
137
+            // receiving remote stream/tracks, as opposed to Plan B where there
138
+            // are only 3 channels: audio, video and data.
139
+            logger.log("RECVONLY REMOTE STREAM IGNORED: " + event.stream + " - " + event.stream.id);
140
+        }
134 141
     };
135 142
     this.peerconnection.onsignalingstatechange = function (event) {
136 143
         if (!(self && self.peerconnection)) return;
@@ -1381,6 +1388,20 @@ JingleSessionPC.prototype.remoteStreamAdded = function (data, times) {
1381 1388
     }
1382 1389
 }
1383 1390
 
1391
+/**
1392
+ * Handles remote stream removal.
1393
+ * @param event The event object associated with the removal.
1394
+ */
1395
+JingleSessionPC.prototype.remoteStreamRemoved = function (event) {
1396
+    var thessrc;
1397
+    var streamId = RTC.getStreamID(event.stream);
1398
+    if (!streamId) {
1399
+        logger.error("No stream ID for", event.stream);
1400
+    } else if (streamId && streamId.indexOf('mixedmslabel') === -1) {
1401
+        this.room.eventEmitter.emit(XMPPEvents.REMOTE_STREAM_REMOVED, streamId);
1402
+    }
1403
+}
1404
+
1384 1405
 /**
1385 1406
  * Returns the ice connection state for the peer connection.
1386 1407
  * @returns the ice connection state for the peer connection.

+ 4
- 0
service/xmpp/XMPPEvents.js View File

@@ -85,6 +85,10 @@ var XMPPEvents = {
85 85
     READY_TO_JOIN: 'xmpp.ready_to_join',
86 86
     FOCUS_LEFT: "xmpp.focus_left",
87 87
     REMOTE_STREAM_RECEIVED: "xmpp.remote_stream_received",
88
+    /**
89
+     * Indicates that remote stream has been removed from the conference.
90
+     */
91
+    REMOTE_STREAM_REMOVED: "xmpp.remote_stream_removed",
88 92
     /**
89 93
      * Indicates that recording state changed.
90 94
      */

Loading…
Cancel
Save