Ver código fonte

fix(signaling): Merge ssrcOwners and _sourceName.

Additional benefits are:
 - ssrc -> source name will be updated on ssrc remap message from
 the bridge.
 - the map will be correctly cleaned when member leave (this logic was
 not working well for _sourceName map)
 - Looks cleaner and simpler.
release-8443
Hristo Terezov 2 anos atrás
pai
commit
3d55666c0f

+ 0
- 6
modules/proxyconnection/CustomSignalingLayer.js Ver arquivo

@@ -108,12 +108,6 @@ export default class CustomSignalingLayer extends SignalingLayer {
108 108
         return false;
109 109
     }
110 110
 
111
-    /**
112
-     * @inheritDoc
113
-     */
114
-    setTrackSourceName(ssrc, sourceName) { // eslint-disable-line no-unused-vars
115
-    }
116
-
117 111
     /**
118 112
      * @inheritDoc
119 113
      */

+ 5
- 6
modules/xmpp/JingleSessionPC.js Ver arquivo

@@ -926,16 +926,15 @@ export default class JingleSessionPC extends JingleSession {
926 926
 
927 927
         ssrcs.each((i, ssrcElement) => {
928 928
             const ssrc = Number(ssrcElement.getAttribute('ssrc'));
929
+            let sourceName;
929 930
 
930 931
             if (ssrcElement.hasAttribute('name')) {
931
-                const sourceName = ssrcElement.getAttribute('name');
932
-
933
-                this._signalingLayer.setTrackSourceName(ssrc, sourceName);
932
+                sourceName = ssrcElement.getAttribute('name');
934 933
             }
935 934
 
936 935
             if (this.isP2P) {
937 936
                 // In P2P all SSRCs are owner by the remote peer
938
-                this._signalingLayer.setSSRCOwner(ssrc, Strophe.getResourceFromJid(this.remoteJid));
937
+                this._signalingLayer.setSSRCOwner(ssrc, Strophe.getResourceFromJid(this.remoteJid), sourceName);
939 938
             } else {
940 939
                 $(ssrcElement)
941 940
                     .find('>ssrc-info[xmlns="http://jitsi.org/jitmeet"]')
@@ -946,7 +945,7 @@ export default class JingleSessionPC extends JingleSession {
946 945
                             if (isNaN(ssrc) || ssrc < 0) {
947 946
                                 logger.warn(`${this} Invalid SSRC ${ssrc} value received for ${owner}`);
948 947
                             } else {
949
-                                this._signalingLayer.setSSRCOwner(ssrc, getEndpointId(owner));
948
+                                this._signalingLayer.setSSRCOwner(ssrc, getEndpointId(owner), sourceName);
950 949
                             }
951 950
                         }
952 951
                     });
@@ -1804,7 +1803,7 @@ export default class JingleSessionPC extends JingleSession {
1804 1803
                 logger.debug(`Existing SSRC ${ssrc}: new owner=${owner}, source-name=${source}`);
1805 1804
 
1806 1805
                 // Update the SSRC owner.
1807
-                this._signalingLayer.setSSRCOwner(ssrc, owner);
1806
+                this._signalingLayer.setSSRCOwner(ssrc, owner, source);
1808 1807
 
1809 1808
                 // Update the track with all the relevant info.
1810 1809
                 track.setSourceName(source);

+ 24
- 48
modules/xmpp/SignalingLayerImpl.js Ver arquivo

@@ -27,12 +27,10 @@ export default class SignalingLayerImpl extends SignalingLayer {
27 27
         super();
28 28
 
29 29
         /**
30
-         * A map that stores SSRCs of remote streams. And is used only locally
31
-         * We store the mapping when jingle is received, and later is used
32
-         * onaddstream webrtc event where we have only the ssrc
30
+         * A map that stores SSRCs of remote streams and the corresponding jid and source name.
33 31
          * FIXME: This map got filled and never cleaned and can grow during long
34 32
          * conference
35
-         * @type {Map<number, string>} maps SSRC number to jid
33
+         * @type {Map<number, { endpointId: string, sourceName: string }>} maps SSRC number to jid and source name.
36 34
          */
37 35
         this.ssrcOwners = new Map();
38 36
 
@@ -53,16 +51,6 @@ export default class SignalingLayerImpl extends SignalingLayer {
53 51
          * @private
54 52
          */
55 53
         this._remoteSourceState = { };
56
-
57
-        /**
58
-         * A map that stores the source name of a track identified by it's ssrc.
59
-         * We store the mapping when jingle is received, and later is used
60
-         * onaddstream webrtc event where we have only the ssrc
61
-         * FIXME: This map got filled and never cleaned and can grow during long
62
-         * conference
63
-         * @type {Map<number, string>} maps SSRC number to source name
64
-         */
65
-        this._sourceNames = new Map();
66 54
     }
67 55
 
68 56
     /**
@@ -199,12 +187,6 @@ export default class SignalingLayerImpl extends SignalingLayer {
199 187
             const endpointId = Strophe.getResourceFromJid(jid);
200 188
 
201 189
             delete this._remoteSourceState[endpointId];
202
-
203
-            for (const [ key, value ] of this.ssrcOwners.entries()) {
204
-                if (value === endpointId) {
205
-                    delete this._sourceNames[key];
206
-                }
207
-            }
208 190
         };
209 191
         room.addEventListener(XMPPEvents.MUC_MEMBER_LEFT, this._memberLeftHandler);
210 192
     }
@@ -301,14 +283,14 @@ export default class SignalingLayerImpl extends SignalingLayer {
301 283
      * @inheritDoc
302 284
      */
303 285
     getSSRCOwner(ssrc) {
304
-        return this.ssrcOwners.get(ssrc);
286
+        return this.ssrcOwners.get(ssrc)?.endpointId;
305 287
     }
306 288
 
307 289
     /**
308 290
      * @inheritDoc
309 291
      */
310 292
     getTrackSourceName(ssrc) {
311
-        return this._sourceNames.get(ssrc);
293
+        return this.ssrcOwners.get(ssrc)?.sourceName;
312 294
     }
313 295
 
314 296
     /**
@@ -353,7 +335,7 @@ export default class SignalingLayerImpl extends SignalingLayer {
353 335
     /**
354 336
      * @inheritDoc
355 337
      */
356
-    setSSRCOwner(ssrc, endpointId) {
338
+    setSSRCOwner(ssrc, newEndpointId, newSourceName) {
357 339
         if (typeof ssrc !== 'number') {
358 340
             throw new TypeError(`SSRC(${ssrc}) must be a number`);
359 341
         }
@@ -362,10 +344,19 @@ export default class SignalingLayerImpl extends SignalingLayer {
362 344
         // an SSRC conflict could potentially occur. Log a message to make debugging easier.
363 345
         const existingOwner = this.ssrcOwners.get(ssrc);
364 346
 
365
-        if (existingOwner && existingOwner !== endpointId) {
366
-            this._logOwnerChangedMessage(`SSRC owner re-assigned from ${existingOwner} to ${endpointId}`);
347
+        if (existingOwner) {
348
+            const { endpointId, sourceName } = existingOwner;
349
+
350
+            if (endpointId !== newEndpointId || sourceName !== newSourceName) {
351
+                this._logOwnerChangedMessage(
352
+                    `SSRC owner re-assigned from ${existingOwner}(source-name=${sourceName}) to ${
353
+                        newEndpointId}(source-name=${newSourceName})`);
354
+            }
367 355
         }
368
-        this.ssrcOwners.set(ssrc, endpointId);
356
+        this.ssrcOwners.set(ssrc, {
357
+            endpointId: newEndpointId,
358
+            sourceName: newSourceName
359
+        });
369 360
     }
370 361
 
371 362
     /**
@@ -386,25 +377,6 @@ export default class SignalingLayerImpl extends SignalingLayer {
386 377
         return false;
387 378
     }
388 379
 
389
-    /**
390
-     * @inheritDoc
391
-     */
392
-    setTrackSourceName(ssrc, sourceName) {
393
-        if (typeof ssrc !== 'number') {
394
-            throw new TypeError(`SSRC(${ssrc}) must be a number`);
395
-        }
396
-
397
-        // Now signaling layer instance is shared between different JingleSessionPC instances, so although very unlikely
398
-        // an SSRC conflict could potentially occur. Log a message to make debugging easier.
399
-        const existingName = this._sourceNames.get(ssrc);
400
-
401
-        if (existingName && existingName !== sourceName) {
402
-            this._logOwnerChangedMessage(`SSRC(${ssrc}) sourceName re-assigned from ${existingName} to ${sourceName}`);
403
-        }
404
-
405
-        this._sourceNames.set(ssrc, sourceName);
406
-    }
407
-
408 380
     /**
409 381
      * @inheritDoc
410 382
      */
@@ -427,9 +399,13 @@ export default class SignalingLayerImpl extends SignalingLayer {
427 399
      * @inheritDoc
428 400
      */
429 401
     updateSsrcOwnersOnLeave(id) {
430
-        const ssrcs = Array.from(this.ssrcOwners)
431
-            .filter(entry => entry[1] === id)
432
-            .map(entry => entry[0]);
402
+        const ssrcs = [];
403
+
404
+        this.ssrcOwners.forEach(({ endpointId }, ssrc) => {
405
+            if (endpointId === id) {
406
+                ssrcs.push(ssrc);
407
+            }
408
+        });
433 409
 
434 410
         if (!ssrcs?.length) {
435 411
             return;

+ 6
- 13
service/RTC/SignalingLayer.js Ver arquivo

@@ -144,11 +144,13 @@ export default class SignalingLayer extends Listenable {
144 144
 
145 145
     /**
146 146
      * Set an SSRC owner.
147
-     * @param {number} ssrc an SSRC to be owned
148
-     * @param {string} endpointId owner's ID (MUC nickname)
149
-     * @throws TypeError if <tt>ssrc</tt> is not a number
147
+     *
148
+     * @param {number} ssrc - An SSRC to be owned.
149
+     * @param {string} endpointId - Owner's ID (MUC nickname).
150
+     * @param {string} sourceName - The related source name.
151
+     * @throws TypeError if <tt>ssrc</tt> is not a number.
150 152
      */
151
-    setSSRCOwner(ssrc, endpointId) { // eslint-disable-line no-unused-vars
153
+    setSSRCOwner(ssrc, endpointId, sourceName) { // eslint-disable-line no-unused-vars
152 154
     }
153 155
 
154 156
     /**
@@ -161,15 +163,6 @@ export default class SignalingLayer extends Listenable {
161 163
     setTrackMuteStatus(sourceName, muted) { // eslint-disable-line no-unused-vars
162 164
     }
163 165
 
164
-    /**
165
-     * Saves the source name for a track identified by it's ssrc.
166
-     * @param {number} ssrc the ssrc of the target track.
167
-     * @param {SourceName} sourceName the track's source name to save.
168
-     * @throws TypeError if <tt>ssrc</tt> is not a number
169
-     */
170
-    setTrackSourceName(ssrc, sourceName) { // eslint-disable-line no-unused-vars
171
-    }
172
-
173 166
     /**
174 167
      * Sets track's video type.
175 168
      * @param {SourceName} sourceName - the track's source name.

Carregando…
Cancelar
Salvar