|
@@ -9,6 +9,15 @@ const RTCEvents = require('../../service/RTC/RTCEvents');
|
9
|
9
|
let ttfmTrackerAudioAttached = false;
|
10
|
10
|
let ttfmTrackerVideoAttached = false;
|
11
|
11
|
|
|
12
|
+/**
|
|
13
|
+ * List of container events that we are going to process. _onContainerEventHandler will be added as listener to the
|
|
14
|
+ * container for every event in the list.
|
|
15
|
+ */
|
|
16
|
+const containerEvents = [
|
|
17
|
+ 'abort', 'canplay', 'canplaythrough', 'emptied', 'ended', 'error', 'loadeddata', 'loadedmetadata', 'loadstart',
|
|
18
|
+ 'pause', 'play', 'playing', 'ratechange', 'stalled', 'suspend', 'waiting'
|
|
19
|
+];
|
|
20
|
+
|
12
|
21
|
/* eslint-disable max-params */
|
13
|
22
|
|
14
|
23
|
/**
|
|
@@ -64,6 +73,8 @@ export default class JitsiRemoteTrack extends JitsiTrack {
|
64
|
73
|
this.muted = muted;
|
65
|
74
|
this.isP2P = isP2P;
|
66
|
75
|
|
|
76
|
+ logger.debug(`New remote track added: ${this}`);
|
|
77
|
+
|
67
|
78
|
// we want to mark whether the track has been ever muted
|
68
|
79
|
// to detect ttfm events for startmuted conferences, as it can
|
69
|
80
|
// significantly increase ttfm values
|
|
@@ -71,19 +82,26 @@ export default class JitsiRemoteTrack extends JitsiTrack {
|
71
|
82
|
|
72
|
83
|
// Bind 'onmute' and 'onunmute' event handlers
|
73
|
84
|
if (this.rtc && this.track) {
|
74
|
|
- this._bindMuteHandlers();
|
|
85
|
+ this._bindTrackHandlers();
|
75
|
86
|
}
|
|
87
|
+ this._containerHandlers = {};
|
|
88
|
+ containerEvents.forEach(event => {
|
|
89
|
+ this._containerHandlers[event] = this._containerEventHandler.bind(this, event);
|
|
90
|
+ });
|
76
|
91
|
}
|
77
|
92
|
|
78
|
93
|
/* eslint-enable max-params */
|
79
|
94
|
/**
|
80
|
|
- * Attaches the track muted handlers.
|
|
95
|
+ * Attaches the track handlers.
|
81
|
96
|
*
|
82
|
97
|
* @returns {void}
|
83
|
98
|
*/
|
84
|
|
- _bindMuteHandlers() {
|
|
99
|
+ _bindTrackHandlers() {
|
85
|
100
|
this.track.addEventListener('mute', () => this._onTrackMute());
|
86
|
101
|
this.track.addEventListener('unmute', () => this._onTrackUnmute());
|
|
102
|
+ this.track.addEventListener('ended', () => {
|
|
103
|
+ logger.debug(`"onended" event(${Date.now()}): ${this}`);
|
|
104
|
+ });
|
87
|
105
|
}
|
88
|
106
|
|
89
|
107
|
/**
|
|
@@ -94,9 +112,7 @@ export default class JitsiRemoteTrack extends JitsiTrack {
|
94
|
112
|
* @returns {void}
|
95
|
113
|
*/
|
96
|
114
|
_onTrackMute() {
|
97
|
|
- logger.debug(
|
98
|
|
- `"onmute" event(${Date.now()}): `,
|
99
|
|
- this.getParticipantId(), this.getType(), this.getSSRC());
|
|
115
|
+ logger.debug(`"onmute" event(${Date.now()}): ${this}`);
|
100
|
116
|
|
101
|
117
|
this.rtc.eventEmitter.emit(RTCEvents.REMOTE_TRACK_MUTE, this);
|
102
|
118
|
}
|
|
@@ -109,9 +125,7 @@ export default class JitsiRemoteTrack extends JitsiTrack {
|
109
|
125
|
* @returns {void}
|
110
|
126
|
*/
|
111
|
127
|
_onTrackUnmute() {
|
112
|
|
- logger.debug(
|
113
|
|
- `"onunmute" event(${Date.now()}): `,
|
114
|
|
- this.getParticipantId(), this.getType(), this.getSSRC());
|
|
128
|
+ logger.debug(`"onunmute" event(${Date.now()}): ${this}`);
|
115
|
129
|
|
116
|
130
|
this.rtc.eventEmitter.emit(RTCEvents.REMOTE_TRACK_UNMUTE, this);
|
117
|
131
|
}
|
|
@@ -248,14 +262,62 @@ export default class JitsiRemoteTrack extends JitsiTrack {
|
248
|
262
|
container.addEventListener('canplay', this._playCallback.bind(this));
|
249
|
263
|
}
|
250
|
264
|
|
|
265
|
+ /**
|
|
266
|
+ * Called when the track has been attached to a new container.
|
|
267
|
+ *
|
|
268
|
+ * @param {HTMLElement} container the HTML container which can be 'video' or
|
|
269
|
+ * 'audio' element.
|
|
270
|
+ * @private
|
|
271
|
+ */
|
|
272
|
+ _onTrackAttach(container) {
|
|
273
|
+ logger.debug(`Track has been attached to a container: ${this}`);
|
|
274
|
+
|
|
275
|
+ containerEvents.forEach(event => {
|
|
276
|
+ container.addEventListener(event, this._containerHandlers[event]);
|
|
277
|
+ });
|
|
278
|
+ }
|
|
279
|
+
|
|
280
|
+ /**
|
|
281
|
+ * Called when the track has been detached from a container.
|
|
282
|
+ *
|
|
283
|
+ * @param {HTMLElement} container the HTML container which can be 'video' or
|
|
284
|
+ * 'audio' element.
|
|
285
|
+ * @private
|
|
286
|
+ */
|
|
287
|
+ _onTrackDetach(container) {
|
|
288
|
+ logger.debug(`Track has been detached from a container: ${this}`);
|
|
289
|
+
|
|
290
|
+ containerEvents.forEach(event => {
|
|
291
|
+ container.removeEventListener(event, this._containerHandlers[event]);
|
|
292
|
+ });
|
|
293
|
+ }
|
|
294
|
+
|
|
295
|
+ /**
|
|
296
|
+ * An event handler for events triggered by the attached container.
|
|
297
|
+ *
|
|
298
|
+ * @param {string} type - The type of the event.
|
|
299
|
+ */
|
|
300
|
+ _containerEventHandler(type) {
|
|
301
|
+ logger.debug(`${type} handler was called for a container with attached ${this}`);
|
|
302
|
+ }
|
|
303
|
+
|
|
304
|
+ /**
|
|
305
|
+ * Returns a string with a description of the current status of the track.
|
|
306
|
+ *
|
|
307
|
+ * @returns {string}
|
|
308
|
+ */
|
|
309
|
+ _getStatus() {
|
|
310
|
+ const { enabled, muted, readyState } = this.track;
|
|
311
|
+
|
|
312
|
+ return `readyState: ${readyState}, muted: ${muted}, enabled: ${enabled}`;
|
|
313
|
+ }
|
|
314
|
+
|
251
|
315
|
/**
|
252
|
316
|
* Creates a text representation of this remote track instance.
|
253
|
317
|
* @return {string}
|
254
|
318
|
*/
|
255
|
319
|
toString() {
|
256
|
|
- return `RemoteTrack[${
|
257
|
|
- this.ownerEndpointId}, ${
|
258
|
|
- this.getType()}, p2p: ${
|
259
|
|
- this.isP2P}]`;
|
|
320
|
+ return `RemoteTrack[userID: ${this.getParticipantId()}, type: ${this.getType()}, ssrc: ${
|
|
321
|
+ this.getSSRC()}, p2p: ${this.isP2P}, status: ${this._getStatus()}]`;
|
260
|
322
|
}
|
261
|
323
|
}
|