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
 var Statistics = require("./modules/statistics/statistics");
12
 var Statistics = require("./modules/statistics/statistics");
13
 var JitsiDTMFManager = require('./modules/DTMF/JitsiDTMFManager');
13
 var JitsiDTMFManager = require('./modules/DTMF/JitsiDTMFManager');
14
 var JitsiTrackEvents = require("./JitsiTrackEvents");
14
 var JitsiTrackEvents = require("./JitsiTrackEvents");
15
+var JitsiTrackErrors = require("./JitsiTrackErrors");
15
 var Settings = require("./modules/settings/Settings");
16
 var Settings = require("./modules/settings/Settings");
16
 
17
 
17
 /**
18
 /**
298
  * and there is already another video track in the conference.
299
  * and there is already another video track in the conference.
299
  */
300
  */
300
 JitsiConference.prototype.addTrack = function (track) {
301
 JitsiConference.prototype.addTrack = function (track) {
302
+    if(track.disposed)
303
+    {
304
+        throw new Error(JitsiTrackErrors.TRACK_IS_DISPOSED);
305
+    }
301
     if (track.isVideoTrack()) {
306
     if (track.isVideoTrack()) {
302
         if (this.rtc.getLocalVideoStream()) {
307
         if (this.rtc.getLocalVideoStream()) {
303
             throw new Error("cannot add second video track to the conference");
308
             throw new Error("cannot add second video track to the conference");
336
             }
341
             }
337
 
342
 
338
             track.muteHandler = this._fireMuteChangeEvent.bind(this, track);
343
             track.muteHandler = this._fireMuteChangeEvent.bind(this, track);
339
-            track.stopHandler = this.removeTrack.bind(this, track);
340
             track.audioLevelHandler = this._fireAudioLevelChangeEvent.bind(this);
344
             track.audioLevelHandler = this._fireAudioLevelChangeEvent.bind(this);
341
             track.addEventListener(JitsiTrackEvents.TRACK_MUTE_CHANGED,
345
             track.addEventListener(JitsiTrackEvents.TRACK_MUTE_CHANGED,
342
                                    track.muteHandler);
346
                                    track.muteHandler);
343
-            track.addEventListener(JitsiTrackEvents.TRACK_STOPPED,
344
-                                   track.stopHandler);
345
             track.addEventListener(JitsiTrackEvents.TRACK_AUDIO_LEVEL_CHANGED,
347
             track.addEventListener(JitsiTrackEvents.TRACK_AUDIO_LEVEL_CHANGED,
346
                                    track.audioLevelHandler);
348
                                    track.audioLevelHandler);
347
             //FIXME: This dependacy is not necessary. This is quick fix.
349
             //FIXME: This dependacy is not necessary. This is quick fix.
382
  * @returns {Promise}
384
  * @returns {Promise}
383
  */
385
  */
384
 JitsiConference.prototype.removeTrack = function (track) {
386
 JitsiConference.prototype.removeTrack = function (track) {
387
+    if(track.disposed)
388
+    {
389
+        throw new Error(JitsiTrackErrors.TRACK_IS_DISPOSED);
390
+    }
385
     if(!this.room){
391
     if(!this.room){
386
         if(this.rtc) {
392
         if(this.rtc) {
387
             this.rtc.removeLocalStream(track);
393
             this.rtc.removeLocalStream(track);
397
             this.rtc.removeLocalStream(track);
403
             this.rtc.removeLocalStream(track);
398
             track.removeEventListener(JitsiTrackEvents.TRACK_MUTE_CHANGED,
404
             track.removeEventListener(JitsiTrackEvents.TRACK_MUTE_CHANGED,
399
                 track.muteHandler);
405
                 track.muteHandler);
400
-            track.removeEventListener(JitsiTrackEvents.TRACK_STOPPED,
401
-                track.stopHandler);
402
             track.removeEventListener(JitsiTrackEvents.TRACK_AUDIO_LEVEL_CHANGED,
406
             track.removeEventListener(JitsiTrackEvents.TRACK_AUDIO_LEVEL_CHANGED,
403
                 track.audioLevelHandler);
407
                 track.audioLevelHandler);
404
             this.room.removeListener(XMPPEvents.SENDRECV_STREAMS_CHANGED,
408
             this.room.removeListener(XMPPEvents.SENDRECV_STREAMS_CHANGED,
582
     participant._tracks.push(track);
586
     participant._tracks.push(track);
583
 
587
 
584
     var emitter = this.eventEmitter;
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
     track.addEventListener(
589
     track.addEventListener(
597
         JitsiTrackEvents.TRACK_MUTE_CHANGED,
590
         JitsiTrackEvents.TRACK_MUTE_CHANGED,
598
         function () {
591
         function () {
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
     conference.rtc.addListener(RTCEvents.FAKE_VIDEO_TRACK_CREATED,
884
     conference.rtc.addListener(RTCEvents.FAKE_VIDEO_TRACK_CREATED,
874
         function (track) {
885
         function (track) {
875
             conference.onTrackAdded(track);
886
             conference.onTrackAdded(track);

+ 1
- 1
JitsiMeetJS.js View File

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

+ 2
- 1
JitsiTrackErrors.js View File

31
         "gum.chrome_extension_installation_error",
31
         "gum.chrome_extension_installation_error",
32
     CHROME_EXTENSION_USER_CANCELED:
32
     CHROME_EXTENSION_USER_CANCELED:
33
         "gum.chrome_extension_user_canceled",
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
     /**
10
     /**
11
      * The media track was removed to the conference.
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
      * The video type("camera" or "desktop") of the track was changed.
15
      * The video type("camera" or "desktop") of the track was changed.
16
      */
16
      */

+ 5
- 1
doc/API.md View File

107
         - CONNECTION_DISCONNECTED - indicates that we are disconnected.
107
         - CONNECTION_DISCONNECTED - indicates that we are disconnected.
108
         - WRONG_STATE - indicates that the user has performed action that can't be executed because the connection is in wrong state.
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
 * ```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
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
     We have two error types - connection and conference. You can access the events with the following code ```JitsiMeetJS.errors.<error_type>.<error_name>```.
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
     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```.
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
 
324
 
321
 6. detach(container) - removes the track from the container.
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
    Note: This method is implemented only for the local tracks.
329
    Note: This method is implemented only for the local tracks.
326
 
330
 

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

32
             function () {
32
             function () {
33
                 console.log("local track muted");
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
             function () {
36
             function () {
37
                 console.log("local track stoped");
37
                 console.log("local track stoped");
38
             });
38
             });
67
         function () {
67
         function () {
68
             console.log("remote track muted");
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
         function () {
71
         function () {
72
             console.log("remote track stoped");
72
             console.log("remote track stoped");
73
         });
73
         });
159
 function switchVideo() {
159
 function switchVideo() {
160
     isVideo = !isVideo;
160
     isVideo = !isVideo;
161
     if(localTracks[1]) {
161
     if(localTracks[1]) {
162
-        localTracks[1].stop();
162
+        localTracks[1].dispose();
163
         localTracks.pop();
163
         localTracks.pop();
164
     }
164
     }
165
     JitsiMeetJS.createLocalTracks({devices: isVideo? ["video"] : ["desktop"]}).
165
     JitsiMeetJS.createLocalTracks({devices: isVideo? ["video"] : ["desktop"]}).
169
                 function () {
169
                 function () {
170
                     console.log("local track muted");
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
                 function () {
173
                 function () {
174
                     console.log("local track stoped");
174
                     console.log("local track stoped");
175
                 });
175
                 });

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

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

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

12
  */
12
  */
13
 function JitsiRemoteTrack(RTC, data, sid, ssrc) {
13
 function JitsiRemoteTrack(RTC, data, sid, ssrc) {
14
     JitsiTrack.call(this, RTC, data.stream,
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
     this.rtc = RTC;
16
     this.rtc = RTC;
19
     this.sid = sid;
17
     this.sid = sid;
20
     this.stream = data.stream;
18
     this.stream = data.stream;
89
     this.eventEmitter.emit(JitsiTrackEvents.TRACK_VIDEOTYPE_CHANGED, type);
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
 module.exports = JitsiRemoteTrack;
92
 module.exports = JitsiRemoteTrack;

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

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
  * NOTE: Works for local tracks only.
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
     };
128
     };
129
     this.peerconnection.onremovestream = function (event) {
129
     this.peerconnection.onremovestream = function (event) {
130
         // Remove the stream from remoteStreams
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
     this.peerconnection.onsignalingstatechange = function (event) {
142
     this.peerconnection.onsignalingstatechange = function (event) {
136
         if (!(self && self.peerconnection)) return;
143
         if (!(self && self.peerconnection)) return;
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
  * Returns the ice connection state for the peer connection.
1406
  * Returns the ice connection state for the peer connection.
1386
  * @returns the ice connection state for the peer connection.
1407
  * @returns the ice connection state for the peer connection.

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

85
     READY_TO_JOIN: 'xmpp.ready_to_join',
85
     READY_TO_JOIN: 'xmpp.ready_to_join',
86
     FOCUS_LEFT: "xmpp.focus_left",
86
     FOCUS_LEFT: "xmpp.focus_left",
87
     REMOTE_STREAM_RECEIVED: "xmpp.remote_stream_received",
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
      * Indicates that recording state changed.
93
      * Indicates that recording state changed.
90
      */
94
      */

Loading…
Cancel
Save