|
|
@@ -54,400 +54,380 @@ function addMediaStreamInactiveHandler(mediaStream, handler) {
|
|
54
|
54
|
}
|
|
55
|
55
|
}
|
|
56
|
56
|
|
|
57
|
|
-/* eslint-disable max-params */
|
|
58
|
|
-
|
|
59
|
57
|
/**
|
|
60
|
58
|
* Represents a single media track (either audio or video).
|
|
61
|
|
- * @constructor
|
|
62
|
|
- * @param rtc the rtc instance
|
|
63
|
|
- * @param stream the WebRTC MediaStream instance
|
|
64
|
|
- * @param track the WebRTC MediaStreamTrack instance, must be part of
|
|
65
|
|
- * the given <tt>stream</tt>.
|
|
66
|
|
- * @param streamInactiveHandler the function that will handle
|
|
67
|
|
- * onended/oninactive events of the stream.
|
|
68
|
|
- * @param trackMediaType the media type of the JitsiTrack
|
|
69
|
|
- * @param videoType the VideoType for this track if any
|
|
70
|
59
|
*/
|
|
71
|
|
-export default function JitsiTrack(
|
|
72
|
|
- conference,
|
|
73
|
|
- stream,
|
|
74
|
|
- track,
|
|
75
|
|
- streamInactiveHandler,
|
|
76
|
|
- trackMediaType,
|
|
77
|
|
- videoType) {
|
|
|
60
|
+export default class JitsiTrack extends EventEmitter {
|
|
|
61
|
+ /* eslint-disable max-params */
|
|
78
|
62
|
/**
|
|
79
|
|
- * Array with the HTML elements that are displaying the streams.
|
|
80
|
|
- * @type {Array}
|
|
|
63
|
+ * Represents a single media track (either audio or video).
|
|
|
64
|
+ * @constructor
|
|
|
65
|
+ * @param rtc the rtc instance
|
|
|
66
|
+ * @param stream the WebRTC MediaStream instance
|
|
|
67
|
+ * @param track the WebRTC MediaStreamTrack instance, must be part of
|
|
|
68
|
+ * the given <tt>stream</tt>.
|
|
|
69
|
+ * @param streamInactiveHandler the function that will handle
|
|
|
70
|
+ * onended/oninactive events of the stream.
|
|
|
71
|
+ * @param trackMediaType the media type of the JitsiTrack
|
|
|
72
|
+ * @param videoType the VideoType for this track if any
|
|
81
|
73
|
*/
|
|
82
|
|
- this.containers = [];
|
|
83
|
|
- this.conference = conference;
|
|
84
|
|
- this.stream = stream;
|
|
85
|
|
- this.eventEmitter = new EventEmitter();
|
|
86
|
|
- this.audioLevel = -1;
|
|
87
|
|
- this.type = trackMediaType;
|
|
88
|
|
- this.track = track;
|
|
89
|
|
- this.videoType = videoType;
|
|
90
|
|
- this.handlers = {};
|
|
|
74
|
+ constructor(
|
|
|
75
|
+ conference,
|
|
|
76
|
+ stream,
|
|
|
77
|
+ track,
|
|
|
78
|
+ streamInactiveHandler,
|
|
|
79
|
+ trackMediaType,
|
|
|
80
|
+ videoType) {
|
|
|
81
|
+ super();
|
|
|
82
|
+
|
|
|
83
|
+ // aliases for addListener/removeListener
|
|
|
84
|
+ this.addEventListener = this.addListener;
|
|
|
85
|
+ this.removeEventListener = this.off = this.removeListener;
|
|
|
86
|
+
|
|
|
87
|
+ /**
|
|
|
88
|
+ * Array with the HTML elements that are displaying the streams.
|
|
|
89
|
+ * @type {Array}
|
|
|
90
|
+ */
|
|
|
91
|
+ this.containers = [];
|
|
|
92
|
+ this.conference = conference;
|
|
|
93
|
+ this.stream = stream;
|
|
|
94
|
+ this.audioLevel = -1;
|
|
|
95
|
+ this.type = trackMediaType;
|
|
|
96
|
+ this.track = track;
|
|
|
97
|
+ this.videoType = videoType;
|
|
|
98
|
+ this.handlers = {};
|
|
|
99
|
+
|
|
|
100
|
+ /**
|
|
|
101
|
+ * Indicates whether this JitsiTrack has been disposed. If true, this
|
|
|
102
|
+ * JitsiTrack is to be considered unusable and operations involving it
|
|
|
103
|
+ * are to fail (e.g. {@link JitsiConference#addTrack(JitsiTrack)},
|
|
|
104
|
+ * {@link JitsiConference#removeTrack(JitsiTrack)}).
|
|
|
105
|
+ * @type {boolean}
|
|
|
106
|
+ */
|
|
|
107
|
+ this.disposed = false;
|
|
|
108
|
+ this._setHandler('inactive', streamInactiveHandler);
|
|
|
109
|
+ }
|
|
|
110
|
+
|
|
|
111
|
+ /* eslint-enable max-params */
|
|
91
|
112
|
|
|
92
|
113
|
/**
|
|
93
|
|
- * Indicates whether this JitsiTrack has been disposed. If true, this
|
|
94
|
|
- * JitsiTrack is to be considered unusable and operations involving it are
|
|
95
|
|
- * to fail (e.g. {@link JitsiConference#addTrack(JitsiTrack)},
|
|
96
|
|
- * {@link JitsiConference#removeTrack(JitsiTrack)}).
|
|
97
|
|
- * @type {boolean}
|
|
|
114
|
+ * Sets handler to the WebRTC MediaStream or MediaStreamTrack object
|
|
|
115
|
+ * depending on the passed type.
|
|
|
116
|
+ * @param {string} type the type of the handler that is going to be set
|
|
|
117
|
+ * @param {Function} handler the handler.
|
|
98
|
118
|
*/
|
|
99
|
|
- this.disposed = false;
|
|
100
|
|
- this._setHandler('inactive', streamInactiveHandler);
|
|
101
|
|
-}
|
|
102
|
|
-
|
|
103
|
|
-/* eslint-enable max-params */
|
|
|
119
|
+ _setHandler(type, handler) {
|
|
|
120
|
+ this.handlers[type] = handler;
|
|
|
121
|
+ if (!this.stream) {
|
|
|
122
|
+ return;
|
|
|
123
|
+ }
|
|
104
|
124
|
|
|
105
|
|
-/**
|
|
106
|
|
- * Sets handler to the WebRTC MediaStream or MediaStreamTrack object depending
|
|
107
|
|
- * on the passed type.
|
|
108
|
|
- * @param {string} type the type of the handler that is going to be set
|
|
109
|
|
- * @param {Function} handler the handler.
|
|
110
|
|
- */
|
|
111
|
|
-JitsiTrack.prototype._setHandler = function(type, handler) {
|
|
112
|
|
- this.handlers[type] = handler;
|
|
113
|
|
- if (!this.stream) {
|
|
114
|
|
- return;
|
|
|
125
|
+ if (type === 'inactive') {
|
|
|
126
|
+ if (RTCBrowserType.isFirefox()) {
|
|
|
127
|
+ implementOnEndedHandling(this);
|
|
|
128
|
+ }
|
|
|
129
|
+ addMediaStreamInactiveHandler(this.stream, handler);
|
|
|
130
|
+ } else if (trackHandler2Prop.hasOwnProperty(type)) {
|
|
|
131
|
+ this.stream.getVideoTracks().forEach(track => {
|
|
|
132
|
+ track[trackHandler2Prop[type]] = handler;
|
|
|
133
|
+ }, this);
|
|
|
134
|
+ }
|
|
115
|
135
|
}
|
|
116
|
136
|
|
|
117
|
|
- if (type === 'inactive') {
|
|
118
|
|
- if (RTCBrowserType.isFirefox()) {
|
|
119
|
|
- implementOnEndedHandling(this);
|
|
120
|
|
- }
|
|
121
|
|
- addMediaStreamInactiveHandler(this.stream, handler);
|
|
122
|
|
- } else if (trackHandler2Prop.hasOwnProperty(type)) {
|
|
123
|
|
- this.stream.getVideoTracks().forEach(track => {
|
|
124
|
|
- track[trackHandler2Prop[type]] = handler;
|
|
|
137
|
+ /**
|
|
|
138
|
+ * Sets the stream property of JitsiTrack object and sets all stored
|
|
|
139
|
+ * handlers to it.
|
|
|
140
|
+ * @param {MediaStream} stream the new stream.
|
|
|
141
|
+ */
|
|
|
142
|
+ _setStream(stream) {
|
|
|
143
|
+ this.stream = stream;
|
|
|
144
|
+ Object.keys(this.handlers).forEach(type => {
|
|
|
145
|
+ typeof this.handlers[type] === 'function'
|
|
|
146
|
+ && this._setHandler(type, this.handlers[type]);
|
|
125
|
147
|
}, this);
|
|
126
|
148
|
}
|
|
127
|
|
-};
|
|
128
|
|
-
|
|
129
|
|
-/**
|
|
130
|
|
- * Sets the stream property of JitsiTrack object and sets all stored handlers
|
|
131
|
|
- * to it.
|
|
132
|
|
- * @param {MediaStream} stream the new stream.
|
|
133
|
|
- */
|
|
134
|
|
-JitsiTrack.prototype._setStream = function(stream) {
|
|
135
|
|
- this.stream = stream;
|
|
136
|
|
- Object.keys(this.handlers).forEach(function(type) {
|
|
137
|
|
- typeof this.handlers[type] === 'function'
|
|
138
|
|
- && this._setHandler(type, this.handlers[type]);
|
|
139
|
|
- }, this);
|
|
140
|
|
-};
|
|
141
|
|
-
|
|
142
|
|
-/**
|
|
143
|
|
- * Returns the type (audio or video) of this track.
|
|
144
|
|
- */
|
|
145
|
|
-JitsiTrack.prototype.getType = function() {
|
|
146
|
|
- return this.type;
|
|
147
|
|
-};
|
|
148
|
|
-
|
|
149
|
|
-/**
|
|
150
|
|
- * Check if this is an audio track.
|
|
151
|
|
- */
|
|
152
|
|
-JitsiTrack.prototype.isAudioTrack = function() {
|
|
153
|
|
- return this.getType() === MediaType.AUDIO;
|
|
154
|
|
-};
|
|
155
|
|
-
|
|
156
|
|
-/**
|
|
157
|
|
- * Checks whether the underlying WebRTC <tt>MediaStreamTrack</tt> is muted
|
|
158
|
|
- * according to it's 'muted' field status.
|
|
159
|
|
- * @return {boolean} <tt>true</tt> if the underlying <tt>MediaStreamTrack</tt>
|
|
160
|
|
- * is muted or <tt>false</tt> otherwise.
|
|
161
|
|
- */
|
|
162
|
|
-JitsiTrack.prototype.isWebRTCTrackMuted = function() {
|
|
163
|
|
- return this.track && this.track.muted;
|
|
164
|
|
-};
|
|
165
|
|
-
|
|
166
|
|
-/**
|
|
167
|
|
- * Check if this is a video track.
|
|
168
|
|
- */
|
|
169
|
|
-JitsiTrack.prototype.isVideoTrack = function() {
|
|
170
|
|
- return this.getType() === MediaType.VIDEO;
|
|
171
|
|
-};
|
|
172
|
|
-
|
|
173
|
|
-/**
|
|
174
|
|
- * Checks whether this is a local track.
|
|
175
|
|
- * @abstract
|
|
176
|
|
- * @return {boolean} 'true' if it's a local track or 'false' otherwise.
|
|
177
|
|
- */
|
|
178
|
|
-JitsiTrack.prototype.isLocal = function() {
|
|
179
|
|
- throw new Error('Not implemented by subclass');
|
|
180
|
|
-};
|
|
181
|
|
-
|
|
182
|
|
-/**
|
|
183
|
|
- * Returns the WebRTC MediaStream instance.
|
|
184
|
|
- */
|
|
185
|
|
-JitsiTrack.prototype.getOriginalStream = function() {
|
|
186
|
|
- return this.stream;
|
|
187
|
|
-};
|
|
188
|
149
|
|
|
189
|
|
-/**
|
|
190
|
|
- * Returns the ID of the underlying WebRTC Media Stream(if any)
|
|
191
|
|
- * @returns {String|null}
|
|
192
|
|
- */
|
|
193
|
|
-JitsiTrack.prototype.getStreamId = function() {
|
|
194
|
|
- return this.stream ? this.stream.id : null;
|
|
195
|
|
-};
|
|
196
|
|
-
|
|
197
|
|
-/**
|
|
198
|
|
- * Return the underlying WebRTC MediaStreamTrack
|
|
199
|
|
- * @returns {MediaStreamTrack}
|
|
200
|
|
- */
|
|
201
|
|
-JitsiTrack.prototype.getTrack = function() {
|
|
202
|
|
- return this.track;
|
|
203
|
|
-};
|
|
204
|
|
-
|
|
205
|
|
-/**
|
|
206
|
|
- * Returns the ID of the underlying WebRTC MediaStreamTrack(if any)
|
|
207
|
|
- * @returns {String|null}
|
|
208
|
|
- */
|
|
209
|
|
-JitsiTrack.prototype.getTrackId = function() {
|
|
210
|
|
- return this.track ? this.track.id : null;
|
|
211
|
|
-};
|
|
|
150
|
+ /**
|
|
|
151
|
+ * Returns the type (audio or video) of this track.
|
|
|
152
|
+ */
|
|
|
153
|
+ getType() {
|
|
|
154
|
+ return this.type;
|
|
|
155
|
+ }
|
|
212
|
156
|
|
|
213
|
|
-/**
|
|
214
|
|
- * Return meaningful usage label for this track depending on it's media and
|
|
215
|
|
- * eventual video type.
|
|
216
|
|
- * @returns {string}
|
|
217
|
|
- */
|
|
218
|
|
-JitsiTrack.prototype.getUsageLabel = function() {
|
|
219
|
|
- if (this.isAudioTrack()) {
|
|
220
|
|
- return 'mic';
|
|
|
157
|
+ /**
|
|
|
158
|
+ * Check if this is an audio track.
|
|
|
159
|
+ */
|
|
|
160
|
+ isAudioTrack() {
|
|
|
161
|
+ return this.getType() === MediaType.AUDIO;
|
|
221
|
162
|
}
|
|
222
|
163
|
|
|
223
|
|
- return this.videoType ? this.videoType : 'default';
|
|
|
164
|
+ /**
|
|
|
165
|
+ * Checks whether the underlying WebRTC <tt>MediaStreamTrack</tt> is muted
|
|
|
166
|
+ * according to it's 'muted' field status.
|
|
|
167
|
+ * @return {boolean} <tt>true</tt> if the underlying
|
|
|
168
|
+ * <tt>MediaStreamTrack</tt> is muted or <tt>false</tt> otherwise.
|
|
|
169
|
+ */
|
|
|
170
|
+ isWebRTCTrackMuted() {
|
|
|
171
|
+ return this.track && this.track.muted;
|
|
|
172
|
+ }
|
|
224
|
173
|
|
|
225
|
|
-};
|
|
|
174
|
+ /**
|
|
|
175
|
+ * Check if this is a video track.
|
|
|
176
|
+ */
|
|
|
177
|
+ isVideoTrack() {
|
|
|
178
|
+ return this.getType() === MediaType.VIDEO;
|
|
|
179
|
+ }
|
|
226
|
180
|
|
|
227
|
|
-/**
|
|
228
|
|
- * Eventually will trigger RTCEvents.TRACK_ATTACHED event.
|
|
229
|
|
- * @param container the video/audio container to which this stream is attached
|
|
230
|
|
- * and for which event will be fired.
|
|
231
|
|
- * @private
|
|
232
|
|
- */
|
|
233
|
|
-JitsiTrack.prototype._maybeFireTrackAttached = function(container) {
|
|
234
|
|
- if (this.conference && container) {
|
|
235
|
|
- this.conference._onTrackAttach(this, container);
|
|
|
181
|
+ /**
|
|
|
182
|
+ * Checks whether this is a local track.
|
|
|
183
|
+ * @abstract
|
|
|
184
|
+ * @return {boolean} 'true' if it's a local track or 'false' otherwise.
|
|
|
185
|
+ */
|
|
|
186
|
+ isLocal() {
|
|
|
187
|
+ throw new Error('Not implemented by subclass');
|
|
236
|
188
|
}
|
|
237
|
|
-};
|
|
238
|
189
|
|
|
239
|
|
-/**
|
|
240
|
|
- * Attaches the MediaStream of this track to an HTML container.
|
|
241
|
|
- * Adds the container to the list of containers that are displaying the track.
|
|
242
|
|
- * Note that Temasys plugin will replace original audio/video element with
|
|
243
|
|
- * 'object' when stream is being attached to the container for the first time.
|
|
244
|
|
- *
|
|
245
|
|
- * * NOTE * if given container element is not visible when the stream is being
|
|
246
|
|
- * attached it will be shown back given that Temasys plugin is currently in use.
|
|
247
|
|
- *
|
|
248
|
|
- * @param container the HTML container which can be 'video' or 'audio' element.
|
|
249
|
|
- * It can also be 'object' element if Temasys plugin is in use and this
|
|
250
|
|
- * method has been called previously on video or audio HTML element.
|
|
251
|
|
- *
|
|
252
|
|
- * @returns potentially new instance of container if it was replaced by the
|
|
253
|
|
- * library. That's the case when Temasys plugin is in use.
|
|
254
|
|
- */
|
|
255
|
|
-JitsiTrack.prototype.attach = function(container) {
|
|
256
|
|
- let c = container;
|
|
|
190
|
+ /**
|
|
|
191
|
+ * Returns the WebRTC MediaStream instance.
|
|
|
192
|
+ */
|
|
|
193
|
+ getOriginalStream() {
|
|
|
194
|
+ return this.stream;
|
|
|
195
|
+ }
|
|
257
|
196
|
|
|
258
|
|
- if (this.stream) {
|
|
259
|
|
- c = RTCUtils.attachMediaStream(container, this.stream);
|
|
|
197
|
+ /**
|
|
|
198
|
+ * Returns the ID of the underlying WebRTC Media Stream(if any)
|
|
|
199
|
+ * @returns {String|null}
|
|
|
200
|
+ */
|
|
|
201
|
+ getStreamId() {
|
|
|
202
|
+ return this.stream ? this.stream.id : null;
|
|
260
|
203
|
}
|
|
261
|
|
- this.containers.push(c);
|
|
262
|
|
- this._maybeFireTrackAttached(c);
|
|
263
|
|
- this._attachTTFMTracker(c);
|
|
264
|
204
|
|
|
265
|
|
- return c;
|
|
266
|
|
-};
|
|
|
205
|
+ /**
|
|
|
206
|
+ * Return the underlying WebRTC MediaStreamTrack
|
|
|
207
|
+ * @returns {MediaStreamTrack}
|
|
|
208
|
+ */
|
|
|
209
|
+ getTrack() {
|
|
|
210
|
+ return this.track;
|
|
|
211
|
+ }
|
|
267
|
212
|
|
|
268
|
|
-/**
|
|
269
|
|
- * Removes this JitsiTrack from the passed HTML container.
|
|
270
|
|
- *
|
|
271
|
|
- * @param container the HTML container to detach from this JitsiTrack. If
|
|
272
|
|
- * <tt>null</tt> or <tt>undefined</tt>, all containers are removed. A container
|
|
273
|
|
- * can be a 'video', 'audio' or 'object' HTML element instance to which this
|
|
274
|
|
- * JitsiTrack is currently attached.
|
|
275
|
|
- */
|
|
276
|
|
-JitsiTrack.prototype.detach = function(container) {
|
|
277
|
|
- for (let cs = this.containers, i = cs.length - 1; i >= 0; --i) {
|
|
278
|
|
- const c = cs[i];
|
|
|
213
|
+ /**
|
|
|
214
|
+ * Returns the ID of the underlying WebRTC MediaStreamTrack(if any)
|
|
|
215
|
+ * @returns {String|null}
|
|
|
216
|
+ */
|
|
|
217
|
+ getTrackId() {
|
|
|
218
|
+ return this.track ? this.track.id : null;
|
|
|
219
|
+ }
|
|
279
|
220
|
|
|
280
|
|
- if (!container) {
|
|
281
|
|
- RTCUtils.attachMediaStream(c, null);
|
|
282
|
|
- }
|
|
283
|
|
- if (!container || c === container) {
|
|
284
|
|
- cs.splice(i, 1);
|
|
|
221
|
+ /**
|
|
|
222
|
+ * Return meaningful usage label for this track depending on it's media and
|
|
|
223
|
+ * eventual video type.
|
|
|
224
|
+ * @returns {string}
|
|
|
225
|
+ */
|
|
|
226
|
+ getUsageLabel() {
|
|
|
227
|
+ if (this.isAudioTrack()) {
|
|
|
228
|
+ return 'mic';
|
|
285
|
229
|
}
|
|
|
230
|
+
|
|
|
231
|
+ return this.videoType ? this.videoType : 'default';
|
|
286
|
232
|
}
|
|
287
|
233
|
|
|
288
|
|
- if (container) {
|
|
289
|
|
- RTCUtils.attachMediaStream(container, null);
|
|
|
234
|
+ /**
|
|
|
235
|
+ * Eventually will trigger RTCEvents.TRACK_ATTACHED event.
|
|
|
236
|
+ * @param container the video/audio container to which this stream is
|
|
|
237
|
+ * attached and for which event will be fired.
|
|
|
238
|
+ * @private
|
|
|
239
|
+ */
|
|
|
240
|
+ _maybeFireTrackAttached(container) {
|
|
|
241
|
+ if (this.conference && container) {
|
|
|
242
|
+ this.conference._onTrackAttach(this, container);
|
|
|
243
|
+ }
|
|
290
|
244
|
}
|
|
291
|
|
-};
|
|
292
|
245
|
|
|
293
|
|
-/**
|
|
294
|
|
- * Attach time to first media tracker only if there is conference and only
|
|
295
|
|
- * for the first element.
|
|
296
|
|
- * @param container the HTML container which can be 'video' or 'audio' element.
|
|
297
|
|
- * It can also be 'object' element if Temasys plugin is in use and this
|
|
298
|
|
- * method has been called previously on video or audio HTML element.
|
|
299
|
|
- * @private
|
|
300
|
|
- */
|
|
301
|
|
-// eslint-disable-next-line no-unused-vars
|
|
302
|
|
-JitsiTrack.prototype._attachTTFMTracker = function(container) {
|
|
303
|
|
- // Should be defined by the classes that are extending JitsiTrack
|
|
304
|
|
-};
|
|
|
246
|
+ /**
|
|
|
247
|
+ * Attaches the MediaStream of this track to an HTML container.
|
|
|
248
|
+ * Adds the container to the list of containers that are displaying the
|
|
|
249
|
+ * track. Note that Temasys plugin will replace original audio/video element
|
|
|
250
|
+ * with 'object' when stream is being attached to the container for the
|
|
|
251
|
+ * first time.
|
|
|
252
|
+ * * NOTE * if given container element is not visible when the stream is
|
|
|
253
|
+ * being attached it will be shown back given that Temasys plugin is
|
|
|
254
|
+ * currently in use.
|
|
|
255
|
+ *
|
|
|
256
|
+ * @param container the HTML container which can be 'video' or 'audio'
|
|
|
257
|
+ * element. It can also be 'object' element if Temasys plugin is in use and
|
|
|
258
|
+ * this method has been called previously on video or audio HTML element.
|
|
|
259
|
+ *
|
|
|
260
|
+ * @returns potentially new instance of container if it was replaced by the
|
|
|
261
|
+ * library. That's the case when Temasys plugin is in use.
|
|
|
262
|
+ */
|
|
|
263
|
+ attach(container) {
|
|
|
264
|
+ let c = container;
|
|
305
|
265
|
|
|
306
|
|
-/**
|
|
307
|
|
- * Removes attached event listeners.
|
|
308
|
|
- *
|
|
309
|
|
- * @returns {Promise}
|
|
310
|
|
- */
|
|
311
|
|
-JitsiTrack.prototype.dispose = function() {
|
|
312
|
|
- this.eventEmitter.removeAllListeners();
|
|
|
266
|
+ if (this.stream) {
|
|
|
267
|
+ c = RTCUtils.attachMediaStream(container, this.stream);
|
|
|
268
|
+ }
|
|
|
269
|
+ this.containers.push(c);
|
|
|
270
|
+ this._maybeFireTrackAttached(c);
|
|
|
271
|
+ this._attachTTFMTracker(c);
|
|
313
|
272
|
|
|
314
|
|
- this.disposed = true;
|
|
|
273
|
+ return c;
|
|
|
274
|
+ }
|
|
315
|
275
|
|
|
316
|
|
- return Promise.resolve();
|
|
317
|
|
-};
|
|
|
276
|
+ /**
|
|
|
277
|
+ * Removes this JitsiTrack from the passed HTML container.
|
|
|
278
|
+ *
|
|
|
279
|
+ * @param container the HTML container to detach from this JitsiTrack. If
|
|
|
280
|
+ * <tt>null</tt> or <tt>undefined</tt>, all containers are removed. A
|
|
|
281
|
+ * container can be a 'video', 'audio' or 'object' HTML element instance to
|
|
|
282
|
+ * which this JitsiTrack is currently attached.
|
|
|
283
|
+ */
|
|
|
284
|
+ detach(container) {
|
|
|
285
|
+ for (let cs = this.containers, i = cs.length - 1; i >= 0; --i) {
|
|
|
286
|
+ const c = cs[i];
|
|
|
287
|
+
|
|
|
288
|
+ if (!container) {
|
|
|
289
|
+ RTCUtils.attachMediaStream(c, null);
|
|
|
290
|
+ }
|
|
|
291
|
+ if (!container || c === container) {
|
|
|
292
|
+ cs.splice(i, 1);
|
|
|
293
|
+ }
|
|
|
294
|
+ }
|
|
318
|
295
|
|
|
319
|
|
-/**
|
|
320
|
|
- * Returns true if this is a video track and the source of the video is a
|
|
321
|
|
- * screen capture as opposed to a camera.
|
|
322
|
|
- */
|
|
323
|
|
-JitsiTrack.prototype.isScreenSharing = function() {
|
|
324
|
|
- // FIXME: Should be fixed or removed.
|
|
325
|
|
-};
|
|
|
296
|
+ if (container) {
|
|
|
297
|
+ RTCUtils.attachMediaStream(container, null);
|
|
|
298
|
+ }
|
|
|
299
|
+ }
|
|
326
|
300
|
|
|
327
|
|
-/**
|
|
328
|
|
- * Returns id of the track.
|
|
329
|
|
- * @returns {string|null} id of the track or null if this is fake track.
|
|
330
|
|
- */
|
|
331
|
|
-JitsiTrack.prototype.getId = function() {
|
|
332
|
|
- if (this.stream) {
|
|
333
|
|
- return RTCUtils.getStreamID(this.stream);
|
|
|
301
|
+ /**
|
|
|
302
|
+ * Attach time to first media tracker only if there is conference and only
|
|
|
303
|
+ * for the first element.
|
|
|
304
|
+ *
|
|
|
305
|
+ * @param {HTMLElement} container the HTML container which can be 'video' or
|
|
|
306
|
+ * 'audio' element. It can also be 'object' element if Temasys plugin is in
|
|
|
307
|
+ * use and this method has been called previously on video or audio HTML
|
|
|
308
|
+ * element.
|
|
|
309
|
+ * @private
|
|
|
310
|
+ */
|
|
|
311
|
+ _attachTTFMTracker(container) { // eslint-disable-line no-unused-vars
|
|
|
312
|
+ // Should be defined by the classes that are extending JitsiTrack
|
|
334
|
313
|
}
|
|
335
|
314
|
|
|
336
|
|
- return null;
|
|
|
315
|
+ /**
|
|
|
316
|
+ * Removes attached event listeners.
|
|
|
317
|
+ *
|
|
|
318
|
+ * @returns {Promise}
|
|
|
319
|
+ */
|
|
|
320
|
+ dispose() {
|
|
|
321
|
+ this.removeAllListeners();
|
|
337
|
322
|
|
|
338
|
|
-};
|
|
|
323
|
+ this.disposed = true;
|
|
339
|
324
|
|
|
340
|
|
-/**
|
|
341
|
|
- * Checks whether the MediaStream is active/not ended.
|
|
342
|
|
- * When there is no check for active we don't have information and so
|
|
343
|
|
- * will return that stream is active (in case of FF).
|
|
344
|
|
- * @returns {boolean} whether MediaStream is active.
|
|
345
|
|
- */
|
|
346
|
|
-JitsiTrack.prototype.isActive = function() {
|
|
347
|
|
- if (typeof this.stream.active !== 'undefined') {
|
|
348
|
|
- return this.stream.active;
|
|
|
325
|
+ return Promise.resolve();
|
|
349
|
326
|
}
|
|
350
|
327
|
|
|
351
|
|
- return true;
|
|
|
328
|
+ /**
|
|
|
329
|
+ * Returns true if this is a video track and the source of the video is a
|
|
|
330
|
+ * screen capture as opposed to a camera.
|
|
|
331
|
+ */
|
|
|
332
|
+ isScreenSharing() {
|
|
|
333
|
+ // FIXME: Should be fixed or removed.
|
|
|
334
|
+ }
|
|
352
|
335
|
|
|
353
|
|
-};
|
|
|
336
|
+ /**
|
|
|
337
|
+ * Returns id of the track.
|
|
|
338
|
+ * @returns {string|null} id of the track or null if this is fake track.
|
|
|
339
|
+ */
|
|
|
340
|
+ getId() {
|
|
|
341
|
+ if (this.stream) {
|
|
|
342
|
+ return RTCUtils.getStreamID(this.stream);
|
|
|
343
|
+ }
|
|
354
|
344
|
|
|
355
|
|
-/**
|
|
356
|
|
- * Attaches a handler for events(For example - "audio level changed".).
|
|
357
|
|
- * All possible event are defined in JitsiTrackEvents.
|
|
358
|
|
- * @param eventId the event ID.
|
|
359
|
|
- * @param handler handler for the event.
|
|
360
|
|
- */
|
|
361
|
|
-JitsiTrack.prototype.on = function(eventId, handler) {
|
|
362
|
|
- if (this.eventEmitter) {
|
|
363
|
|
- this.eventEmitter.on(eventId, handler);
|
|
|
345
|
+ return null;
|
|
364
|
346
|
}
|
|
365
|
|
-};
|
|
366
|
347
|
|
|
367
|
|
-/**
|
|
368
|
|
- * Removes event listener
|
|
369
|
|
- * @param eventId the event ID.
|
|
370
|
|
- * @param [handler] optional, the specific handler to unbind
|
|
371
|
|
- */
|
|
372
|
|
-JitsiTrack.prototype.off = function(eventId, handler) {
|
|
373
|
|
- if (this.eventEmitter) {
|
|
374
|
|
- this.eventEmitter.removeListener(eventId, handler);
|
|
375
|
|
- }
|
|
376
|
|
-};
|
|
|
348
|
+ /**
|
|
|
349
|
+ * Checks whether the MediaStream is active/not ended.
|
|
|
350
|
+ * When there is no check for active we don't have information and so
|
|
|
351
|
+ * will return that stream is active (in case of FF).
|
|
|
352
|
+ * @returns {boolean} whether MediaStream is active.
|
|
|
353
|
+ */
|
|
|
354
|
+ isActive() {
|
|
|
355
|
+ if (typeof this.stream.active !== 'undefined') {
|
|
|
356
|
+ return this.stream.active;
|
|
|
357
|
+ }
|
|
377
|
358
|
|
|
378
|
|
-// Common aliases for event emitter
|
|
379
|
|
-JitsiTrack.prototype.addEventListener = JitsiTrack.prototype.on;
|
|
380
|
|
-JitsiTrack.prototype.removeEventListener = JitsiTrack.prototype.off;
|
|
|
359
|
+ return true;
|
|
|
360
|
+ }
|
|
381
|
361
|
|
|
382
|
|
-/**
|
|
383
|
|
- * Sets the audio level for the stream
|
|
384
|
|
- * @param {number} audioLevel value between 0 and 1
|
|
385
|
|
- * @param {TraceablePeerConnection} [tpc] the peerconnection instance which
|
|
386
|
|
- * is source for the audio level. It can be <tt>undefined</tt> for
|
|
387
|
|
- * a local track if the audio level was measured outside of the peerconnection
|
|
388
|
|
- * (see /modules/statistics/LocalStatsCollector.js).
|
|
389
|
|
- */
|
|
390
|
|
-JitsiTrack.prototype.setAudioLevel = function(audioLevel, tpc) {
|
|
391
|
|
- if (this.audioLevel !== audioLevel) {
|
|
392
|
|
- this.audioLevel = audioLevel;
|
|
393
|
|
- this.eventEmitter.emit(
|
|
394
|
|
- JitsiTrackEvents.TRACK_AUDIO_LEVEL_CHANGED,
|
|
395
|
|
- audioLevel,
|
|
396
|
|
- tpc);
|
|
|
362
|
+ /**
|
|
|
363
|
+ * Sets the audio level for the stream
|
|
|
364
|
+ * @param {number} audioLevel value between 0 and 1
|
|
|
365
|
+ * @param {TraceablePeerConnection} [tpc] the peerconnection instance which
|
|
|
366
|
+ * is source for the audio level. It can be <tt>undefined</tt> for
|
|
|
367
|
+ * a local track if the audio level was measured outside of the
|
|
|
368
|
+ * peerconnection (see /modules/statistics/LocalStatsCollector.js).
|
|
|
369
|
+ */
|
|
|
370
|
+ setAudioLevel(audioLevel, tpc) {
|
|
|
371
|
+ if (this.audioLevel !== audioLevel) {
|
|
|
372
|
+ this.audioLevel = audioLevel;
|
|
|
373
|
+ this.emit(
|
|
|
374
|
+ JitsiTrackEvents.TRACK_AUDIO_LEVEL_CHANGED,
|
|
|
375
|
+ audioLevel,
|
|
|
376
|
+ tpc);
|
|
|
377
|
+ }
|
|
397
|
378
|
}
|
|
398
|
|
-};
|
|
399
|
379
|
|
|
400
|
|
-/**
|
|
401
|
|
- * Returns the msid of the stream attached to the JitsiTrack object or null if
|
|
402
|
|
- * no stream is attached.
|
|
403
|
|
- */
|
|
404
|
|
-JitsiTrack.prototype.getMSID = function() {
|
|
405
|
|
- const streamId = this.getStreamId();
|
|
406
|
|
- const trackId = this.getTrackId();
|
|
|
380
|
+ /**
|
|
|
381
|
+ * Returns the msid of the stream attached to the JitsiTrack object or null
|
|
|
382
|
+ * if no stream is attached.
|
|
|
383
|
+ */
|
|
|
384
|
+ getMSID() {
|
|
|
385
|
+ const streamId = this.getStreamId();
|
|
|
386
|
+ const trackId = this.getTrackId();
|
|
407
|
387
|
|
|
408
|
388
|
|
|
409
|
|
- return streamId && trackId ? `${streamId} ${trackId}` : null;
|
|
410
|
|
-};
|
|
|
389
|
+ return streamId && trackId ? `${streamId} ${trackId}` : null;
|
|
|
390
|
+ }
|
|
411
|
391
|
|
|
412
|
|
-/**
|
|
413
|
|
- * Sets new audio output device for track's DOM elements. Video tracks are
|
|
414
|
|
- * ignored.
|
|
415
|
|
- * @param {string} audioOutputDeviceId - id of 'audiooutput' device from
|
|
416
|
|
- * navigator.mediaDevices.enumerateDevices(), '' for default device
|
|
417
|
|
- * @emits JitsiTrackEvents.TRACK_AUDIO_OUTPUT_CHANGED
|
|
418
|
|
- * @returns {Promise}
|
|
419
|
|
- */
|
|
420
|
|
-JitsiTrack.prototype.setAudioOutput = function(audioOutputDeviceId) {
|
|
421
|
|
- const self = this;
|
|
|
392
|
+ /**
|
|
|
393
|
+ * Sets new audio output device for track's DOM elements. Video tracks are
|
|
|
394
|
+ * ignored.
|
|
|
395
|
+ * @param {string} audioOutputDeviceId - id of 'audiooutput' device from
|
|
|
396
|
+ * navigator.mediaDevices.enumerateDevices(), '' for default device
|
|
|
397
|
+ * @emits JitsiTrackEvents.TRACK_AUDIO_OUTPUT_CHANGED
|
|
|
398
|
+ * @returns {Promise}
|
|
|
399
|
+ */
|
|
|
400
|
+ setAudioOutput(audioOutputDeviceId) {
|
|
|
401
|
+ if (!RTCUtils.isDeviceChangeAvailable('output')) {
|
|
|
402
|
+ return Promise.reject(
|
|
|
403
|
+ new Error('Audio output device change is not supported'));
|
|
|
404
|
+ }
|
|
422
|
405
|
|
|
423
|
|
- if (!RTCUtils.isDeviceChangeAvailable('output')) {
|
|
424
|
|
- return Promise.reject(
|
|
425
|
|
- new Error('Audio output device change is not supported'));
|
|
426
|
|
- }
|
|
|
406
|
+ // All audio communication is done through audio tracks, so ignore
|
|
|
407
|
+ // changing audio output for video tracks at all.
|
|
|
408
|
+ if (this.isVideoTrack()) {
|
|
|
409
|
+ return Promise.resolve();
|
|
|
410
|
+ }
|
|
427
|
411
|
|
|
428
|
|
- // All audio communication is done through audio tracks, so ignore changing
|
|
429
|
|
- // audio output for video tracks at all.
|
|
430
|
|
- if (this.isVideoTrack()) {
|
|
431
|
|
- return Promise.resolve();
|
|
|
412
|
+ return (
|
|
|
413
|
+ Promise.all(
|
|
|
414
|
+ this.containers.map(
|
|
|
415
|
+ element =>
|
|
|
416
|
+ element.setSinkId(audioOutputDeviceId)
|
|
|
417
|
+ .catch(error => {
|
|
|
418
|
+ logger.warn(
|
|
|
419
|
+ 'Failed to change audio output device'
|
|
|
420
|
+ + ' on element. Default or'
|
|
|
421
|
+ + ' previously set audio output'
|
|
|
422
|
+ + ' device will be used.',
|
|
|
423
|
+ element,
|
|
|
424
|
+ error);
|
|
|
425
|
+ throw error;
|
|
|
426
|
+ })))
|
|
|
427
|
+ .then(() => {
|
|
|
428
|
+ this.emit(
|
|
|
429
|
+ JitsiTrackEvents.TRACK_AUDIO_OUTPUT_CHANGED,
|
|
|
430
|
+ audioOutputDeviceId);
|
|
|
431
|
+ }));
|
|
432
|
432
|
}
|
|
433
|
|
-
|
|
434
|
|
- return (
|
|
435
|
|
- Promise.all(
|
|
436
|
|
- this.containers.map(
|
|
437
|
|
- element =>
|
|
438
|
|
- element.setSinkId(audioOutputDeviceId)
|
|
439
|
|
- .catch(error => {
|
|
440
|
|
- logger.warn(
|
|
441
|
|
- 'Failed to change audio output device on'
|
|
442
|
|
- + ' element. Default or previously set'
|
|
443
|
|
- + ' audio output device will be used.',
|
|
444
|
|
- element,
|
|
445
|
|
- error);
|
|
446
|
|
- throw error;
|
|
447
|
|
- })))
|
|
448
|
|
- .then(() => {
|
|
449
|
|
- self.eventEmitter.emit(
|
|
450
|
|
- JitsiTrackEvents.TRACK_AUDIO_OUTPUT_CHANGED,
|
|
451
|
|
- audioOutputDeviceId);
|
|
452
|
|
- }));
|
|
453
|
|
-};
|
|
|
433
|
+}
|