diff --git a/JitsiConferenceEventManager.js b/JitsiConferenceEventManager.js index 3fc16f2079..2168e518af 100644 --- a/JitsiConferenceEventManager.js +++ b/JitsiConferenceEventManager.js @@ -275,16 +275,14 @@ JitsiConferenceEventManager.prototype.setupChatRoomListeners = function() { this.chatRoomForwarder.forward(XMPPEvents.PHONE_NUMBER_CHANGED, JitsiConferenceEvents.PHONE_NUMBER_CHANGED); - chatRoom.setParticipantPropertyListener((node, from) => { - const participant = conference.getParticipantById(from); + chatRoom.setParticipantPropertyListener((id, prop, value) => { + const participant = conference.getParticipantById(id); if (!participant) { return; } - participant.setProperty( - node.tagName.substring('jitsi_participant_'.length), - node.value); + participant.setProperty(prop, value); }); chatRoom.addListener(XMPPEvents.KICKED, diff --git a/modules/xmpp/ChatRoom.js b/modules/xmpp/ChatRoom.js index e6f3b93844..89eb73350a 100644 --- a/modules/xmpp/ChatRoom.js +++ b/modules/xmpp/ChatRoom.js @@ -772,6 +772,8 @@ export default class ChatRoom extends Listenable { } } + const participantProperties = new Map(); + // after we had fired member or room joined events, lets fire events // for the rest info we got in presence for (let i = 0; i < nodes.length; i++) { @@ -850,11 +852,24 @@ export default class ChatRoom extends Listenable { this.eventEmitter.emit(XMPPEvents.PHONE_NUMBER_CHANGED); break; } - default: - this.processNode(node, from); + default: { + if (node.tagName.startsWith('jitsi_participant_')) { + participantProperties + .set(node.tagName.substring('jitsi_participant_'.length), node.value); + } else { + this.processNode(node, from); + } + } } } + // All participant properties are in `participantProperties`, call the event handlers now. + const participantId = Strophe.getResourceFromJid(from); + + for (const [ key, value ] of participantProperties) { + this.participantPropertyListener(participantId, key, value); + } + // Trigger status message update if necessary if (hasStatusUpdate) { this.eventEmitter.emit( @@ -915,17 +930,11 @@ export default class ChatRoom extends Listenable { // make sure we catch all errors coming from any handler // otherwise we can remove the presence handler from strophe try { - let tagHandlers = this.presHandlers[node.tagName]; - - if (node.tagName.startsWith('jitsi_participant_')) { - tagHandlers = [ this.participantPropertyListener ]; - } + const tagHandlers = this.presHandlers[node.tagName] ?? []; - if (tagHandlers) { - tagHandlers.forEach(handler => { - handler(node, Strophe.getResourceFromJid(from), from); - }); - } + tagHandlers.forEach(handler => { + handler(node, Strophe.getResourceFromJid(from), from); + }); } catch (e) { logger.error(`Error processing:${node.tagName} node.`, e); }