Browse Source

Prevents firing TRACK_REMOVED events when muting.

tags/v0.0.2
hristoterezov 10 years ago
parent
commit
50c2843d5e
3 changed files with 83 additions and 14 deletions
  1. 73
    11
      lib-jitsi-meet.js
  2. 8
    2
      modules/RTC/JitsiLocalTrack.js
  3. 2
    1
      modules/RTC/JitsiTrack.js

+ 73
- 11
lib-jitsi-meet.js View File

@@ -844,11 +844,15 @@ function JitsiLocalTrack(RTC, stream, eventEmitter, videoType, isGUMStream)
844 844
     this.eventEmitter = eventEmitter;
845 845
     this.videoType = videoType;
846 846
     this.isGUMStream = true;
847
+    this.dontFireRemoveEvent = false;
848
+    var self = this;
847 849
     if(isGUMStream === false)
848 850
         this.isGUMStream = isGUMStream;
849 851
     this.stream.onended = function () {
850
-        this.eventEmitter.emit(StreamEventTypes.EVENT_TYPE_LOCAL_ENDED, this);
851
-    }.bind(this);
852
+        if(!self.dontFireRemoveEvent)
853
+            self.eventEmitter.emit(StreamEventTypes.EVENT_TYPE_LOCAL_ENDED, self);
854
+        self.dontFireRemoveEvent = false;
855
+    };
852 856
 }
853 857
 
854 858
 JitsiLocalTrack.prototype = Object.create(JitsiTrack.prototype);
@@ -860,7 +864,7 @@ JitsiLocalTrack.prototype.constructor = JitsiLocalTrack;
860 864
  */
