瀏覽代碼

fix: Drop caps handling (#1495)

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

* fix: Drop using private fields outside JitsiParticipant.
dev1
Дамян Минков 4 年之前
父節點
當前提交
63aad7c0f8
沒有連結到貢獻者的電子郵件帳戶。
共有 4 個檔案被更改,包括 37 行新增131 行删除
  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 查看文件

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

+ 1
- 1
JitsiConferenceEventManager.js 查看文件

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

+ 29
- 33
JitsiParticipant.js 查看文件

1
 
1
 
2
-import { getLogger } from 'jitsi-meet-logger';
3
 import { Strophe } from 'strophe.js';
2
 import { Strophe } from 'strophe.js';
4
 
3
 
5
 
4
 
6
 import * as JitsiConferenceEvents from './JitsiConferenceEvents';
5
 import * as JitsiConferenceEvents from './JitsiConferenceEvents';
7
 import { ParticipantConnectionStatus }
6
 import { ParticipantConnectionStatus }
8
     from './modules/connectivity/ParticipantConnectionStatus';
7
     from './modules/connectivity/ParticipantConnectionStatus';
9
-import { ERROR_FEATURE_VERSION_MISMATCH } from './modules/xmpp/Caps';
10
 import * as MediaType from './service/RTC/MediaType';
8
 import * as MediaType from './service/RTC/MediaType';
11
 
9
 
12
-const logger = getLogger(__filename);
13
-
14
 /**
10
 /**
15
  * Represents a participant in (i.e. a member of) a conference.
11
  * Represents a participant in (i.e. a member of) a conference.
16
  */
12
  */
229
         return this._role;
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
     }
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
     getBotType() {
274
     getBotType() {
287
         return this._botType;
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 查看文件

5
 import XMPPEvents from '../../service/xmpp/XMPPEvents';
5
 import XMPPEvents from '../../service/xmpp/XMPPEvents';
6
 import Listenable from '../util/Listenable';
6
 import Listenable from '../util/Listenable';
7
 
7
 
8
-const logger = require('jitsi-meet-logger').getLogger(__filename);
9
-
10
 /**
8
 /**
11
  * The property
9
  * The property
12
  */
10
  */
14
 const IDENTITY_PROPERTIES_FOR_COMPARE = [ 'category', 'type', 'lang' ];
12
 const IDENTITY_PROPERTIES_FOR_COMPARE = [ 'category', 'type', 'lang' ];
15
 const HASH = 'sha-1';
13
 const HASH = 'sha-1';
16
 
14
 
17
-export const ERROR_FEATURE_VERSION_MISMATCH = 'Feature version mismatch';
18
-
19
 /**
15
 /**
20
  *
16
  *
21
  * @param a
17
  * @param a
74
                 + '(disco plugin is required)!');
70
                 + '(disco plugin is required)!');
75
         }
71
         }
76
 
72
 
77
-        this.versionToCapabilities = Object.create(null);
78
-        this.jidToVersion = Object.create(null);
79
         this.version = '';
73
         this.version = '';
80
         this.rooms = new Set();
74
         this.rooms = new Set();
81
 
75
 
95
 
89
 
96
         Strophe.addNamespace('CAPS', 'http://jabber.org/protocol/caps');
90
         Strophe.addNamespace('CAPS', 'http://jabber.org/protocol/caps');
97
         this.disco.addFeature(Strophe.NS.CAPS);
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
         }
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
      * Returns a set with the features for a host.
170
      * Returns a set with the features for a host.
226
      * @param {String} jid the jid of the host
171
      * @param {String} jid the jid of the host
271
      */
216
      */
272
     _addChatRoom(room) {
217
     _addChatRoom(room) {
273
         this.rooms.add(room);
218
         this.rooms.add(room);
274
-        room.addListener(XMPPEvents.MUC_MEMBER_LEFT, this._onMucMemberLeft);
275
         this._fixChatRoomPresenceMap(room);
219
         this._fixChatRoomPresenceMap(room);
276
 
220
 
277
         this._updateRoomWithExternalFeatures(room);
221
         this._updateRoomWithExternalFeatures(room);
284
      */
228
      */
285
     _removeChatRoom(room) {
229
     _removeChatRoom(room) {
286
         this.rooms.delete(room);
230
         this.rooms.delete(room);
287
-        room.removeListener(XMPPEvents.MUC_MEMBER_LEFT, this._onMucMemberLeft);
288
     }
231
     }
289
 
232
 
290
     /**
233
     /**
319
 
262
 
320
         this._notifyVersionChanged();
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
 }

Loading…
取消
儲存