From acbf641fb45c69938c012338979e4d9de1a83822 Mon Sep 17 00:00:00 2001 From: Jim Bullington Date: Tue, 5 May 2020 10:03:54 -0400 Subject: [PATCH] Add participantRoleChanged event to external API (#6573) * Add participantRoleChanged event to external API * Update API documentation * Remove unneeded whitespace * Remove more unneeded whitespace * Fix jsdoc formatting * Fix jsdoc formatting --- conference.js | 1 + doc/api.md | 8 ++++++++ modules/API/API.js | 16 ++++++++++++++++ modules/API/external/external_api.js | 1 + react/features/base/participants/actionTypes.js | 13 +++++++++++++ react/features/external-api/middleware.js | 5 +++++ 6 files changed, 44 insertions(+) diff --git a/conference.js b/conference.js index 2e50e6834..9665623b8 100644 --- a/conference.js +++ b/conference.js @@ -2093,6 +2093,7 @@ export default { logger.info(`My role changed, new role: ${role}`); APP.store.dispatch(localParticipantRoleChanged(role)); + APP.API.notifyUserRoleChanged(id, role); } else { APP.store.dispatch(participantRoleChanged(id, role)); } diff --git a/doc/api.md b/doc/api.md index 9281c3a6e..85b1e8d60 100644 --- a/doc/api.md +++ b/doc/api.md @@ -465,6 +465,14 @@ changes. The listener will receive an object with the following structure: } ``` +* **participantRoleChanged** - event notification fired when the role of the local user has changed (none, moderator, participant). The listener will receive an object with the following structure: +```javascript +{ + id: string // the id of the participant + role: string // the new role of the participant +} +``` + * **passwordRequired** - event notifications fired when failing to join a room because it has a password. * **videoConferenceJoined** - event notifications fired when the local user has joined the video conference. The listener will receive an object with the following structure: diff --git a/modules/API/API.js b/modules/API/API.js index a37199b3c..7adec2f62 100644 --- a/modules/API/API.js +++ b/modules/API/API.js @@ -439,6 +439,22 @@ class API { }); } + /** + * Notify external application (if API is enabled) that the user role + * has changed. + * + * @param {string} id - User id. + * @param {string} role - The new user role. + * @returns {void} + */ + notifyUserRoleChanged(id: string, role: string) { + this._sendEvent({ + name: 'participant-role-changed', + id, + role + }); + } + /** * Notify external application (if API is enabled) that user changed their * avatar. diff --git a/modules/API/external/external_api.js b/modules/API/external/external_api.js index c0d3a8cdb..a79faf3bb 100644 --- a/modules/API/external/external_api.js +++ b/modules/API/external/external_api.js @@ -67,6 +67,7 @@ const events = { 'participant-joined': 'participantJoined', 'participant-kicked-out': 'participantKickedOut', 'participant-left': 'participantLeft', + 'participant-role-changed': 'participantRoleChanged', 'password-required': 'passwordRequired', 'proxy-connection-event': 'proxyConnectionEvent', 'video-ready-to-close': 'readyToClose', diff --git a/react/features/base/participants/actionTypes.js b/react/features/base/participants/actionTypes.js index 6bfb3cc28..377a45b5e 100644 --- a/react/features/base/participants/actionTypes.js +++ b/react/features/base/participants/actionTypes.js @@ -57,6 +57,19 @@ export const PARTICIPANT_DISPLAY_NAME_CHANGED */ export const PARTICIPANT_ID_CHANGED = 'PARTICIPANT_ID_CHANGED'; +/** + * Action to signal that participant role has changed. e. + * + * { + * type: PARTICIPANT_ROLE_CHANGED, + * participant: { + * id: string + * } + * role: string + * } + */ +export const PARTICIPANT_ROLE_CHANGED = 'PARTICIPANT_ROLE_CHANGED'; + /** * Action to signal that a participant has joined. * diff --git a/react/features/external-api/middleware.js b/react/features/external-api/middleware.js index 1ac2b28c4..a9d41ea4b 100644 --- a/react/features/external-api/middleware.js +++ b/react/features/external-api/middleware.js @@ -12,6 +12,7 @@ import { PARTICIPANT_KICKED, PARTICIPANT_LEFT, PARTICIPANT_JOINED, + PARTICIPANT_ROLE_CHANGED, SET_LOADABLE_AVATAR_URL, getLocalParticipant, getParticipantById @@ -157,6 +158,10 @@ MiddlewareRegistry.register(store => next => action => { break; } + case PARTICIPANT_ROLE_CHANGED: + APP.API.notifyUserRoleChanged(action.participant.id, action.participant.role); + break; + case SET_FILMSTRIP_VISIBLE: APP.API.notifyFilmstripDisplayChanged(action.visible); break;