Browse Source

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

tags/v0.0.2
hristoterezov 9 years ago
parent
commit
1c9eed44c5

+ 10
- 6
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,
@@ -868,7 +872,7 @@ function setupListeners(conference) {
868 872
                 for(var i = 0; i < tracks.length; i++) {
869 873
                     if(tracks[i] && tracks[i].stream &&
870 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 876
                         conference.eventEmitter.emit(
873 877
                             JitsiConferenceEvents.TRACK_REMOVED, track);
874 878
                         return;

+ 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

@@ -23,5 +23,6 @@ module.exports = {
23 23
     },
24 24
     UNSUPPORTED_RESOLUTION: "gum.unsupported_resolution",
25 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 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

@@ -106,6 +106,10 @@ JitsiMeetJS.setLogLevel(JitsiMeetJS.logLevels.ERROR);
106 106
         - CONNECTION_DISCONNECTED - indicates that we are disconnected.
107 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 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 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 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,7 +323,7 @@ We have the following methods for controling the tracks:
319 323
 
320 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 328
    Note: This method is implemented only for the local tracks.
325 329
 

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

Loading…
Cancel
Save