Bladeren bron

fix: Drop caps handling (#1495)

* feat: Drops unused code about handling incoming caps changes.

* fix: Drop using private fields outside JitsiParticipant.
dev1
Дамян Минков 4 jaren geleden
bovenliggende
commit
63aad7c0f8
No account linked to committer's email address
4 gewijzigde bestanden met toevoegingen van 37 en 131 verwijderingen
  1. 7
    7
      JitsiConference.js
  2. 1
    1
      JitsiConferenceEventManager.js
  3. 29
    33
      JitsiParticipant.js
  4. 0
    90
      modules/xmpp/Caps.js

+ 7
- 7
JitsiConference.js Bestand weergeven

@@ -1536,9 +1536,9 @@ JitsiConference.prototype.onMemberJoined = function(
1536 1536
     const participant
1537 1537
         = new JitsiParticipant(jid, this, nick, isHidden, statsID, status, identity);
1538 1538
 
1539
-    participant._role = role;
1540
-    participant._botType = botType;
1541
-    participant._features = features || new Set();
1539
+    participant.setRole(role);
1540
+    participant.setBotType(botType);
1541
+    participant.setFeatures(features);
1542 1542
 
1543 1543
     this.participants[id] = participant;
1544 1544
     this.eventEmitter.emit(
@@ -1606,7 +1606,7 @@ JitsiConference.prototype._onMemberBotTypeChanged = function(jid, botType) {
1606 1606
     const botParticipant = peers.find(p => p.getJid() === jid);
1607 1607
 
1608 1608
     if (botParticipant) {
1609
-        botParticipant._botType = botType;
1609
+        botParticipant.setBotType(botType);
1610 1610
         const id = Strophe.getResourceFromJid(jid);
1611 1611
 
1612 1612
         this.eventEmitter.emit(
@@ -1619,7 +1619,7 @@ JitsiConference.prototype._onMemberBotTypeChanged = function(jid, botType) {
1619 1619
     // poltergeist mode this is the moment when the poltergeist had exited and
1620 1620
     // the real participant had already replaced it.
1621 1621
     // In this case we can check and try p2p
1622
-    if (!botParticipant._botType) {
1622
+    if (!botParticipant.getBotType()) {
1623 1623
         this._maybeStartOrStopP2P();
1624 1624
     }
1625 1625
 };
@@ -1702,7 +1702,7 @@ JitsiConference.prototype.onUserRoleChanged = function(jid, role) {
1702 1702
     if (!participant) {
1703 1703
         return;
1704 1704
     }
1705
-    participant._role = role;
1705
+    participant.setRole(role);
1706 1706
     this.eventEmitter.emit(JitsiConferenceEvents.USER_ROLE_CHANGED, id, role);
1707 1707
 };
1708 1708
 
@@ -3194,7 +3194,7 @@ JitsiConference.prototype._maybeStartOrStopP2P = function(userLeftEvent) {
3194 3194
 JitsiConference.prototype._shouldBeInP2PMode = function() {
3195 3195
     const peers = this.getParticipants();
3196 3196
     const peerCount = peers.length;
3197
-    const hasBotPeer = peers.find(p => p._botType === 'poltergeist' || p._features.has(FEATURE_JIGASI)) !== undefined;
3197
+    const hasBotPeer = peers.find(p => p.getBotType() === 'poltergeist' || p.hasFeature(FEATURE_JIGASI)) !== undefined;
3198 3198
     const shouldBeInP2P = peerCount === 1 && !hasBotPeer;
3199 3199
 
3200 3200
     logger.debug(`P2P? peerCount: ${peerCount}, hasBotPeer: ${hasBotPeer} => ${shouldBeInP2P}`);

+ 1
- 1
JitsiConferenceEventManager.js Bestand weergeven

@@ -608,7 +608,7 @@ JitsiConferenceEventManager.prototype.setupXMPPListeners = function() {
608 608
         const participant = conference.getParticipantById(Strophe.getResourceFromJid(from));
609 609
 
610 610
         if (participant) {
611
-            participant._features = features || new Set();
611
+            participant.setFeatures(features);
612 612
             conference.eventEmitter.emit(JitsiConferenceEvents.PARTCIPANT_FEATURES_CHANGED, participant);
613 613
         }
614 614
     };

+ 29
- 33
JitsiParticipant.js Bestand weergeven

@@ -1,16 +1,12 @@
1 1
 
2
-import { getLogger } from 'jitsi-meet-logger';
3 2
 import { Strophe } from 'strophe.js';
4 3
 
5 4
 
6 5
 import * as JitsiConferenceEvents from './JitsiConferenceEvents';
7 6
 import { ParticipantConnectionStatus }
8 7
     from './modules/connectivity/ParticipantConnectionStatus';
9
-import { ERROR_FEATURE_VERSION_MISMATCH } from './modules/xmpp/Caps';
10 8
 import * as MediaType from './service/RTC/MediaType';
11 9
 
12
-const logger = getLogger(__filename);
13
-
14 10
 /**
15 11
  * Represents a participant in (i.e. a member of) a conference.
16 12
  */
@@ -229,6 +225,14 @@ export default class JitsiParticipant {
229 225
         return this._role;
230 226
     }
231 227
 
228
+    /**
229
+     * Sets a new participant role.
230
+     * @param {String} newRole - the new role.
231
+     */
232
+    setRole(newRole) {
233
+        this._role = newRole;
234
+    }
235
+
232 236
     /**
233 237
      *
234 238
      */
@@ -245,37 +249,21 @@ export default class JitsiParticipant {
245 249
     }
246 250
 
247 251
     /**
248
-     * Returns a set with the features for the participant.
249
-     * @param {int} timeout the timeout in ms for reply from the participant.
250
-     * @returns {Promise<Set<String>, Error>}
252
+     * Checks current set features.
253
+     * @param {String} feature - the feature to check.
254
+     * @return {boolean} <tt>true</tt> if this <tt>participant</tt> contains the
255
+     * <tt>feature</tt>.
251 256
      */
252
-    queryFeatures(timeout = 5000) {
253
-        if (this._getFeaturesPromise) {
254
-            return this._getFeaturesPromise;
255
-        }
256
-
257
-        this._getFeaturesPromise = this._conference.xmpp.caps.getFeatures(this._jid, timeout)
258
-            .catch(error => {
259
-                // Retry on feature version mismatch
260
-                if (error === ERROR_FEATURE_VERSION_MISMATCH) {
261
-                    return this._conference.xmpp.caps.getFeatures(this._jid, timeout);
262
-                }
263
-
264
-                logger.warn(`Failed to discover features of ${this._jid}`, error);
265
-
266
-                return Promise.reject(error);
267
-            });
268
-
269
-        return this._getFeaturesPromise
270
-            .then(result => {
271
-                this._getFeaturesPromise = undefined;
272
-
273
-                return result;
274
-            }, error => {
275
-                this._getFeaturesPromise = undefined;
257
+    hasFeature(feature) {
258
+        return this._features.has(feature);
259
+    }
276 260
 
277
-                throw error;
278
-            });
261
+    /**
262
+     * Set new features.
263
+     * @param {Set<String>|undefined} newFeatures - Sets new features.
264
+     */
265
+    setFeatures(newFeatures) {
266
+        this._features = newFeatures || new Set();
279 267
     }
280 268
 
281 269
     /**
@@ -286,4 +274,12 @@ export default class JitsiParticipant {
286 274
     getBotType() {
287 275
         return this._botType;
288 276
     }
277
+
278
+    /**
279
+     * Sets the bot type for the participant.
280
+     * @param {String} newBotType - The new bot type to set.
281
+     */
282
+    setBotType(newBotType) {
283
+        this._botType = newBotType;
284
+    }
289 285
 }

+ 0
- 90
modules/xmpp/Caps.js Bestand weergeven

@@ -5,8 +5,6 @@ import { b64_sha1, Strophe } from 'strophe.js'; // eslint-disable-line camelcase
5 5
 import XMPPEvents from '../../service/xmpp/XMPPEvents';
6 6
 import Listenable from '../util/Listenable';
7 7
 
8
-const logger = require('jitsi-meet-logger').getLogger(__filename);
9
-
10 8
 /**
11 9
  * The property
12 10
  */
@@ -14,8 +12,6 @@ const IDENTITY_PROPERTIES = [ 'category', 'type', 'lang', 'name' ];
14 12
 const IDENTITY_PROPERTIES_FOR_COMPARE = [ 'category', 'type', 'lang' ];
15 13
 const HASH = 'sha-1';
16 14
 
17
-export const ERROR_FEATURE_VERSION_MISMATCH = 'Feature version mismatch';
18
-
19 15
 /**
20 16
  *
21 17
  * @param a
@@ -74,8 +70,6 @@ export default class Caps extends Listenable {
74 70
                 + '(disco plugin is required)!');
75 71
         }
76 72
 
77
-        this.versionToCapabilities = Object.create(null);
78
-        this.jidToVersion = Object.create(null);
79 73
         this.version = '';
80 74
         this.rooms = new Set();
81 75
 
@@ -95,9 +89,6 @@ export default class Caps extends Listenable {
95 89
 
96 90
         Strophe.addNamespace('CAPS', 'http://jabber.org/protocol/caps');
97 91
         this.disco.addFeature(Strophe.NS.CAPS);
98
-        connection.addHandler(this._handleCaps.bind(this), Strophe.NS.CAPS);
99
-
100
-        this._onMucMemberLeft = this._removeJidToVersionEntry.bind(this);
101 92
     }
102 93
 
103 94
     /**
@@ -175,52 +166,6 @@ export default class Caps extends Listenable {
175 166
         }
176 167
     }
177 168
 
178
-    /**
179
-     * Returns a set with the features for a participant.
180
-     * @param {String} jid the jid of the participant
181
-     * @param {int} timeout the timeout in ms for reply from the participant.
182
-     * @returns {Promise<Set<String>, Error>}
183
-     */
184
-    getFeatures(jid, timeout = 5000) {
185
-        const user
186
-            = jid in this.jidToVersion ? this.jidToVersion[jid] : null;
187
-
188
-        if (!user || !(user.version in this.versionToCapabilities)) {
189
-            const node = user ? `${user.node}#${user.version}` : null;
190
-
191
-            return this._getDiscoInfo(jid, node, timeout)
192
-                .then(({ features, identities }) => {
193
-                    if (user) {
194
-                        const sha = generateSha(
195
-                            Array.from(identities),
196
-                            Array.from(features)
197
-                        );
198
-                        const receivedNode = `${user.node}#${sha}`;
199
-
200
-                        if (receivedNode === node) {
201
-                            this.versionToCapabilities[receivedNode] = features;
202
-
203
-                            return features;
204
-                        }
205
-
206
-                        // Check once if it has been cached asynchronously.
207
-                        if (this.versionToCapabilities[receivedNode]) {
208
-                            return this.versionToCapabilities[receivedNode];
209
-                        }
210
-
211
-                        logger.error(`Expected node ${node} but received ${
212
-                            receivedNode}`);
213
-
214
-                        return Promise.reject(ERROR_FEATURE_VERSION_MISMATCH);
215
-                    }
216
-
217
-                    return features;
218
-                });
219
-        }
220
-
221
-        return Promise.resolve(this.versionToCapabilities[user.version]);
222
-    }
223
-
224 169
     /**
225 170
      * Returns a set with the features for a host.
226 171
      * @param {String} jid the jid of the host
@@ -271,7 +216,6 @@ export default class Caps extends Listenable {
271 216
      */
272 217
     _addChatRoom(room) {
273 218
         this.rooms.add(room);
274
-        room.addListener(XMPPEvents.MUC_MEMBER_LEFT, this._onMucMemberLeft);
275 219
         this._fixChatRoomPresenceMap(room);
276 220
 
277 221
         this._updateRoomWithExternalFeatures(room);
@@ -284,7 +228,6 @@ export default class Caps extends Listenable {
284 228
      */
285 229
     _removeChatRoom(room) {
286 230
         this.rooms.delete(room);
287
-        room.removeListener(XMPPEvents.MUC_MEMBER_LEFT, this._onMucMemberLeft);
288 231
     }
289 232
 
290 233
     /**
@@ -319,37 +262,4 @@ export default class Caps extends Listenable {
319 262
 
320 263
         this._notifyVersionChanged();
321 264
     }
322
-
323
-    /**
324
-     * Parses the "c" xml node from presence.
325
-     * @param {DOMElement} stanza the presence packet
326
-     */
327
-    _handleCaps(stanza) {
328
-        const from = stanza.getAttribute('from');
329
-        const caps = stanza.querySelector('c');
330
-        const version = caps.getAttribute('ver');
331
-        const node = caps.getAttribute('node');
332
-        const oldVersion = this.jidToVersion[from];
333
-
334
-        this.jidToVersion[from] = { version,
335
-            node };
336
-        if (oldVersion && oldVersion.version !== version) {
337
-            // We should be receiving update of features in the presence <feature> node
338
-            // and ignore the caps version for disco-info
339
-            logger.warn(`Received update in caps for ${from}`);
340
-        }
341
-
342
-        // return true to not remove the handler from Strophe
343
-        return true;
344
-    }
345
-
346
-    /**
347
-     * Removes entry from this.jidToVersion map.
348
-     * @param {String} jid the jid to be removed.
349
-     */
350
-    _removeJidToVersionEntry(jid) {
351
-        if (jid in this.jidToVersion) {
352
-            delete this.jidToVersion[jid];
353
-        }
354
-    }
355 265
 }

Laden…
Annuleren
Opslaan