Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add feat Breakout Room Messaging/Broadcast message #2339

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 44 additions & 2 deletions modules/xmpp/BreakoutRooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const FEATURE_KEY = 'features/breakout-rooms';
const BREAKOUT_ROOM_ACTIONS = {
ADD: `${FEATURE_KEY}/add`,
MOVE_TO_ROOM: `${FEATURE_KEY}/move-to-room`,
MESSAGE_TO_ROOM: `${FEATURE_KEY}/message-to-room`,
Bloodiko marked this conversation as resolved.
Show resolved Hide resolved
REMOVE: `${FEATURE_KEY}/remove`,
RENAME: `${FEATURE_KEY}/rename`
};
Expand Down Expand Up @@ -88,11 +89,11 @@ export default class BreakoutRooms {
/**
* Changes the subject of a breakout room.
*
* @param {string} breakoutRoomJid - JID of the room to be removed.
* @param {string} breakoutRoomJid - JID of the room to be renamed.
* @param {string} subject - A new subject for the breakout room.
*/
renameBreakoutRoom(breakoutRoomJid, subject) {
if (!this.isSupported() || !this.room.isModerator()) {
if (!this.isSupported() || !this.isFeatureSupported('rename') || !this.room.isModerator()) {
logger.error(`Cannot rename breakout room - supported:${this.isSupported()},
moderator:${this.room.isModerator()}`);

Expand Down Expand Up @@ -131,6 +132,47 @@ export default class BreakoutRooms {
this._sendMessage(message);
}

/**
* Sends a message to a breakout room.
*
* @param {string} roomJid - JID of the room to send the message to.
* @param {string} textContent - The message content.
*/
sendMessageToRoom(roomJid, textContent) {
Bloodiko marked this conversation as resolved.
Show resolved Hide resolved
if (!this.isSupported() || !this.isFeatureSupported('broadcast') || !this.room.isModerator()) {
logger.error(`Cannot send message to room - supported:${this.isSupported()},
moderator:${this.room.isModerator()}`);

return;
}

const message = {
type: BREAKOUT_ROOM_ACTIONS.MESSAGE_TO_ROOM,
roomJid,
textContent
};

this._sendMessage(message);
}

/**
* Sends a message to all breakout rooms.
*
* @param {string} textContent - The message content.
*/
sendBroadcastMessage(textContent) {
if (!this.isSupported() || !this.isFeatureSupported('broadcast') || !this.room.isModerator()) {
logger.error(`Cannot send broadcast message - supported:${this.isSupported()},
moderator:${this.room.isModerator()}`);

return;
}

Object.values(this._rooms).forEach(room => {
this.sendMessageToRoom(room.jid, textContent);
});
}

/**
* Retrieves whether a breakout room feature is supported.
*
Expand Down
3 changes: 3 additions & 0 deletions modules/xmpp/xmpp.js
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,9 @@ export default class XMPP extends Listenable {
if (fr.endsWith('#rename')) {
this.breakoutRoomsFeatures.rename = true;
}
if (fr.endsWith('#broadcast')) {
this.breakoutRoomsFeatures.broadcast = true;
}
});
};

Expand Down