|
@@ -9,6 +9,7 @@ import Listenable from '../util/Listenable';
|
9
|
9
|
import * as MediaType from '../../service/RTC/MediaType';
|
10
|
10
|
import XMPPEvents from '../../service/xmpp/XMPPEvents';
|
11
|
11
|
|
|
12
|
+import Lobby from './Lobby';
|
12
|
13
|
import Moderator from './moderator';
|
13
|
14
|
import XmppConnection from './XmppConnection';
|
14
|
15
|
|
|
@@ -80,6 +81,12 @@ function filterNodeFromPresenceJSON(pres, nodeName) {
|
80
|
81
|
// of chaining function calls, allow long function call chains.
|
81
|
82
|
/* eslint-disable newline-per-chained-call */
|
82
|
83
|
|
|
84
|
+/**
|
|
85
|
+ * Array of affiliations that are allowed in members only room.
|
|
86
|
+ * @type {string[]}
|
|
87
|
+ */
|
|
88
|
+const MEMBERS_AFFILIATIONS = [ 'owner', 'admin', 'member' ];
|
|
89
|
+
|
83
|
90
|
/**
|
84
|
91
|
*
|
85
|
92
|
*/
|
|
@@ -95,8 +102,10 @@ export default class ChatRoom extends Listenable {
|
95
|
102
|
* @param XMPP
|
96
|
103
|
* @param options
|
97
|
104
|
* @param {boolean} options.disableFocus - when set to {@code false} will
|
98
|
|
- * not invite Jicofo into the room. This is intended to be used only by
|
99
|
|
- * jitsi-meet-spot.
|
|
105
|
+ * not invite Jicofo into the room.
|
|
106
|
+ * @param {boolean} options.disableDiscoInfo - when set to {@code false} will skip disco info.
|
|
107
|
+ * This is intended to be used only for lobby rooms.
|
|
108
|
+ * @param {boolean} options.enableLobby - when set to {@code false} will skip creating lobby room.
|
100
|
109
|
*/
|
101
|
110
|
constructor(connection, jid, password, XMPP, options) {
|
102
|
111
|
super();
|
|
@@ -120,6 +129,9 @@ export default class ChatRoom extends Listenable {
|
120
|
129
|
connection: this.xmpp.options,
|
121
|
130
|
conference: this.options
|
122
|
131
|
});
|
|
132
|
+ if (typeof this.options.enableLobby === 'undefined' || this.options.enableLobby) {
|
|
133
|
+ this.lobby = new Lobby(this);
|
|
134
|
+ }
|
123
|
135
|
this.initPresenceMap(options);
|
124
|
136
|
this.lastPresences = {};
|
125
|
137
|
this.phoneNumber = null;
|
|
@@ -168,16 +180,19 @@ export default class ChatRoom extends Listenable {
|
168
|
180
|
|
169
|
181
|
/**
|
170
|
182
|
* Joins the chat room.
|
171
|
|
- * @param password
|
|
183
|
+ * @param {string} password - Password to unlock room on joining.
|
|
184
|
+ * @param {Object} customJoinPresenceExtensions - Key values object to be used
|
|
185
|
+ * for the initial presence, they key will be an xmpp node and its text is the value,
|
|
186
|
+ * and those will be added to the initial <x xmlns='http://jabber.org/protocol/muc'/>
|
172
|
187
|
* @returns {Promise} - resolved when join completes. At the time of this
|
173
|
188
|
* writing it's never rejected.
|
174
|
189
|
*/
|
175
|
|
- join(password) {
|
|
190
|
+ join(password, customJoinPresenceExtensions) {
|
176
|
191
|
this.password = password;
|
177
|
192
|
|
178
|
193
|
return new Promise(resolve => {
|
179
|
194
|
this.options.disableFocus
|
180
|
|
- && logger.info('Conference focus disabled');
|
|
195
|
+ && logger.info(`Conference focus disabled for ${this.roomjid}`);
|
181
|
196
|
|
182
|
197
|
const preJoin
|
183
|
198
|
= this.options.disableFocus
|
|
@@ -185,7 +200,7 @@ export default class ChatRoom extends Listenable {
|
185
|
200
|
: this.moderator.allocateConferenceFocus();
|
186
|
201
|
|
187
|
202
|
preJoin.then(() => {
|
188
|
|
- this.sendPresence(true);
|
|
203
|
+ this.sendPresence(true, customJoinPresenceExtensions);
|
189
|
204
|
this._removeConnListeners.push(
|
190
|
205
|
this.connection.addEventListener(
|
191
|
206
|
XmppConnection.Events.CONN_STATUS_CHANGED,
|
|
@@ -198,9 +213,10 @@ export default class ChatRoom extends Listenable {
|
198
|
213
|
|
199
|
214
|
/**
|
200
|
215
|
*
|
201
|
|
- * @param fromJoin
|
|
216
|
+ * @param fromJoin - Whether this is initial presence to join the room.
|
|
217
|
+ * @param customJoinPresenceExtensions - Object of key values to be added to the initial presence only.
|
202
|
218
|
*/
|
203
|
|
- sendPresence(fromJoin) {
|
|
219
|
+ sendPresence(fromJoin, customJoinPresenceExtensions) {
|
204
|
220
|
const to = this.presMap.to;
|
205
|
221
|
|
206
|
222
|
if (!this.connection || !this.connection.connected || !to || (!this.joined && !fromJoin)) {
|
|
@@ -221,6 +237,11 @@ export default class ChatRoom extends Listenable {
|
221
|
237
|
if (this.password) {
|
222
|
238
|
pres.c('password').t(this.password).up();
|
223
|
239
|
}
|
|
240
|
+ if (customJoinPresenceExtensions) {
|
|
241
|
+ Object.keys(customJoinPresenceExtensions).forEach(key => {
|
|
242
|
+ pres.c(key).t(customJoinPresenceExtensions[key]).up();
|
|
243
|
+ });
|
|
244
|
+ }
|
224
|
245
|
pres.up();
|
225
|
246
|
}
|
226
|
247
|
|
|
@@ -298,8 +319,23 @@ export default class ChatRoom extends Listenable {
|
298
|
319
|
if (meetingIdValEl.length) {
|
299
|
320
|
this.setMeetingId(meetingIdValEl.text());
|
300
|
321
|
} else {
|
301
|
|
- logger.trace('No meeting ID from backend');
|
|
322
|
+ logger.warn('No meeting ID from backend');
|
|
323
|
+ }
|
|
324
|
+
|
|
325
|
+ const membersOnly = $(result).find('>query>feature[var="muc_membersonly"]').length === 1;
|
|
326
|
+
|
|
327
|
+ const lobbyRoomField
|
|
328
|
+ = $(result).find('>query>x[type="result"]>field[var="muc#roominfo_lobbyroom"]>value');
|
|
329
|
+
|
|
330
|
+ if (this.lobby) {
|
|
331
|
+ this.lobby.setLobbyRoomJid(lobbyRoomField && lobbyRoomField.length ? lobbyRoomField.text() : undefined);
|
302
|
332
|
}
|
|
333
|
+
|
|
334
|
+ if (membersOnly !== this.membersOnlyEnabled) {
|
|
335
|
+ this.membersOnlyEnabled = membersOnly;
|
|
336
|
+ this.eventEmitter.emit(XMPPEvents.MUC_MEMBERS_ONLY_CHANGED, membersOnly);
|
|
337
|
+ }
|
|
338
|
+
|
303
|
339
|
}, error => {
|
304
|
340
|
GlobalOnErrorHandler.callErrorHandler(error);
|
305
|
341
|
logger.error('Error getting room info: ', error);
|
|
@@ -328,6 +364,10 @@ export default class ChatRoom extends Listenable {
|
328
|
364
|
createNonAnonymousRoom() {
|
329
|
365
|
// http://xmpp.org/extensions/xep-0045.html#createroom-reserved
|
330
|
366
|
|
|
367
|
+ if (this.options.disableDiscoInfo) {
|
|
368
|
+ return;
|
|
369
|
+ }
|
|
370
|
+
|
331
|
371
|
const getForm = $iq({ type: 'get',
|
332
|
372
|
to: this.roomjid })
|
333
|
373
|
.c('query', { xmlns: 'http://jabber.org/protocol/muc#owner' })
|
|
@@ -533,7 +573,7 @@ export default class ChatRoom extends Listenable {
|
533
|
573
|
|
534
|
574
|
// Now let's check the disco-info to retrieve the
|
535
|
575
|
// meeting Id if any
|
536
|
|
- this.discoRoomInfo();
|
|
576
|
+ !this.options.disableDiscoInfo && this.discoRoomInfo();
|
537
|
577
|
}
|
538
|
578
|
} else if (jid === undefined) {
|
539
|
579
|
logger.info('Ignoring member with undefined JID');
|
|
@@ -558,7 +598,8 @@ export default class ChatRoom extends Listenable {
|
558
|
598
|
member.statsID,
|
559
|
599
|
member.status,
|
560
|
600
|
member.identity,
|
561
|
|
- member.botType);
|
|
601
|
+ member.botType,
|
|
602
|
+ member.jid);
|
562
|
603
|
|
563
|
604
|
// we are reporting the status with the join
|
564
|
605
|
// so we do not want a second event about status update
|
|
@@ -575,6 +616,11 @@ export default class ChatRoom extends Listenable {
|
575
|
616
|
XMPPEvents.MUC_ROLE_CHANGED, from, member.role);
|
576
|
617
|
}
|
577
|
618
|
|
|
619
|
+ // affiliation changed
|
|
620
|
+ if (memberOfThis.affiliation !== member.affiliation) {
|
|
621
|
+ memberOfThis.affiliation = member.affiliation;
|
|
622
|
+ }
|
|
623
|
+
|
578
|
624
|
// fire event that botType had changed
|
579
|
625
|
if (memberOfThis.botType !== member.botType) {
|
580
|
626
|
memberOfThis.botType = member.botType;
|
|
@@ -856,8 +902,9 @@ export default class ChatRoom extends Listenable {
|
856
|
902
|
}
|
857
|
903
|
|
858
|
904
|
// room destroyed ?
|
859
|
|
- if ($(pres).find('>x[xmlns="http://jabber.org/protocol/muc#user"]'
|
860
|
|
- + '>destroy').length) {
|
|
905
|
+ const destroySelect = $(pres).find('>x[xmlns="http://jabber.org/protocol/muc#user"]>destroy');
|
|
906
|
+
|
|
907
|
+ if (destroySelect.length) {
|
861
|
908
|
let reason;
|
862
|
909
|
const reasonSelect
|
863
|
910
|
= $(pres).find(
|
|
@@ -868,7 +915,7 @@ export default class ChatRoom extends Listenable {
|
868
|
915
|
reason = reasonSelect.text();
|
869
|
916
|
}
|
870
|
917
|
|
871
|
|
- this.eventEmitter.emit(XMPPEvents.MUC_DESTROYED, reason);
|
|
918
|
+ this.eventEmitter.emit(XMPPEvents.MUC_DESTROYED, reason, destroySelect.attr('jid'));
|
872
|
919
|
this.connection.emuc.doLeave(this.roomjid);
|
873
|
920
|
|
874
|
921
|
return true;
|
|
@@ -900,24 +947,17 @@ export default class ChatRoom extends Listenable {
|
900
|
947
|
actorNick = actorSelect.attr('nick');
|
901
|
948
|
}
|
902
|
949
|
|
903
|
|
- // if no member is found this is the case we had kicked someone
|
904
|
|
- // and we are not in the list of members
|
905
|
|
- if (membersKeys.find(jid => Strophe.getResourceFromJid(jid) === actorNick)) {
|
906
|
|
- // we first fire the kicked so we can show the participant
|
907
|
|
- // who kicked, before notifying that participant left
|
908
|
|
- // we fire kicked for us and for any participant kicked
|
909
|
|
- this.eventEmitter.emit(
|
910
|
|
- XMPPEvents.KICKED,
|
911
|
|
- isSelfPresence,
|
912
|
|
- actorNick,
|
913
|
|
- Strophe.getResourceFromJid(from));
|
914
|
|
- }
|
|
950
|
+ // we first fire the kicked so we can show the participant
|
|
951
|
+ // who kicked, before notifying that participant left
|
|
952
|
+ // we fire kicked for us and for any participant kicked
|
|
953
|
+ this.eventEmitter.emit(
|
|
954
|
+ XMPPEvents.KICKED,
|
|
955
|
+ isSelfPresence,
|
|
956
|
+ actorNick,
|
|
957
|
+ Strophe.getResourceFromJid(from));
|
915
|
958
|
}
|
916
|
959
|
|
917
|
|
- if (!isSelfPresence) {
|
918
|
|
- delete this.members[from];
|
919
|
|
- this.onParticipantLeft(from, false);
|
920
|
|
- } else if (membersKeys.length > 0) {
|
|
960
|
+ if (isSelfPresence) {
|
921
|
961
|
// If the status code is 110 this means we're leaving and we would
|
922
|
962
|
// like to remove everyone else from our view, so we trigger the
|
923
|
963
|
// event.
|
|
@@ -934,6 +974,9 @@ export default class ChatRoom extends Listenable {
|
934
|
974
|
if (!isKick) {
|
935
|
975
|
this.eventEmitter.emit(XMPPEvents.MUC_LEFT);
|
936
|
976
|
}
|
|
977
|
+ } else {
|
|
978
|
+ delete this.members[from];
|
|
979
|
+ this.onParticipantLeft(from, false);
|
937
|
980
|
}
|
938
|
981
|
}
|
939
|
982
|
|
|
@@ -986,9 +1029,23 @@ export default class ChatRoom extends Listenable {
|
986
|
1029
|
}
|
987
|
1030
|
}
|
988
|
1031
|
|
989
|
|
- if (from === this.roomjid
|
990
|
|
- && $(msg).find('>x[xmlns="http://jabber.org/protocol/muc#user"]>status[code="104"]').length) {
|
991
|
|
- this.discoRoomInfo();
|
|
1032
|
+ if (from === this.roomjid) {
|
|
1033
|
+ let invite;
|
|
1034
|
+
|
|
1035
|
+ if ($(msg).find('>x[xmlns="http://jabber.org/protocol/muc#user"]>status[code="104"]').length) {
|
|
1036
|
+ this.discoRoomInfo();
|
|
1037
|
+ } else if ((invite = $(msg).find('>x[xmlns="http://jabber.org/protocol/muc#user"]>invite'))
|
|
1038
|
+ && invite.length) {
|
|
1039
|
+ const passwordSelect = $(msg).find('>x[xmlns="http://jabber.org/protocol/muc#user"]>password');
|
|
1040
|
+ let password;
|
|
1041
|
+
|
|
1042
|
+ if (passwordSelect && passwordSelect.length) {
|
|
1043
|
+ password = passwordSelect.text();
|
|
1044
|
+ }
|
|
1045
|
+
|
|
1046
|
+ this.eventEmitter.emit(XMPPEvents.INVITE_MESSAGE_RECEIVED,
|
|
1047
|
+ from, invite.attr('from'), txt, password);
|
|
1048
|
+ }
|
992
|
1049
|
}
|
993
|
1050
|
const jsonMessage = $(msg).find('>json-message').text();
|
994
|
1051
|
const parsedJson = this.xmpp.tryParseJSONAndVerify(jsonMessage);
|
|
@@ -1052,6 +1109,21 @@ export default class ChatRoom extends Listenable {
|
1052
|
1109
|
logger.warn('Maximum users limit for the room has been reached',
|
1053
|
1110
|
pres);
|
1054
|
1111
|
this.eventEmitter.emit(XMPPEvents.ROOM_MAX_USERS_ERROR);
|
|
1112
|
+ } else if ($(pres)
|
|
1113
|
+ .find(
|
|
1114
|
+ '>error[type="auth"]'
|
|
1115
|
+ + '>registration-required['
|
|
1116
|
+ + 'xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"]').length) {
|
|
1117
|
+
|
|
1118
|
+ // let's extract the lobby jid from the custom field
|
|
1119
|
+ const lobbyRoomNode = $(pres).find('>lobbyroom');
|
|
1120
|
+ let lobbyRoomJid;
|
|
1121
|
+
|
|
1122
|
+ if (lobbyRoomNode.length) {
|
|
1123
|
+ lobbyRoomJid = lobbyRoomNode.text();
|
|
1124
|
+ }
|
|
1125
|
+
|
|
1126
|
+ this.eventEmitter.emit(XMPPEvents.ROOM_CONNECT_MEMBERS_ONLY_ERROR, lobbyRoomJid);
|
1055
|
1127
|
} else {
|
1056
|
1128
|
logger.warn('onPresError ', pres);
|
1057
|
1129
|
this.eventEmitter.emit(XMPPEvents.ROOM_CONNECT_ERROR);
|
|
@@ -1132,6 +1204,16 @@ export default class ChatRoom extends Listenable {
|
1132
|
1204
|
.up()
|
1133
|
1205
|
.up();
|
1134
|
1206
|
|
|
1207
|
+ // if members only enabled
|
|
1208
|
+ if (this.membersOnlyEnabled) {
|
|
1209
|
+ formsubmit
|
|
1210
|
+ .c('field', { 'var': 'muc#roomconfig_membersonly' })
|
|
1211
|
+ .c('value')
|
|
1212
|
+ .t('true')
|
|
1213
|
+ .up()
|
|
1214
|
+ .up();
|
|
1215
|
+ }
|
|
1216
|
+
|
1135
|
1217
|
// Fixes a bug in prosody 0.9.+
|
1136
|
1218
|
// https://prosody.im/issues/issue/373
|
1137
|
1219
|
formsubmit
|
|
@@ -1151,6 +1233,87 @@ export default class ChatRoom extends Listenable {
|
1151
|
1233
|
|
1152
|
1234
|
/* eslint-enable max-params */
|
1153
|
1235
|
|
|
1236
|
+ /**
|
|
1237
|
+ * Turns off or on the members only config for the main room.
|
|
1238
|
+ *
|
|
1239
|
+ * @param {boolean} enabled - Whether to turn it on or off.
|
|
1240
|
+ * @param onSuccess - optional callback.
|
|
1241
|
+ * @param onError - optional callback.
|
|
1242
|
+ */
|
|
1243
|
+ setMembersOnly(enabled, onSuccess, onError) {
|
|
1244
|
+ if (enabled && Object.values(this.members).filter(m => !m.isFocus).length) {
|
|
1245
|
+ let sendGrantMembershipIq = false;
|
|
1246
|
+
|
|
1247
|
+ // first grant membership to all that are in the room
|
|
1248
|
+ const grantMembership = $iq({ to: this.roomjid,
|
|
1249
|
+ type: 'set' })
|
|
1250
|
+ .c('query', { xmlns: 'http://jabber.org/protocol/muc#admin' });
|
|
1251
|
+
|
|
1252
|
+ Object.values(this.members).forEach(m => {
|
|
1253
|
+ if (m.jid && !MEMBERS_AFFILIATIONS.includes(m.affiliation)) {
|
|
1254
|
+ grantMembership.c('item', {
|
|
1255
|
+ 'affiliation': 'member',
|
|
1256
|
+ 'jid': m.jid }).up();
|
|
1257
|
+ sendGrantMembershipIq = true;
|
|
1258
|
+ }
|
|
1259
|
+ });
|
|
1260
|
+
|
|
1261
|
+ if (sendGrantMembershipIq) {
|
|
1262
|
+ this.xmpp.connection.sendIQ(grantMembership.up());
|
|
1263
|
+ }
|
|
1264
|
+ }
|
|
1265
|
+
|
|
1266
|
+ const errorCallback = onError ? onError : () => {}; // eslint-disable-line no-empty-function
|
|
1267
|
+
|
|
1268
|
+ this.xmpp.connection.sendIQ(
|
|
1269
|
+ $iq({
|
|
1270
|
+ to: this.roomjid,
|
|
1271
|
+ type: 'get'
|
|
1272
|
+ }).c('query', { xmlns: 'http://jabber.org/protocol/muc#owner' }),
|
|
1273
|
+ res => {
|
|
1274
|
+ if ($(res).find('>query>x[xmlns="jabber:x:data"]>field[var="muc#roomconfig_membersonly"]').length) {
|
|
1275
|
+ const formToSubmit
|
|
1276
|
+ = $iq({
|
|
1277
|
+ to: this.roomjid,
|
|
1278
|
+ type: 'set'
|
|
1279
|
+ }).c('query', { xmlns: 'http://jabber.org/protocol/muc#owner' });
|
|
1280
|
+
|
|
1281
|
+ formToSubmit.c('x', {
|
|
1282
|
+ xmlns: 'jabber:x:data',
|
|
1283
|
+ type: 'submit'
|
|
1284
|
+ });
|
|
1285
|
+ formToSubmit
|
|
1286
|
+ .c('field', { 'var': 'FORM_TYPE' })
|
|
1287
|
+ .c('value')
|
|
1288
|
+ .t('http://jabber.org/protocol/muc#roomconfig')
|
|
1289
|
+ .up()
|
|
1290
|
+ .up();
|
|
1291
|
+ formToSubmit
|
|
1292
|
+ .c('field', { 'var': 'muc#roomconfig_membersonly' })
|
|
1293
|
+ .c('value')
|
|
1294
|
+ .t(enabled ? 'true' : 'false')
|
|
1295
|
+ .up()
|
|
1296
|
+ .up();
|
|
1297
|
+
|
|
1298
|
+ // if room is locked from other participant or we are locking it
|
|
1299
|
+ if (this.locked) {
|
|
1300
|
+ formToSubmit
|
|
1301
|
+ .c('field',
|
|
1302
|
+ { 'var': 'muc#roomconfig_passwordprotectedroom' })
|
|
1303
|
+ .c('value')
|
|
1304
|
+ .t('1')
|
|
1305
|
+ .up()
|
|
1306
|
+ .up();
|
|
1307
|
+ }
|
|
1308
|
+
|
|
1309
|
+ this.xmpp.connection.sendIQ(formToSubmit, onSuccess, errorCallback);
|
|
1310
|
+ } else {
|
|
1311
|
+ errorCallback(new Error('Setting members only room not supported!'));
|
|
1312
|
+ }
|
|
1313
|
+ },
|
|
1314
|
+ errorCallback);
|
|
1315
|
+ }
|
|
1316
|
+
|
1154
|
1317
|
/**
|
1155
|
1318
|
* Adds the key to the presence map, overriding any previous value.
|
1156
|
1319
|
* @param key
|
|
@@ -1404,6 +1567,14 @@ export default class ChatRoom extends Listenable {
|
1404
|
1567
|
return this.connection.rayo.hangup();
|
1405
|
1568
|
}
|
1406
|
1569
|
|
|
1570
|
+ /**
|
|
1571
|
+ *
|
|
1572
|
+ * @returns {Lobby}
|
|
1573
|
+ */
|
|
1574
|
+ getLobby() {
|
|
1575
|
+ return this.lobby;
|
|
1576
|
+ }
|
|
1577
|
+
|
1407
|
1578
|
/**
|
1408
|
1579
|
* Returns the phone number for joining the conference.
|
1409
|
1580
|
*/
|
|
@@ -1475,6 +1646,14 @@ export default class ChatRoom extends Listenable {
|
1475
|
1646
|
}
|
1476
|
1647
|
}
|
1477
|
1648
|
|
|
1649
|
+ /**
|
|
1650
|
+ * Clean any listeners or resources, executed on leaving.
|
|
1651
|
+ */
|
|
1652
|
+ clean() {
|
|
1653
|
+ this._removeConnListeners.forEach(remove => remove());
|
|
1654
|
+ this._removeConnListeners = [];
|
|
1655
|
+ }
|
|
1656
|
+
|
1478
|
1657
|
/**
|
1479
|
1658
|
* Leaves the room. Closes the jingle session.
|
1480
|
1659
|
* @returns {Promise} which is resolved if XMPPEvents.MUC_LEFT is received
|
|
@@ -1486,8 +1665,7 @@ export default class ChatRoom extends Listenable {
|
1486
|
1665
|
const timeout = setTimeout(() => onMucLeft(true), 5000);
|
1487
|
1666
|
const eventEmitter = this.eventEmitter;
|
1488
|
1667
|
|
1489
|
|
- this._removeConnListeners.forEach(remove => remove());
|
1490
|
|
- this._removeConnListeners = [];
|
|
1668
|
+ this.clean();
|
1491
|
1669
|
|
1492
|
1670
|
/**
|
1493
|
1671
|
*
|