Skip to content

Commit 79373c3

Browse files
naman9271naman9271
authored andcommitted
conflicts resolved
1 parent 806e213 commit 79373c3

File tree

1 file changed

+52
-21
lines changed

1 file changed

+52
-21
lines changed

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

Lines changed: 52 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { $msg, Strophe } from 'strophe.js';
33

44
import { XMPPEvents } from '../../service/xmpp/XMPPEvents';
55

6+
import ChatRoom from './ChatRoom';
7+
68
const FEATURE_KEY = 'features/breakout-rooms';
79
const BREAKOUT_ROOM_ACTIONS = {
810
ADD: `${FEATURE_KEY}/add`,
@@ -17,17 +19,46 @@ const BREAKOUT_ROOM_EVENTS = {
1719

1820
const logger = getLogger('modules/xmpp/BreakoutRooms');
1921

22+
/**
23+
* Types for breakout room participants and rooms.
24+
*/
25+
export interface IBreakoutRoomParticipant {
26+
[key: string]: unknown;
27+
jid: string;
28+
}
29+
30+
export interface IBreakoutRoom {
31+
[key: string]: unknown;
32+
participants?: { [key: string]: IBreakoutRoomParticipant; };
33+
}
34+
35+
export interface IBreakoutRoomsUpdatePayload {
36+
[key: string]: unknown;
37+
event: string;
38+
rooms: { [key: string]: IBreakoutRoom; };
39+
}
40+
41+
export interface IBreakoutRoomsMoveToRoomPayload {
42+
[key: string]: unknown;
43+
event: string;
44+
roomJid: string;
45+
}
46+
2047
/**
2148
* Helper class for handling breakout rooms.
2249
*/
2350
export default class BreakoutRooms {
51+
private room: ChatRoom;
52+
private _rooms: { [key: string]: IBreakoutRoom; };
53+
private _isBreakoutRoom?: boolean;
54+
private _mainRoomJid?: string;
2455

2556
/**
2657
* Constructs breakout room.
2758
*
2859
* @param {ChatRoom} room the room we are in.
2960
*/
30-
constructor(room) {
61+
constructor(room: ChatRoom) {
3162
this.room = room;
3263

3364
this._handleMessages = this._handleMessages.bind(this);
@@ -39,7 +70,7 @@ export default class BreakoutRooms {
3970
/**
4071
* Stops listening for events.
4172
*/
42-
dispose() {
73+
dispose(): void {
4374
this.room.xmpp.removeListener(XMPPEvents.BREAKOUT_ROOMS_EVENT, this._handleMessages);
4475
}
4576

@@ -48,7 +79,7 @@ export default class BreakoutRooms {
4879
*
4980
* @param {string} subject - A subject for the breakout room.
5081
*/
51-
createBreakoutRoom(subject) {
82+
createBreakoutRoom(subject: string): void {
5283
if (!this.isSupported() || !this.room.isModerator()) {
5384
logger.error(`Cannot create breakout room - supported:${this.isSupported()},
5485
moderator:${this.room.isModerator()}`);
@@ -69,7 +100,7 @@ export default class BreakoutRooms {
69100
*
70101
* @param {string} breakoutRoomJid - JID of the room to be removed.
71102
*/
72-
removeBreakoutRoom(breakoutRoomJid) {
103+
removeBreakoutRoom(breakoutRoomJid: string): void {
73104
if (!this.isSupported() || !this.room.isModerator()) {
74105
logger.error(`Cannot remove breakout room - supported:${this.isSupported()},
75106
moderator:${this.room.isModerator()}`);
@@ -91,7 +122,7 @@ export default class BreakoutRooms {
91122
* @param {string} breakoutRoomJid - JID of the room to be removed.
92123
* @param {string} subject - A new subject for the breakout room.
93124
*/
94-
renameBreakoutRoom(breakoutRoomJid, subject) {
125+
renameBreakoutRoom(breakoutRoomJid: string, subject: string): void {
95126
if (!this.isSupported() || !this.room.isModerator()) {
96127
logger.error(`Cannot rename breakout room - supported:${this.isSupported()},
97128
moderator:${this.room.isModerator()}`);
@@ -115,7 +146,7 @@ export default class BreakoutRooms {
115146
* @param {string} participantJid - JID of the participant to be sent to a room.
116147
* @param {string} roomJid - JID of the target room.
117148
*/
118-
sendParticipantToRoom(participantJid, roomJid) {
149+
sendParticipantToRoom(participantJid: string, roomJid: string): void {
119150
if (!this.isSupported() || !this.room.isModerator()) {
120151
logger.error(`Cannot send participant to room - supported:${this.isSupported()},
121152
moderator:${this.room.isModerator()}`);
@@ -138,14 +169,14 @@ export default class BreakoutRooms {
138169
* @param {string} feature - Feature to check.
139170
* @returns Wether the feature is supported.
140171
*/
141-
isFeatureSupported(feature) {
142-
return Boolean((this.room.xmpp.breakoutRoomsFeatures || {})[feature]);
172+
isFeatureSupported(feature: string): boolean {
173+
return Boolean(this.room.xmpp.breakoutRoomsFeatures?.[feature]);
143174
}
144175

145176
/**
146177
* Whether Breakout Rooms support is enabled in the backend or not.
147178
*/
148-
isSupported() {
179+
isSupported(): boolean {
149180
return Boolean(this.getComponentAddress());
150181
}
151182

@@ -154,7 +185,7 @@ export default class BreakoutRooms {
154185
*
155186
* @returns The address of the component.
156187
*/
157-
getComponentAddress() {
188+
getComponentAddress(): string | undefined {
158189
return this.room.xmpp.breakoutRoomsComponentAddress;
159190
}
160191

@@ -163,7 +194,7 @@ export default class BreakoutRooms {
163194
*
164195
* @param {boolean} isBreakoutRoom - Whether this room is a breakout room.
165196
*/
166-
_setIsBreakoutRoom(isBreakoutRoom) {
197+
_setIsBreakoutRoom(isBreakoutRoom: boolean): void {
167198
this._isBreakoutRoom = isBreakoutRoom;
168199
}
169200

@@ -172,7 +203,7 @@ export default class BreakoutRooms {
172203
*
173204
* @returns True if the room is a breakout room, false otherwise.
174205
*/
175-
isBreakoutRoom() {
206+
isBreakoutRoom(): boolean {
176207
if (typeof this._isBreakoutRoom !== 'undefined') {
177208
return this._isBreakoutRoom;
178209
}
@@ -187,7 +218,7 @@ export default class BreakoutRooms {
187218
*
188219
* @param {string} jid - The main room JID.
189220
*/
190-
_setMainRoomJid(jid) {
221+
_setMainRoomJid(jid: string): void {
191222
this._mainRoomJid = jid;
192223
}
193224

@@ -196,7 +227,7 @@ export default class BreakoutRooms {
196227
*
197228
* @returns The main room JID.
198229
*/
199-
getMainRoomJid() {
230+
getMainRoomJid(): string | undefined {
200231
return this._mainRoomJid;
201232
}
202233

@@ -205,13 +236,13 @@ export default class BreakoutRooms {
205236
*
206237
* @param {object} payload - Arbitrary data.
207238
*/
208-
_handleMessages(payload) {
239+
_handleMessages(payload: IBreakoutRoomsUpdatePayload | IBreakoutRoomsMoveToRoomPayload): void {
209240
switch (payload.event) {
210241
case BREAKOUT_ROOM_EVENTS.MOVE_TO_ROOM:
211-
this.room.eventEmitter.emit(XMPPEvents.BREAKOUT_ROOMS_MOVE_TO_ROOM, payload.roomJid);
242+
this.room.eventEmitter.emit(XMPPEvents.BREAKOUT_ROOMS_MOVE_TO_ROOM, (payload as IBreakoutRoomsMoveToRoomPayload).roomJid);
212243
break;
213244
case BREAKOUT_ROOM_EVENTS.UPDATE: {
214-
const filteredPayload = this._filterUpdatePayload(payload);
245+
const filteredPayload = this._filterUpdatePayload(payload as IBreakoutRoomsUpdatePayload);
215246

216247
this._rooms = filteredPayload.rooms;
217248
this.room.eventEmitter.emit(XMPPEvents.BREAKOUT_ROOMS_UPDATED, filteredPayload);
@@ -226,14 +257,14 @@ export default class BreakoutRooms {
226257
* @param {Object} payload - The payload of the update message.
227258
* @return {Object} - The filtered payload.
228259
*/
229-
_filterUpdatePayload(payload) {
260+
_filterUpdatePayload(payload: IBreakoutRoomsUpdatePayload): IBreakoutRoomsUpdatePayload {
230261
const hiddenDomain = this.room.options.hiddenDomain;
231262
const { rooms } = payload;
232-
const filteredRooms = {};
263+
const filteredRooms: { [key: string]: IBreakoutRoom; } = {};
233264

234265
Object.entries(rooms).forEach(([ key, room ]) => {
235266
const { participants = {} } = room;
236-
const filteredParticipants = {};
267+
const filteredParticipants: { [key: string]: IBreakoutRoomParticipant; } = {};
237268

238269
Object.entries(participants).forEach(([ k, participant ]) => {
239270
if (Strophe.getDomainFromJid(participant.jid) !== hiddenDomain) {
@@ -258,7 +289,7 @@ export default class BreakoutRooms {
258289
*
259290
* @param {Object} message - Command that needs to be sent.
260291
*/
261-
_sendMessage(message) {
292+
_sendMessage(message: { [key: string]: unknown; }): void {
262293
const msg = $msg({ to: this.getComponentAddress() });
263294

264295
msg.c('breakout_rooms', message).up();

0 commit comments

Comments
 (0)