861 865
 JitsiLocalTrack.prototype._setMute = function (mute) {
862 866
     var isAudio = this.type === JitsiTrack.AUDIO;
863
-    //FIXME: ADD some container logic (attach detach the streams)
867
+    this.dontFireRemoveEvent = false;
864 868
 
865 869
     if ((window.location.protocol != "https:" && this.isGUMStream) ||
866 870
         (isAudio && this.isGUMStream) || this.videoType === "screen" ||
@@ -878,6 +882,7 @@ JitsiLocalTrack.prototype._setMute = function (mute) {
878 882
         this.eventEmitter.emit(StreamEventTypes.TRACK_MUTE_CHANGED, this);
879 883
     } else {
880 884
         if (mute) {
885
+            this.dontFireRemoveEvent = true;
881 886
             this.rtc.room.removeStream(this.stream);
882 887
             this.stream.stop();
883 888
             if(isAudio)
@@ -979,9 +984,14 @@ var StreamEventTypes = require("../../service/RTC/StreamEventTypes");
979 984
 
980 985
 /**
981 986
  * Represents a single media track (either audio or video).
987
+ * @param RTC the rtc instance.
988
+ * @param data object with the stream and some details about it(participant id, video type, etc.)
989
+ * @param sid sid for the Media Stream
990
+ * @param ssrc ssrc for the Media Stream
991
+ * @param eventEmitter the event emitter
982 992
  * @constructor
983 993
  */
984
-function JitsiRemoteTrack(RTC, data, sid, ssrc, browser, eventEmitter) {
994
+function JitsiRemoteTrack(RTC, data, sid, ssrc, eventEmitter) {
985 995
     JitsiTrack.call(this, RTC, data.stream);
986 996
     this.rtc = RTC;
987 997
     this.sid = sid;
@@ -1001,18 +1011,27 @@ function JitsiRemoteTrack(RTC, data, sid, ssrc, browser, eventEmitter) {
1001 1011
 JitsiRemoteTrack.prototype = Object.create(JitsiTrack.prototype);
1002 1012
 JitsiRemoteTrack.prototype.constructor = JitsiRemoteTrack;
1003 1013
 
1014
+/**
1015
+ * Sets current muted status and fires an events for the change.
1016
+ * @param value the muted status.
1017
+ */
1004 1018
 JitsiRemoteTrack.prototype.setMute = function (value) {
1005 1019
     this.stream.muted = value;
1006 1020
     this.muted = value;
1007 1021
     this.eventEmitter.emit(StreamEventTypes.TRACK_MUTE_CHANGED, this);
1008 1022
 };
1009 1023
 
1024
+/**
1025
+ * Returns the current muted status of the track.
1026
+ * @returns {boolean|*|JitsiRemoteTrack.muted} <tt>true</tt> if the track is muted and <tt>false</tt> otherwise.
1027
+ */
1010 1028
 JitsiRemoteTrack.prototype.isMuted = function () {
1011 1029
     return this.muted;
1012 1030
 }
1013 1031
 
1014 1032
 /**
1015
- * @returns {JitsiParticipant} to which this track belongs, or null if it is a local track.
1033
+ * Returns the participant id which owns the track.
1034
+ * @returns {string} the id of the participants.
1016 1035
  */
1017 1036
 JitsiRemoteTrack.prototype.getParitcipantId = function() {
1018 1037
     return Strophe.getResourceFromJid(this.peerjid);
@@ -1051,6 +1070,10 @@ function implementOnEndedHandling(stream) {
1051 1070
  */
1052 1071
 function JitsiTrack(RTC, stream)
1053 1072
 {
1073
+    /**
1074
+     * Array with the HTML elements that are displaying the streams.
1075
+     * @type {Array}
1076
+     */
1054 1077
     this.containers = [];
1055 1078
     this.rtc = RTC;
1056 1079
     this.stream = stream;
@@ -1112,16 +1135,18 @@ JitsiTrack.prototype.unmute = function () {
1112 1135
 
1113 1136
 /**
1114 1137
  * Attaches the MediaStream of this track to an HTML container (?).
1138
+ * Adds the container to the list of containers that are displaying the track.
1115 1139
  * @param container the HTML container
1116 1140
  */
1117 1141
 JitsiTrack.prototype.attach = function (container) {
1118
-    RTC.attachMediaStream(container, this.stream);
1142
+    if(this.stream)
1143
+        RTC.attachMediaStream(container, this.stream);
1119 1144
     this.containers.push(container);
1120 1145
 }
1121 1146
 
1122 1147
 /**
1123 1148
  * Removes the track from the passed HTML container.
1124
- * @param container the HTML container
1149
+ * @param container the HTML container. If <tt>null</tt> all containers are removed.
1125 1150
  */
1126 1151
 JitsiTrack.prototype.detach = function (container) {
1127 1152
     for(var i = 0; i < this.containers.length; i++)
@@ -1145,8 +1170,6 @@ JitsiTrack.prototype.detach = function (container) {
1145 1170
  * NOTE: Works for local tracks only.
1146 1171
  */
1147 1172
 JitsiTrack.prototype.stop = function () {
1148
-
1149
-    this.detach();
1150 1173
 }
1151 1174
 
1152 1175
 
@@ -1255,6 +1278,14 @@ function RTC(room, options) {
1255 1278
 
1256 1279
 }
1257 1280
 
1281
+/**
1282
+ * Creates the local MediaStreams.
1283
+ * @param options object for options (NOTE: currently only list of devices and resolution are supported)
1284
+ * @param dontCreateJitsiTrack if <tt>true</tt> objects with the following structure {stream: the Media Stream,
1285
+  * type: "audio" or "video", isMuted: true/false, videoType: "camera" or "desktop"}
1286
+ * will be returned trough the Promise, otherwise JitsiTrack objects will be returned.
1287
+ * @returns {*} Promise object that will receive the new JitsiTracks
1288
+ */
1258 1289
 RTC.prototype.obtainAudioAndVideoPermissions = function (options, dontCreateJitsiTrack) {
1259 1290
     return RTCUtils.obtainAudioAndVideoPermissions(this,
1260 1291
         options.devices, getMediaStreamUsage(), options.resolution, dontCreateJitsiTrack);
@@ -2038,8 +2069,15 @@ var RTCUtils = {
2038 2069
     },
2039 2070
 
2040 2071
     /**
2041
-     * We ask for audio and video combined stream in order to get permissions and
2042
-     * not to ask twice.
2072
+     * Creates the local MediaStreams.
2073
+     * @param RTC the rtc service.
2074
+     * @param devices the devices that will be requested
2075
+     * @param usageOptions object with devices that should be requested.
2076
+     * @param resolution resolution constraints
2077
+     * @param dontCreateJitsiTrack if <tt>true</tt> objects with the following structure {stream: the Media Stream,
2078
+     * type: "audio" or "video", isMuted: true/false, videoType: "camera" or "desktop"}
2079
+     * will be returned trough the Promise, otherwise JitsiTrack objects will be returned.
2080
+     * @returns {*} Promise object that will receive the new JitsiTracks
2043 2081
      */
2044 2082
     obtainAudioAndVideoPermissions: function (RTC, devices, usageOptions, resolution, dontCreateJitsiTracks) {
2045 2083
         var self = this;
@@ -2133,6 +2171,13 @@ var RTCUtils = {
2133 2171
         }.bind(this));
2134 2172
     },
2135 2173
 
2174
+    /**
2175
+     * Successful callback called from GUM.
2176
+     * @param RTC the rtc service
2177
+     * @param stream the new MediaStream
2178
+     * @param usageOptions the list of the devices that should be queried.
2179
+     * @returns {*}
2180
+     */
2136 2181
     successCallback: function (RTC, stream, usageOptions) {
2137 2182
         // If this is FF or IE, the stream parameter is *not* a MediaStream object,
2138 2183
         // it's an object with two properties: audioStream, videoStream.
@@ -2142,6 +2187,16 @@ var RTCUtils = {
2142 2187
         return this.handleLocalStream(RTC, stream, usageOptions);
2143 2188
     },
2144 2189
 
2190
+    /**
2191
+     * Error callback called from GUM. Retries the GUM call with different resolutions.
2192
+     * @param error the error
2193
+     * @param resolve the resolve funtion that will be called on success.
2194
+     * @param RTC the rtc service
2195
+     * @param currentResolution the last resolution used for GUM.
2196
+     * @param dontCreateJitsiTracks if <tt>true</tt> objects with the following structure {stream: the Media Stream,
2197
+     * type: "audio" or "video", isMuted: true/false, videoType: "camera" or "desktop"}
2198
+     * will be returned trough the Promise, otherwise JitsiTrack objects will be returned.
2199
+     */
2145 2200
     errorCallback: function (error, resolve, RTC, currentResolution, dontCreateJitsiTracks) {
2146 2201
         var self = this;
2147 2202
         console.error('failed to obtain audio/video stream - trying audio only', error);
@@ -2178,6 +2233,13 @@ var RTCUtils = {
2178 2233
         }
2179 2234
     },
2180 2235
 
2236
+    /**
2237
+     * Handles the newly created Media Streams.
2238
+     * @param service the rtc service
2239
+     * @param stream the new Media Streams
2240
+     * @param usageOptions the list of the devices that should be queried.
2241
+     * @returns {*[]} Promise object with the new Media Streams.
2242
+     */
2181 2243
     handleLocalStream: function (service, stream, usageOptions) {
2182 2244
         var audioStream, videoStream;
2183 2245
         // If this is FF, the stream parameter is *not* a MediaStream object, it's

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

@@ -13,11 +13,15 @@ function JitsiLocalTrack(RTC, stream, eventEmitter, videoType, isGUMStream)
13 13
     this.eventEmitter = eventEmitter;
14 14
     this.videoType = videoType;
15 15
     this.isGUMStream = true;
16
+    this.dontFireRemoveEvent = false;
17
+    var self = this;
16 18
     if(isGUMStream === false)
17 19
         this.isGUMStream = isGUMStream;
18 20
     this.stream.onended = function () {
19
-        this.eventEmitter.emit(StreamEventTypes.EVENT_TYPE_LOCAL_ENDED, this);
20
-    }.bind(this);
21
+        if(!self.dontFireRemoveEvent)
22
+            self.eventEmitter.emit(StreamEventTypes.EVENT_TYPE_LOCAL_ENDED, self);
23
+        self.dontFireRemoveEvent = false;
24
+    };
21 25
 }
22 26
 
23 27
 JitsiLocalTrack.prototype = Object.create(JitsiTrack.prototype);
@@ -29,6 +33,7 @@ JitsiLocalTrack.prototype.constructor = JitsiLocalTrack;
29 33
  */
30 34
 JitsiLocalTrack.prototype._setMute = function (mute) {
31 35
     var isAudio = this.type === JitsiTrack.AUDIO;
36
+    this.dontFireRemoveEvent = false;
32 37
 
33 38
     if ((window.location.protocol != "https:" && this.isGUMStream) ||
34 39
         (isAudio && this.isGUMStream) || this.videoType === "screen" ||
@@ -46,6 +51,7 @@ JitsiLocalTrack.prototype._setMute = function (mute) {
46 51
         this.eventEmitter.emit(StreamEventTypes.TRACK_MUTE_CHANGED, this);
47 52
     } else {
48 53
         if (mute) {
54
+            this.dontFireRemoveEvent = true;
49 55
             this.rtc.room.removeStream(this.stream);
50 56
             this.stream.stop();
51 57
             if(isAudio)

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

@@ -93,7 +93,8 @@ JitsiTrack.prototype.unmute = function () {
93 93
  * @param container the HTML container
94 94
  */
95 95
 JitsiTrack.prototype.attach = function (container) {
96
-    RTC.attachMediaStream(container, this.stream);
96
+    if(this.stream)
97
+        RTC.attachMediaStream(container, this.stream);
97 98
     this.containers.push(container);
98 99
 }
99 100
 

Loading…
Cancel
Save