Bläddra i källkod

Renames JitsiTrack.stop method and TRACK_STOPPED event. Fixes minor issues with TRACK_REMOVED event.

master
hristoterezov 9 år sedan
förälder
incheckning
1c9eed44c5

+ 10
- 6
JitsiConference.js Visa fil

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,
868
                 for(var i = 0; i < tracks.length; i++) {
872
                 for(var i = 0; i < tracks.length; i++) {
869
                     if(tracks[i] && tracks[i].stream &&
873
                     if(tracks[i] && tracks[i].stream &&
870
                         RTC.getStreamID(tracks[i].stream) == streamId){
874
                         RTC.getStreamID(tracks[i].stream) == streamId){
871
-                        var track = participant._tracks.splice(i, 1);
875
+                        var track = participant._tracks.splice(i, 1)[0];
872
                         conference.eventEmitter.emit(
876
                         conference.eventEmitter.emit(
873
                             JitsiConferenceEvents.TRACK_REMOVED, track);
877
                             JitsiConferenceEvents.TRACK_REMOVED, track);
874
                         return;
878
                         return;

+ 1
- 1
JitsiMeetJS.js Visa fil

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 Visa fil

23
     },
23
     },
24
     UNSUPPORTED_RESOLUTION: "gum.unsupported_resolution",
24
     UNSUPPORTED_RESOLUTION: "gum.unsupported_resolution",
25
     FIREFOX_EXTENSION_NEEDED: "gum.firefox_extension_needed",
25
     FIREFOX_EXTENSION_NEEDED: "gum.firefox_extension_needed",
26
-    GENERAL: "gum.general"
26
+    GENERAL: "gum.general",
27
+    TRACK_IS_DISPOSED: "track.track_is_disposed"
27
 };
28
 };

+ 1
- 1
JitsiTrackEvents.js Visa fil

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 Visa fil

106
         - CONNECTION_DISCONNECTED - indicates that we are disconnected.
106
         - CONNECTION_DISCONNECTED - indicates that we are disconnected.
107
         - WRONG_STATE - indicates that the user has performed action that can't be executed because the connection is in wrong state.
107
         - WRONG_STATE - indicates that the user has performed action that can't be executed because the connection is in wrong state.
108
 
108
 
109
+    3. tracks
110
+        - LOCAL_TRACK_STOPPED - indicates that a local track was stopped. This
111
+        event can be fired when ```dispose()``` method is called or for other reasons.
112
+
109
 * ```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
113
 * ```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
110
     We have two error types - connection and conference. You can access the events with the following code ```JitsiMeetJS.errors.<error_type>.<error_name>```.
114
     We have two error types - connection and conference. You can access the events with the following code ```JitsiMeetJS.errors.<error_type>.<error_name>```.
111
     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```.
115
     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```.
319
 
323
 
320
 6. detach(container) - removes the track from the container.
324
 6. detach(container) - removes the track from the container.
321
 
325
 
322
-7. stop() - stop sending the track to the other participants in the conference. Returns Promise.
326
+7. dispose() - disposes the track. If the track is added to a conference the track will be removed. Returns Promise.
323
 
327
 
324
    Note: This method is implemented only for the local tracks.
328
    Note: This method is implemented only for the local tracks.
325
 
329
 

+ 4
- 4
doc/example/example.js Visa fil

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 Visa fil

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 Visa fil

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 Visa fil

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
 /**

Laddar…
Avbryt
Spara