Skip to content

Commit b31f089

Browse files
naman9271naman9271
authored andcommitted
done
1 parent 806e213 commit b31f089

File tree

1 file changed

+48
-47
lines changed

1 file changed

+48
-47
lines changed

modules/xmpp/Lobby.js renamed to modules/xmpp/Lobby.ts

Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { getLogger } from '@jitsi/logger';
22
import { $msg, Strophe } from 'strophe.js';
33

44
import { XMPPEvents } from '../../service/xmpp/XMPPEvents';
5+
import XMPP from './xmpp';
6+
import ChatRoom from './ChatRoom';
57

68
const logger = getLogger('modules/xmpp/Lobby');
79

@@ -17,13 +19,17 @@ const EMAIL_COMMAND = 'email';
1719
* approving or denying access to participants from the lobby room.
1820
*/
1921
export default class Lobby {
22+
xmpp: XMPP;
23+
mainRoom: any;
24+
lobbyRoomJid?: string;
25+
lobbyRoom?: any;
2026

2127
/**
2228
* Constructs lobby room.
2329
*
2430
* @param {ChatRoom} room the main room.
2531
*/
26-
constructor(room) {
32+
constructor(room: ChatRoom) {
2733
this.xmpp = room.xmpp;
2834
this.mainRoom = room;
2935

@@ -39,7 +45,7 @@ export default class Lobby {
3945

4046
this.mainRoom.addEventListener(
4147
XMPPEvents.ROOM_CONNECT_MEMBERS_ONLY_ERROR,
42-
jid => {
48+
(jid: string) => {
4349
this.lobbyRoomJid = jid;
4450
});
4551
}
@@ -49,24 +55,24 @@ export default class Lobby {
4955
*
5056
* @returns {boolean} whether lobby is supported on backend.
5157
*/
52-
isSupported() {
58+
isSupported(): boolean {
5359
return this.xmpp.lobbySupported;
5460
}
5561

5662
/**
5763
* Enables lobby by setting the main room to be members only and joins the lobby chat room.
5864
*
59-
* @returns {Promise}
65+
* @returns {Promise<void>}
6066
*/
61-
enable() {
67+
enable(): Promise<void> {
6268
if (!this.isSupported()) {
6369
return Promise.reject(new Error('Lobby not supported!'));
6470
}
6571

6672
// let's wait for the room data form to be populated after XMPPEvents.MUC_JOINED
6773
if (!this.mainRoom.initialDiscoRoomInfoReceived) {
6874
return new Promise((resolve, reject) => {
69-
let unsubscribers = [];
75+
let unsubscribers: Array<() => void> = [];
7076
const unsubscribe = () => {
7177
unsubscribers.forEach(remove => remove());
7278
unsubscribers = [];
@@ -86,7 +92,7 @@ export default class Lobby {
8692
}));
8793

8894
// on timeout or failure
89-
unsubscribers.push(this.mainRoom.addCancellableListener(XMPPEvents.ROOM_DISCO_INFO_FAILED, e => {
95+
unsubscribers.push(this.mainRoom.addCancellableListener(XMPPEvents.ROOM_DISCO_INFO_FAILED, (e: any) => {
9096
unsubscribe();
9197
reject(e);
9298
}));
@@ -107,7 +113,7 @@ export default class Lobby {
107113
*
108114
* @returns {void}
109115
*/
110-
disable() {
116+
disable(): void {
111117
if (!this.isSupported() || !this.mainRoom.isModerator()
112118
|| !this.lobbyRoom || !this.mainRoom.membersOnlyEnabled) {
113119
return;
@@ -122,7 +128,7 @@ export default class Lobby {
122128
*
123129
* @returns {void}
124130
*/
125-
sendMessage(message) {
131+
sendMessage(message: object): void {
126132
if (this.lobbyRoom) {
127133
this.lobbyRoom.sendMessage(JSON.stringify(message), 'json-message');
128134
}
@@ -135,7 +141,7 @@ export default class Lobby {
135141
*
136142
* @returns {void}
137143
*/
138-
sendPrivateMessage(id, message) {
144+
sendPrivateMessage(id: string, message: object): void {
139145
if (this.lobbyRoom) {
140146
this.lobbyRoom.sendPrivateMessage(id, JSON.stringify(message), 'json-message');
141147
}
@@ -145,9 +151,9 @@ export default class Lobby {
145151
* Gets the local id for a participant in a lobby room.
146152
* This is used for lobby room private chat messages.
147153
*
148-
* @returns {string}
154+
* @returns {string|undefined}
149155
*/
150-
getLocalId() {
156+
getLocalId(): string | undefined {
151157
if (this.lobbyRoom) {
152158
return Strophe.getResourceFromJid(this.lobbyRoom.myroomjid);
153159
}
@@ -158,11 +164,11 @@ export default class Lobby {
158164
* @param {Function} listener The listener function,
159165
* called when a new message is received in the lobby room.
160166
*
161-
* @returns {Function} Handler returned to be able to remove it later.
167+
* @returns {Function|undefined} Handler returned to be able to remove it later.
162168
*/
163-
addMessageListener(listener) {
169+
addMessageListener(listener: (message: string, participantId: string) => void): ((participantId: string, message: any) => void) | undefined {
164170
if (this.lobbyRoom) {
165-
const handler = (participantId, message) => {
171+
const handler = (participantId: string, message: string) => {
166172
listener(message, Strophe.getResourceFromJid(participantId));
167173
};
168174

@@ -178,7 +184,7 @@ export default class Lobby {
178184
*
179185
* @returns {void}
180186
*/
181-
removeMessageHandler(handler) {
187+
removeMessageHandler(handler: (...args: any[]) => void): void {
182188
if (this.lobbyRoom) {
183189
this.lobbyRoom.off(XMPPEvents.JSON_MESSAGE_RECEIVED, handler);
184190
}
@@ -187,16 +193,16 @@ export default class Lobby {
187193
/**
188194
* Leaves the lobby room.
189195
*
190-
* @returns {Promise}
196+
* @returns {Promise<void>}
191197
*/
192-
leave() {
198+
leave(): Promise<void> {
193199
if (this.lobbyRoom) {
194200
return this.lobbyRoom.leave()
195201
.then(() => {
196202
this.lobbyRoom = undefined;
197203
logger.info('Lobby room left!');
198204
})
199-
.catch(() => {}); // eslint-disable-line no-empty-function
205+
.catch(() => {}); // eslint-disable-line @typescript-eslint/no-empty-function
200206
}
201207

202208
return Promise.reject(
@@ -208,15 +214,15 @@ export default class Lobby {
208214
*
209215
* @param jid the lobby room jid to join.
210216
*/
211-
setLobbyRoomJid(jid) {
217+
setLobbyRoomJid(jid: string): void {
212218
this.lobbyRoomJid = jid;
213219
}
214220

215221
/**
216222
* Checks the state of mainRoom, lobbyRoom and current user role to decide whether to join lobby room.
217223
* @private
218224
*/
219-
_maybeJoinLobbyRoom() {
225+
_maybeJoinLobbyRoom(): void {
220226
if (!this.isSupported()) {
221227
return;
222228
}
@@ -227,18 +233,18 @@ export default class Lobby {
227233
// join the lobby
228234
this.join()
229235
.then(() => logger.info('Joined lobby room'))
230-
.catch(e => logger.error('Failed joining lobby', e));
236+
.catch((e: Error) => logger.error('Failed joining lobby', e));
231237
}
232238
}
233239

234240
/**
235241
* Joins a lobby room setting display name and eventually avatar(using the email provided).
236242
*
237-
* @param {string} username is required.
243+
* @param {string} displayName is required.
238244
* @param {string} email is optional.
239-
* @returns {Promise} resolves once we join the room.
245+
* @returns {Promise<void>} resolves once we join the room.
240246
*/
241-
join(displayName, email) {
247+
join(displayName?: string, email?: string): Promise<void> {
242248
const isModerator = this.mainRoom.joined && this.mainRoom.isModerator();
243249

244250
if (!this.lobbyRoomJid) {
@@ -266,21 +272,21 @@ export default class Lobby {
266272
}
267273

268274
if (isModerator) {
269-
this.lobbyRoom.addPresenceListener(EMAIL_COMMAND, (node, from) => {
275+
this.lobbyRoom.addPresenceListener(EMAIL_COMMAND, (node: any, from: string) => {
270276
this.mainRoom.eventEmitter.emit(XMPPEvents.MUC_LOBBY_MEMBER_UPDATED, from, { email: node.value });
271277
});
272278
this.lobbyRoom.addEventListener(
273279
XMPPEvents.MUC_MEMBER_JOINED,
274280
// eslint-disable-next-line max-params
275-
(from, nick, role, isHiddenDomain, statsID, status, identity, botType, jid) => {
281+
(from: string, nick: string, role: string, isHiddenDomain: boolean, statsID: any, status: any, identity: any, botType: any, jid: string) => {
276282
// we need to ignore joins on lobby for participants that are already in the main room
277-
if (Object.values(this.mainRoom.members).find(m => m.jid === jid)) {
283+
if (Object.values(this.mainRoom.members).find((m: any) => m.jid === jid)) {
278284
return;
279285
}
280286

281287
// Check if the user is a member if any breakout room.
282288
for (const room of Object.values(this.mainRoom.getBreakoutRooms()._rooms)) {
283-
if (Object.values(room.participants).find(p => p.jid === jid)) {
289+
if (Object.values((room as { participants: { jid: string; }[]; }).participants).find(p => p.jid === jid)) {
284290
return;
285291
}
286292
}
@@ -295,7 +301,7 @@ export default class Lobby {
295301
);
296302
});
297303
this.lobbyRoom.addEventListener(
298-
XMPPEvents.MUC_MEMBER_LEFT, from => {
304+
XMPPEvents.MUC_MEMBER_LEFT, (from: string) => {
299305
// we emit the new event on the main room so we can propagate
300306
// events to the conference
301307
this.mainRoom.eventEmitter.emit(
@@ -318,13 +324,11 @@ export default class Lobby {
318324
});
319325
} else {
320326
// this should only be handled by those waiting in lobby
321-
this.lobbyRoom.addEventListener(XMPPEvents.KICKED, isSelfPresence => {
327+
this.lobbyRoom.addEventListener(XMPPEvents.KICKED, (isSelfPresence: boolean) => {
322328
if (isSelfPresence) {
323329
this.mainRoom.eventEmitter.emit(XMPPEvents.MUC_DENIED_ACCESS);
324330

325331
this.lobbyRoom.clean();
326-
327-
328332
}
329333
});
330334

@@ -333,7 +337,7 @@ export default class Lobby {
333337
// the invite message should be received directly to the xmpp conn in general
334338
this.mainRoom.addEventListener(
335339
XMPPEvents.INVITE_MESSAGE_RECEIVED,
336-
(roomJid, from, txt, invitePassword) => {
340+
(roomJid: string, from: string, txt: string, invitePassword: string) => {
337341
logger.debug(`Received approval to join ${roomJid} ${from} ${txt}`);
338342
if (roomJid === this.mainRoom.roomjid) {
339343
// we are now allowed, so let's join
@@ -342,7 +346,7 @@ export default class Lobby {
342346
});
343347
this.lobbyRoom.addEventListener(
344348
XMPPEvents.MUC_DESTROYED,
345-
(reason, jid) => {
349+
(reason: any, jid: string) => {
346350
this.lobbyRoom?.clean();
347351

348352
this.lobbyRoom = undefined;
@@ -370,7 +374,7 @@ export default class Lobby {
370374
});
371375
}
372376

373-
return new Promise((resolve, reject) => {
377+
return new Promise<void>((resolve, reject) => {
374378
this.lobbyRoom.addEventListener(XMPPEvents.MUC_JOINED, () => {
375379
resolve();
376380

@@ -393,7 +397,7 @@ export default class Lobby {
393397
* Should be possible only for moderators.
394398
* @param id
395399
*/
396-
denyAccess(id) {
400+
denyAccess(id: string): void {
397401
if (!this.isSupported() || !this.mainRoom.isModerator()) {
398402
return;
399403
}
@@ -412,7 +416,7 @@ export default class Lobby {
412416
* Should be possible only for moderators.
413417
* @param param or an array of ids.
414418
*/
415-
approveAccess(param) {
419+
approveAccess(param: string | string[]): void {
416420
if (!this.isSupported() || !this.mainRoom.isModerator()) {
417421
return;
418422
}
@@ -425,12 +429,8 @@ export default class Lobby {
425429
mainRoomJid = this.mainRoom.getBreakoutRooms().getMainRoomJid();
426430
}
427431

428-
const membersToApprove = [];
429-
let ids = param;
430-
431-
if (!Array.isArray(param)) {
432-
ids = [ param ];
433-
}
432+
const membersToApprove: string[] = [];
433+
const ids: string[] = Array.isArray(param) ? param : [ param ];
434434

435435
ids.forEach(id => {
436436
const memberRoomJid = Object.keys(this.lobbyRoom.members)
@@ -453,10 +453,11 @@ export default class Lobby {
453453
});
454454

455455
this.xmpp.connection.sendIQ(msgToSend,
456-
() => { }, // eslint-disable-line no-empty-function
457-
e => {
456+
() => { }, // eslint-disable-line @typescript-eslint/no-empty-function
457+
(e: Error) => {
458458
logger.error(`Error sending invite for ${membersToApprove}`, e);
459-
});
459+
},
460+
undefined);
460461
}
461462
}
462463
}

0 commit comments

Comments
 (0)