|
@@ -6,6 +6,7 @@ import * as SignalingEvents from '../../service/RTC/SignalingEvents';
|
6
|
6
|
import SignalingLayer, { getMediaTypeFromSourceName } from '../../service/RTC/SignalingLayer';
|
7
|
7
|
import { VideoType } from '../../service/RTC/VideoType';
|
8
|
8
|
import { XMPPEvents } from '../../service/xmpp/XMPPEvents';
|
|
9
|
+import FeatureFlags from '../flags/FeatureFlags';
|
9
|
10
|
|
10
|
11
|
import { filterNodeFromPresenceJSON } from './ChatRoom';
|
11
|
12
|
|
|
@@ -79,45 +80,6 @@ export default class SignalingLayerImpl extends SignalingLayer {
|
79
|
80
|
return false;
|
80
|
81
|
}
|
81
|
82
|
|
82
|
|
- /**
|
83
|
|
- * Check is given endpoint has advertised <SourceInfo/> in it's presence which means that the source name signaling
|
84
|
|
- * is used by this endpoint.
|
85
|
|
- *
|
86
|
|
- * @param {EndpointId} endpointId
|
87
|
|
- * @returns {boolean}
|
88
|
|
- */
|
89
|
|
- _doesEndpointSendNewSourceInfo(endpointId) {
|
90
|
|
- const presence = this.chatRoom?.getLastPresence(endpointId);
|
91
|
|
-
|
92
|
|
- return Boolean(presence && presence.find(node => node.tagName === SOURCE_INFO_PRESENCE_ELEMENT));
|
93
|
|
- }
|
94
|
|
-
|
95
|
|
- /**
|
96
|
|
- * Sets the <tt>ChatRoom</tt> instance used and binds presence listeners.
|
97
|
|
- * @param {ChatRoom} room
|
98
|
|
- */
|
99
|
|
- setChatRoom(room) {
|
100
|
|
- const oldChatRoom = this.chatRoom;
|
101
|
|
-
|
102
|
|
- this.chatRoom = room;
|
103
|
|
- if (oldChatRoom) {
|
104
|
|
- oldChatRoom.removePresenceListener(
|
105
|
|
- 'audiomuted', this._audioMuteHandler);
|
106
|
|
- oldChatRoom.removePresenceListener(
|
107
|
|
- 'videomuted', this._videoMuteHandler);
|
108
|
|
- oldChatRoom.removePresenceListener(
|
109
|
|
- 'videoType', this._videoTypeHandler);
|
110
|
|
- this._sourceInfoHandler
|
111
|
|
- && oldChatRoom.removePresenceListener(SOURCE_INFO_PRESENCE_ELEMENT, this._sourceInfoHandler);
|
112
|
|
- this._memberLeftHandler
|
113
|
|
- && oldChatRoom.removeEventListener(XMPPEvents.MUC_MEMBER_LEFT, this._memberLeftHandler);
|
114
|
|
- }
|
115
|
|
- if (room) {
|
116
|
|
- this._bindChatRoomEventHandlers(room);
|
117
|
|
- this._addLocalSourceInfoToPresence();
|
118
|
|
- }
|
119
|
|
- }
|
120
|
|
-
|
121
|
83
|
/**
|
122
|
84
|
* Binds event listeners to the chat room instance.
|
123
|
85
|
* @param {ChatRoom} room
|
|
@@ -235,28 +197,31 @@ export default class SignalingLayerImpl extends SignalingLayer {
|
235
|
197
|
}
|
236
|
198
|
|
237
|
199
|
/**
|
238
|
|
- * Finds the first source of given media type for the given endpoint.
|
239
|
|
- * @param endpointId
|
240
|
|
- * @param mediaType
|
241
|
|
- * @returns {SourceInfo|null}
|
242
|
|
- * @private
|
|
200
|
+ * Check is given endpoint has advertised <SourceInfo/> in it's presence which means that the source name signaling
|
|
201
|
+ * is used by this endpoint.
|
|
202
|
+ *
|
|
203
|
+ * @param {EndpointId} endpointId
|
|
204
|
+ * @returns {boolean}
|
243
|
205
|
*/
|
244
|
|
- _findEndpointSourceInfoForMediaType(endpointId, mediaType) {
|
245
|
|
- const remoteSourceState = this._remoteSourceState[endpointId];
|
246
|
|
-
|
247
|
|
- if (!remoteSourceState) {
|
248
|
|
- return null;
|
249
|
|
- }
|
|
206
|
+ _doesEndpointSendNewSourceInfo(endpointId) {
|
|
207
|
+ const presence = this.chatRoom?.getLastPresence(endpointId);
|
250
|
208
|
|
251
|
|
- for (const sourceInfo of Object.values(remoteSourceState)) {
|
252
|
|
- const _mediaType = getMediaTypeFromSourceName(sourceInfo.sourceName);
|
|
209
|
+ return Boolean(presence && presence.find(node => node.tagName === SOURCE_INFO_PRESENCE_ELEMENT));
|
|
210
|
+ }
|
253
|
211
|
|
254
|
|
- if (_mediaType === mediaType) {
|
255
|
|
- return sourceInfo;
|
256
|
|
- }
|
|
212
|
+ /**
|
|
213
|
+ * Logs a debug or error message to console depending on whether SSRC rewriting is enabled or not.
|
|
214
|
+ * Owner changes are permitted only when SSRC rewriting is enabled.
|
|
215
|
+ *
|
|
216
|
+ * @param {string} message - The message to be logged.
|
|
217
|
+ * @returns {void}
|
|
218
|
+ */
|
|
219
|
+ _logOwnerChangedMessage(message) {
|
|
220
|
+ if (FeatureFlags.isSsrcRewritingSupported()) {
|
|
221
|
+ logger.debug(message);
|
|
222
|
+ } else {
|
|
223
|
+ logger.error(message);
|
257
|
224
|
}
|
258
|
|
-
|
259
|
|
- return null;
|
260
|
225
|
}
|
261
|
226
|
|
262
|
227
|
/**
|
|
@@ -322,6 +287,52 @@ export default class SignalingLayerImpl extends SignalingLayer {
|
322
|
287
|
return this.ssrcOwners.get(ssrc);
|
323
|
288
|
}
|
324
|
289
|
|
|
290
|
+ /**
|
|
291
|
+ * @inheritDoc
|
|
292
|
+ */
|
|
293
|
+ getTrackSourceName(ssrc) {
|
|
294
|
+ return this._sourceNames.get(ssrc);
|
|
295
|
+ }
|
|
296
|
+
|
|
297
|
+ /**
|
|
298
|
+ * @inheritDoc
|
|
299
|
+ */
|
|
300
|
+ removeSSRCOwners(ssrcList) {
|
|
301
|
+ if (!ssrcList?.length) {
|
|
302
|
+ return;
|
|
303
|
+ }
|
|
304
|
+
|
|
305
|
+ for (const ssrc of ssrcList) {
|
|
306
|
+ this.ssrcOwners.delete(ssrc);
|
|
307
|
+ }
|
|
308
|
+ }
|
|
309
|
+
|
|
310
|
+ /**
|
|
311
|
+ * Sets the <tt>ChatRoom</tt> instance used and binds presence listeners.
|
|
312
|
+ * @param {ChatRoom} room
|
|
313
|
+ */
|
|
314
|
+ setChatRoom(room) {
|
|
315
|
+ const oldChatRoom = this.chatRoom;
|
|
316
|
+
|
|
317
|
+ this.chatRoom = room;
|
|
318
|
+ if (oldChatRoom) {
|
|
319
|
+ oldChatRoom.removePresenceListener(
|
|
320
|
+ 'audiomuted', this._audioMuteHandler);
|
|
321
|
+ oldChatRoom.removePresenceListener(
|
|
322
|
+ 'videomuted', this._videoMuteHandler);
|
|
323
|
+ oldChatRoom.removePresenceListener(
|
|
324
|
+ 'videoType', this._videoTypeHandler);
|
|
325
|
+ this._sourceInfoHandler
|
|
326
|
+ && oldChatRoom.removePresenceListener(SOURCE_INFO_PRESENCE_ELEMENT, this._sourceInfoHandler);
|
|
327
|
+ this._memberLeftHandler
|
|
328
|
+ && oldChatRoom.removeEventListener(XMPPEvents.MUC_MEMBER_LEFT, this._memberLeftHandler);
|
|
329
|
+ }
|
|
330
|
+ if (room) {
|
|
331
|
+ this._bindChatRoomEventHandlers(room);
|
|
332
|
+ this._addLocalSourceInfoToPresence();
|
|
333
|
+ }
|
|
334
|
+ }
|
|
335
|
+
|
325
|
336
|
/**
|
326
|
337
|
* @inheritDoc
|
327
|
338
|
*/
|
|
@@ -335,7 +346,7 @@ export default class SignalingLayerImpl extends SignalingLayer {
|
335
|
346
|
const existingOwner = this.ssrcOwners.get(ssrc);
|
336
|
347
|
|
337
|
348
|
if (existingOwner && existingOwner !== endpointId) {
|
338
|
|
- logger.error(`SSRC owner re-assigned from ${existingOwner} to ${endpointId}`);
|
|
349
|
+ this._logOwnerChangedMessage(`SSRC owner re-assigned from ${existingOwner} to ${endpointId}`);
|
339
|
350
|
}
|
340
|
351
|
this.ssrcOwners.set(ssrc, endpointId);
|
341
|
352
|
}
|
|
@@ -357,6 +368,25 @@ export default class SignalingLayerImpl extends SignalingLayer {
|
357
|
368
|
return false;
|
358
|
369
|
}
|
359
|
370
|
|
|
371
|
+ /**
|
|
372
|
+ * @inheritDoc
|
|
373
|
+ */
|
|
374
|
+ setTrackSourceName(ssrc, sourceName) {
|
|
375
|
+ if (typeof ssrc !== 'number') {
|
|
376
|
+ throw new TypeError(`SSRC(${ssrc}) must be a number`);
|
|
377
|
+ }
|
|
378
|
+
|
|
379
|
+ // Now signaling layer instance is shared between different JingleSessionPC instances, so although very unlikely
|
|
380
|
+ // an SSRC conflict could potentially occur. Log a message to make debugging easier.
|
|
381
|
+ const existingName = this._sourceNames.get(ssrc);
|
|
382
|
+
|
|
383
|
+ if (existingName && existingName !== sourceName) {
|
|
384
|
+ this._logOwnerChangedMessage(`SSRC(${ssrc}) sourceName re-assigned from ${existingName} to ${sourceName}`);
|
|
385
|
+ }
|
|
386
|
+
|
|
387
|
+ this._sourceNames.set(ssrc, sourceName);
|
|
388
|
+ }
|
|
389
|
+
|
360
|
390
|
/**
|
361
|
391
|
* @inheritDoc
|
362
|
392
|
*/
|
|
@@ -378,27 +408,16 @@ export default class SignalingLayerImpl extends SignalingLayer {
|
378
|
408
|
/**
|
379
|
409
|
* @inheritDoc
|
380
|
410
|
*/
|
381
|
|
- getTrackSourceName(ssrc) {
|
382
|
|
- return this._sourceNames.get(ssrc);
|
383
|
|
- }
|
384
|
|
-
|
385
|
|
- /**
|
386
|
|
- * @inheritDoc
|
387
|
|
- */
|
388
|
|
- setTrackSourceName(ssrc, sourceName) {
|
389
|
|
- if (typeof ssrc !== 'number') {
|
390
|
|
- throw new TypeError(`SSRC(${ssrc}) must be a number`);
|
391
|
|
- }
|
392
|
|
-
|
393
|
|
- // Now signaling layer instance is shared between different JingleSessionPC instances, so although very unlikely
|
394
|
|
- // an SSRC conflict could potentially occur. Log a message to make debugging easier.
|
395
|
|
- const existingName = this._sourceNames.get(ssrc);
|
|
411
|
+ updateSsrcOwnersOnLeave(id) {
|
|
412
|
+ const ssrcs = Array.from(this.ssrcOwners)
|
|
413
|
+ .filter(entry => entry[1] === id)
|
|
414
|
+ .map(entry => entry[0]);
|
396
|
415
|
|
397
|
|
- if (existingName && existingName !== sourceName) {
|
398
|
|
- logger.error(`SSRC(${ssrc}) sourceName re-assigned from ${existingName} to ${sourceName}`);
|
|
416
|
+ if (!ssrcs?.length) {
|
|
417
|
+ return;
|
399
|
418
|
}
|
400
|
419
|
|
401
|
|
- this._sourceNames.set(ssrc, sourceName);
|
|
420
|
+ this.removeSSRCOwners(ssrcs);
|
402
|
421
|
}
|
403
|
422
|
|
404
|
423
|
}
|