|
@@ -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
|
}
|