From 6710ca8373a306c257365465197e6f453ba30c79 Mon Sep 17 00:00:00 2001 From: Bloodiko Date: Tue, 15 Aug 2023 18:08:34 +0200 Subject: [PATCH 1/5] fix typo --- modules/xmpp/BreakoutRooms.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/xmpp/BreakoutRooms.js b/modules/xmpp/BreakoutRooms.js index 7c73be5a6f..055afdfa06 100644 --- a/modules/xmpp/BreakoutRooms.js +++ b/modules/xmpp/BreakoutRooms.js @@ -88,7 +88,7 @@ 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) { From e743eccd2acb47b7543b69c6020ef16f82848a54 Mon Sep 17 00:00:00 2001 From: Bloodiko Date: Tue, 15 Aug 2023 19:29:49 +0200 Subject: [PATCH 2/5] add feat Breakout Room Messaging/Broadcast message --- modules/xmpp/BreakoutRooms.js | 42 +++++++++++++++++++++++++++++++++++ modules/xmpp/ChatRoom.js | 10 +++++---- modules/xmpp/xmpp.js | 3 +++ 3 files changed, 51 insertions(+), 4 deletions(-) diff --git a/modules/xmpp/BreakoutRooms.js b/modules/xmpp/BreakoutRooms.js index 055afdfa06..c8b161001a 100644 --- a/modules/xmpp/BreakoutRooms.js +++ b/modules/xmpp/BreakoutRooms.js @@ -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`, REMOVE: `${FEATURE_KEY}/remove`, RENAME: `${FEATURE_KEY}/rename` }; @@ -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) { + if (!this.isSupported() || !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.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. * diff --git a/modules/xmpp/ChatRoom.js b/modules/xmpp/ChatRoom.js index 33d3e13395..15e96817f6 100644 --- a/modules/xmpp/ChatRoom.js +++ b/modules/xmpp/ChatRoom.js @@ -892,9 +892,10 @@ export default class ChatRoom extends Listenable { * Send text message to the other participants in the conference * @param message * @param elementName + * @param {string} [roomjid] the jid of the chat room where the message will be sent */ - sendMessage(message, elementName) { - const msg = $msg({ to: this.roomjid, + sendMessage(message, elementName, roomjid = this.roomjid) { + const msg = $msg({ to: roomjid, type: 'groupchat' }); // We are adding the message in a packet extension. If this element @@ -916,9 +917,10 @@ export default class ChatRoom extends Listenable { * @param id id/muc resource of the receiver * @param message * @param elementName + * @param {string} [roomjid] the jid of the chat room where the recieving participant is */ - sendPrivateMessage(id, message, elementName) { - const msg = $msg({ to: `${this.roomjid}/${id}`, + sendPrivateMessage(id, message, elementName, roomjid = this.roomjid) { + const msg = $msg({ to: `${roomjid}/${id}`, type: 'chat' }); // We are adding the message in packet. If this element is different diff --git a/modules/xmpp/xmpp.js b/modules/xmpp/xmpp.js index 59d90c2958..cf7e164789 100644 --- a/modules/xmpp/xmpp.js +++ b/modules/xmpp/xmpp.js @@ -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; + } }); }; From f566f5e357b9a1544194e737408589c5e3410676 Mon Sep 17 00:00:00 2001 From: Bloodiko Date: Thu, 24 Aug 2023 20:33:28 +0200 Subject: [PATCH 3/5] add feature Check for new Function --- modules/xmpp/BreakoutRooms.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/xmpp/BreakoutRooms.js b/modules/xmpp/BreakoutRooms.js index c8b161001a..f3f1a2e41c 100644 --- a/modules/xmpp/BreakoutRooms.js +++ b/modules/xmpp/BreakoutRooms.js @@ -139,7 +139,7 @@ export default class BreakoutRooms { * @param {string} textContent - The message content. */ sendMessageToRoom(roomJid, textContent) { - if (!this.isSupported() || !this.room.isModerator()) { + if (!this.isSupported() || !this.isFeatureSupported('broadcast') || !this.room.isModerator()) { logger.error(`Cannot send message to room - supported:${this.isSupported()}, moderator:${this.room.isModerator()}`); @@ -161,7 +161,7 @@ export default class BreakoutRooms { * @param {string} textContent - The message content. */ sendBroadcastMessage(textContent) { - if (!this.isSupported() || !this.room.isModerator()) { + if (!this.isSupported() || !this.isFeatureSupported('broadcast') || !this.room.isModerator()) { logger.error(`Cannot send broadcast message - supported:${this.isSupported()}, moderator:${this.room.isModerator()}`); From 7a511267ef2a92a3ac5134e01ba80d2159260414 Mon Sep 17 00:00:00 2001 From: Bloodiko Date: Thu, 24 Aug 2023 20:34:02 +0200 Subject: [PATCH 4/5] add rename function feature check as well, seemed to be missing --- modules/xmpp/BreakoutRooms.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/xmpp/BreakoutRooms.js b/modules/xmpp/BreakoutRooms.js index f3f1a2e41c..c2e987af1e 100644 --- a/modules/xmpp/BreakoutRooms.js +++ b/modules/xmpp/BreakoutRooms.js @@ -93,7 +93,7 @@ export default class BreakoutRooms { * @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()}`); From c2416a09902d92b5c3a8c0b0a2cdeb11d792024b Mon Sep 17 00:00:00 2001 From: Bloodiko Date: Thu, 24 Aug 2023 20:41:30 +0200 Subject: [PATCH 5/5] reverting my change, as commented --- modules/xmpp/ChatRoom.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/modules/xmpp/ChatRoom.js b/modules/xmpp/ChatRoom.js index 15e96817f6..33d3e13395 100644 --- a/modules/xmpp/ChatRoom.js +++ b/modules/xmpp/ChatRoom.js @@ -892,10 +892,9 @@ export default class ChatRoom extends Listenable { * Send text message to the other participants in the conference * @param message * @param elementName - * @param {string} [roomjid] the jid of the chat room where the message will be sent */ - sendMessage(message, elementName, roomjid = this.roomjid) { - const msg = $msg({ to: roomjid, + sendMessage(message, elementName) { + const msg = $msg({ to: this.roomjid, type: 'groupchat' }); // We are adding the message in a packet extension. If this element @@ -917,10 +916,9 @@ export default class ChatRoom extends Listenable { * @param id id/muc resource of the receiver * @param message * @param elementName - * @param {string} [roomjid] the jid of the chat room where the recieving participant is */ - sendPrivateMessage(id, message, elementName, roomjid = this.roomjid) { - const msg = $msg({ to: `${roomjid}/${id}`, + sendPrivateMessage(id, message, elementName) { + const msg = $msg({ to: `${this.roomjid}/${id}`, type: 'chat' }); // We are adding the message in packet. If this element is different