Skip to content

Commit b81813e

Browse files
committed
migrated
1 parent 04f536a commit b81813e

File tree

2 files changed

+52
-22
lines changed

2 files changed

+52
-22
lines changed

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

Lines changed: 48 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,42 @@ const BREAKOUT_ROOM_EVENTS = {
1719

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

22+
/**
23+
* Types for breakout room participants and rooms.
24+
*/
25+
export interface IBreakoutRoomParticipant {
26+
jid: string;
27+
}
28+
29+
export interface IBreakoutRoom {
30+
participants?: { [key: string]: IBreakoutRoomParticipant; };
31+
}
32+
33+
export interface IBreakoutRoomsUpdatePayload {
34+
event: string;
35+
rooms: { [key: string]: IBreakoutRoom; };
36+
}
37+
38+
export interface IBreakoutRoomsMoveToRoomPayload {
39+
event: string;
40+
roomJid: string;
41+
}
42+
2043
/**
2144
* Helper class for handling breakout rooms.
2245
*/
2346
export default class BreakoutRooms {
47+
private room: ChatRoom;
48+
private _rooms: { [key: string]: IBreakoutRoom; };
49+
private _isBreakoutRoom?: boolean;
50+
private _mainRoomJid?: string;
2451

2552
/**
2653
* Constructs breakout room.
2754
*
2855
* @param {ChatRoom} room the room we are in.
2956
*/
30-
constructor(room) {
57+
constructor(room: ChatRoom) {
3158
this.room = room;
3259

3360
this._handleMessages = this._handleMessages.bind(this);
@@ -39,7 +66,7 @@ export default class BreakoutRooms {
3966
/**
4067
* Stops listening for events.
4168
*/
42-
dispose() {
69+
dispose(): void {
4370
this.room.xmpp.removeListener(XMPPEvents.BREAKOUT_ROOMS_EVENT, this._handleMessages);
4471
}
4572

@@ -48,7 +75,7 @@ export default class BreakoutRooms {
4875
*
4976
* @param {string} subject - A subject for the breakout room.
5077
*/
51-
createBreakoutRoom(subject) {
78+
createBreakoutRoom(subject: string): void {
5279
if (!this.isSupported() || !this.room.isModerator()) {
5380
logger.error(`Cannot create breakout room - supported:${this.isSupported()},
5481
moderator:${this.room.isModerator()}`);
@@ -69,7 +96,7 @@ export default class BreakoutRooms {
6996
*
7097
* @param {string} breakoutRoomJid - JID of the room to be removed.
7198
*/
72-
removeBreakoutRoom(breakoutRoomJid) {
99+
removeBreakoutRoom(breakoutRoomJid: string): void {
73100
if (!this.isSupported() || !this.room.isModerator()) {
74101
logger.error(`Cannot remove breakout room - supported:${this.isSupported()},
75102
moderator:${this.room.isModerator()}`);
@@ -91,7 +118,7 @@ export default class BreakoutRooms {
91118
* @param {string} breakoutRoomJid - JID of the room to be removed.
92119
* @param {string} subject - A new subject for the breakout room.
93120
*/
94-
renameBreakoutRoom(breakoutRoomJid, subject) {
121+
renameBreakoutRoom(breakoutRoomJid: string, subject: string): void {
95122
if (!this.isSupported() || !this.room.isModerator()) {
96123
logger.error(`Cannot rename breakout room - supported:${this.isSupported()},
97124
moderator:${this.room.isModerator()}`);
@@ -115,7 +142,7 @@ export default class BreakoutRooms {
115142
* @param {string} participantJid - JID of the participant to be sent to a room.
116143
* @param {string} roomJid - JID of the target room.
117144
*/
118-
sendParticipantToRoom(participantJid, roomJid) {
145+
sendParticipantToRoom(participantJid: string, roomJid: string): void {
119146
if (!this.isSupported() || !this.room.isModerator()) {
120147
logger.error(`Cannot send participant to room - supported:${this.isSupported()},
121148
moderator:${this.room.isModerator()}`);
@@ -138,14 +165,14 @@ export default class BreakoutRooms {
138165
* @param {string} feature - Feature to check.
139166
* @returns Wether the feature is supported.
140167
*/
141-
isFeatureSupported(feature) {
142-
return Boolean((this.room.xmpp.breakoutRoomsFeatures || {})[feature]);
168+
isFeatureSupported(feature: string): boolean {
169+
return Boolean(this.room.xmpp.breakoutRoomsFeatures?.[feature]);
143170
}
144171

145172
/**
146173
* Whether Breakout Rooms support is enabled in the backend or not.
147174
*/
148-
isSupported() {
175+
isSupported(): boolean {
149176
return Boolean(this.getComponentAddress());
150177
}
151178

@@ -154,7 +181,7 @@ export default class BreakoutRooms {
154181
*
155182
* @returns The address of the component.
156183
*/
157-
getComponentAddress() {
184+
getComponentAddress(): Optional<string> {
158185
return this.room.xmpp.breakoutRoomsComponentAddress;
159186
}
160187

@@ -163,7 +190,7 @@ export default class BreakoutRooms {
163190
*
164191
* @param {boolean} isBreakoutRoom - Whether this room is a breakout room.
165192
*/
166-
_setIsBreakoutRoom(isBreakoutRoom) {
193+
_setIsBreakoutRoom(isBreakoutRoom: boolean): void {
167194
this._isBreakoutRoom = isBreakoutRoom;
168195
}
169196

@@ -172,7 +199,7 @@ export default class BreakoutRooms {
172199
*
173200
* @returns True if the room is a breakout room, false otherwise.
174201
*/
175-
isBreakoutRoom() {
202+
isBreakoutRoom(): boolean {
176203
if (typeof this._isBreakoutRoom !== 'undefined') {
177204
return this._isBreakoutRoom;
178205
}
@@ -187,7 +214,7 @@ export default class BreakoutRooms {
187214
*
188215
* @param {string} jid - The main room JID.
189216
*/
190-
_setMainRoomJid(jid) {
217+
_setMainRoomJid(jid: string): void {
191218
this._mainRoomJid = jid;
192219
}
193220

@@ -196,7 +223,7 @@ export default class BreakoutRooms {
196223
*
197224
* @returns The main room JID.
198225
*/
199-
getMainRoomJid() {
226+
getMainRoomJid(): Optional<string> {
200227
return this._mainRoomJid;
201228
}
202229

@@ -205,13 +232,13 @@ export default class BreakoutRooms {
205232
*
206233
* @param {object} payload - Arbitrary data.
207234
*/
208-
_handleMessages(payload) {
235+
_handleMessages(payload: IBreakoutRoomsUpdatePayload | IBreakoutRoomsMoveToRoomPayload): void {
209236
switch (payload.event) {
210237
case BREAKOUT_ROOM_EVENTS.MOVE_TO_ROOM:
211-
this.room.eventEmitter.emit(XMPPEvents.BREAKOUT_ROOMS_MOVE_TO_ROOM, payload.roomJid);
238+
this.room.eventEmitter.emit(XMPPEvents.BREAKOUT_ROOMS_MOVE_TO_ROOM, (payload as IBreakoutRoomsMoveToRoomPayload).roomJid);
212239
break;
213240
case BREAKOUT_ROOM_EVENTS.UPDATE: {
214-
const filteredPayload = this._filterUpdatePayload(payload);
241+
const filteredPayload = this._filterUpdatePayload(payload as IBreakoutRoomsUpdatePayload);
215242

216243
this._rooms = filteredPayload.rooms;
217244
this.room.eventEmitter.emit(XMPPEvents.BREAKOUT_ROOMS_UPDATED, filteredPayload);
@@ -226,14 +253,14 @@ export default class BreakoutRooms {
226253
* @param {Object} payload - The payload of the update message.
227254
* @return {Object} - The filtered payload.
228255
*/
229-
_filterUpdatePayload(payload) {
256+
_filterUpdatePayload(payload: IBreakoutRoomsUpdatePayload): IBreakoutRoomsUpdatePayload {
230257
const hiddenDomain = this.room.options.hiddenDomain;
231258
const { rooms } = payload;
232-
const filteredRooms = {};
259+
const filteredRooms: { [key: string]: IBreakoutRoom; } = {};
233260

234261
Object.entries(rooms).forEach(([ key, room ]) => {
235262
const { participants = {} } = room;
236-
const filteredParticipants = {};
263+
const filteredParticipants: { [key: string]: IBreakoutRoomParticipant; } = {};
237264

238265
Object.entries(participants).forEach(([ k, participant ]) => {
239266
if (Strophe.getDomainFromJid(participant.jid) !== hiddenDomain) {
@@ -258,7 +285,7 @@ export default class BreakoutRooms {
258285
*
259286
* @param {Object} message - Command that needs to be sent.
260287
*/
261-
_sendMessage(message) {
288+
_sendMessage(message: { [key: string]: unknown; }): void {
262289
const msg = $msg({ to: this.getComponentAddress() });
263290

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

modules/xmpp/ChatRoom.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,6 @@ export default class ChatRoom extends Listenable {
226226
private _removeConnListeners: (() => void)[];
227227
private inProgressEmitted: boolean;
228228
private noBridgeAvailable: boolean;
229-
private options: IChatRoomOptions;
230229
private eventsForwarder: EventEmitterForwarder;
231230
private lobby?: Lobby;
232231
private avModeration: AVModeration;
@@ -246,6 +245,10 @@ export default class ChatRoom extends Listenable {
246245
private subject?: string;
247246
private _roomCreationRetries?: number;
248247
private cachedShortTermCredentials?: Record<string, string>;
248+
/**
249+
* @internal
250+
*/
251+
options: IChatRoomOptions;
249252
public xmpp: XMPP;
250253
public connection: XmppConnection;
251254
public roomjid: string;

0 commit comments

Comments
 (0)