// @ts-ignore import {StatelessWebexPlugin} from '@webex/webex-core'; import {MEETINGS} from '../constants'; import ParameterError from '../common/errors/parameter'; import MembersUtil from './util'; import MeetingUtil from '../meeting/util'; /** * @class MembersRequest */ export default class MembersRequest extends StatelessWebexPlugin { namespace = MEETINGS; locusDeltaRequest: (options: object) => Promise; /** * Constructor * @param {Object} attrs * @param {Object} options */ constructor(attrs: {meeting: any}, options: object) { const {meeting, ...otherAttrs} = attrs; super(otherAttrs, options); this.locusDeltaRequest = MeetingUtil.generateLocusDeltaRequest(meeting); } /** * * @param {Object} options with format of {invitee: string, locusUrl: string} * @returns {Promise} * @throws {Error} if the options are not valid and complete, must have invitee with emailAddress OR email AND locusUrl * @memberof MembersRequest */ addMembers(options: any) { if ( !( !options || !options.invitee || !options.invitee.emailAddress || !options.invitee.email || !options.invitee.phoneNumber || !options.locusUrl ) ) { throw new ParameterError( 'invitee must be passed and the associated locus url for this meeting object must be defined.' ); } const requestParams = MembersUtil.getAddMemberRequestParams(options); return this.locusDeltaRequest(requestParams); } /** * * @param {Object} options * @returns {Promise} * @throws {Error} if the options are not valid and complete, must have memberIds AND locusUrl * @memberof MembersRequest */ admitMember(options: any) { if (!options || !options.locusUrl || !options.memberIds) { throw new ParameterError( 'memberIds must be an array passed and the associated locus url for this meeting object must be defined.' ); } const requestParams = MembersUtil.getAdmitMemberRequestParams(options); return this.locusDeltaRequest(requestParams); } /** * Sends a request to remove a member * @param {Object} options * @param {String} options.locusUrl * @param {String} options.memberId ID of member * @returns {Promise} */ removeMember(options) { if (!options || !options.locusUrl || !options.memberId) { throw new ParameterError( 'memberId must be defined, and the associated locus url for this meeting object must be defined.' ); } const requestParams = MembersUtil.getRemoveMemberRequestParams(options); return this.locusDeltaRequest(requestParams); } /** * Sends a request to mute a member * @param {Object} options * @param {String} options.locusUrl * @param {String} options.memberId ID of member * @returns {Promise} */ muteMember(options) { if (!options || !options.locusUrl || !options.memberId) { throw new ParameterError( 'memberId must be defined, and the associated locus url for this meeting object must be defined.' ); } const requestParams = MembersUtil.getMuteMemberRequestParams(options); // @ts-ignore return this.locusDeltaRequest(requestParams); } /** * Sends a request to the DTMF endpoint to send tones * @param {Object} options * @param {String} options.locusUrl * @param {String} options.memberId ID of PSTN user * @returns {Promise} */ assignRolesMember(options: any) { if (!options || !options.locusUrl || !options.memberId) { throw new ParameterError( 'memberId must be defined, and the associated locus url for this meeting object must be defined.' ); } const requestParams = MembersUtil.getRoleAssignmentMemberRequestParams(options); return this.locusDeltaRequest(requestParams); } /** * Sends a request to move a meeting member into the lobby. * * * @param {Object} options - Request options. * @param {string} options.locusUrl - The locus URL for the meeting. * @param {string} options.memberId - The ID of the member to move. * @param {Object} body - The request payload. * @param {Object} body.moveToLobby - Container for move‐to‐lobby data. * @param {string[]} body.moveToLobby.participantIds - Array of participant IDs to move. * @returns {Promise} - Resolves with the locus‐delta response. */ moveToLobbyMember( options: {locusUrl: string; memberId: string}, body: {moveToLobby: {participantIds: string[]}} ) { if (!options || !options.locusUrl || !options.memberId) { throw new ParameterError( 'memberId must be defined, and the associated locus url for this meeting object must be defined.' ); } const requestParams = MembersUtil.getMoveMemberToLobbyRequestParams(options, body); return this.locusDeltaRequest(requestParams); } /** * Sends a request to raise or lower a member's hand * @param {Object} options * @param {String} options.locusUrl * @param {String} options.memberId ID of member * @returns {Promise} */ raiseOrLowerHandMember(options) { if (!options || !options.locusUrl || !options.memberId) { throw new ParameterError( 'memberId must be defined, and the associated locus url for this meeting object must be defined.' ); } const requestParams = MembersUtil.getRaiseHandMemberRequestParams(options); return this.locusDeltaRequest(requestParams); } /** * Sends a request to lower all hands * @param {Object} options * @param {String} options.locusUrl * @param {String} options.requestingParticipantId ID of requesting participant * @returns {Promise} */ lowerAllHandsMember(options) { if (!options || !options.locusUrl || !options.requestingParticipantId) { throw new ParameterError( 'requestingParticipantId must be defined, and the associated locus url for this meeting object must be defined.' ); } const requestParams = MembersUtil.getLowerAllHandsMemberRequestParams(options); return this.locusDeltaRequest(requestParams); } /** * * @param {Object} options with format of {locusUrl: string, requestingParticipantId: string} * @returns {Promise} * @throws {Error} if the options are not valid and complete, must have requestingParticipantId AND locusUrl * @memberof MembersRequest */ editDisplayNameMember(options: {locusUrl: string; requestingParticipantId: string}) { if (!options || !options.locusUrl || !options.requestingParticipantId) { throw new ParameterError( 'requestingParticipantId must be defined, and the associated locus url for this meeting object must be defined.' ); } const requestParams = MembersUtil.editDisplayNameMemberRequestParams(options); return this.locusDeltaRequest(requestParams); } /** * Sends a request to raise or lower a member's hand * @param {Object} options * @param {String} options.locusUrl * @param {String} options.memberId ID of member * @param {String} options.moderator ID of moderator * @returns {Promise} */ transferHostToMember(options) { if (!options || !options.locusUrl || !options.memberId || !options.moderator) { throw new ParameterError( 'memberId must be defined, the associated locus url, and the moderator for this meeting object must be defined.' ); } const requestParams = MembersUtil.getTransferHostToMemberRequestParams(options); return this.locusDeltaRequest(requestParams); } /** * Sends a request to the DTMF endpoint to send tones * @param {Object} options * @param {String} options.locusUrl * @param {String} options.url device url SIP user * @param {String} options.tones a string of one or more DTMF tones to send * @param {String} options.memberId ID of PSTN user * @returns {Promise} */ sendDialPadKey(options: {locusUrl: string; url: string; tones: string; memberId: string}) { // @ts-ignore if ( !options || !options.locusUrl || !options.memberId || !options.url || // @ts-ignore (!options.tones && options.tones !== 0) ) { throw new ParameterError( 'memberId must be defined, the associated locus url, the device url and DTMF tones for this meeting object must be defined.' ); } const requestParams = MembersUtil.generateSendDTMFRequestParams(options); return this.locusDeltaRequest(requestParams); } /** * @param {Object} options with format of {invitee: string, locusUrl: string} * @returns {Promise} * @throws {Error} if the options are not valid and complete, must have invitee with emailAddress OR email AND locusUrl * @memberof MembersRequest */ cancelPhoneInvite(options: any) { if (!(options?.invitee?.phoneNumber || options?.locusUrl)) { throw new ParameterError( 'invitee must be passed and the associated locus url for this meeting object must be defined.' ); } const requestParams = MembersUtil.generateCancelInviteRequestParams(options); return this.locusDeltaRequest(requestParams); } /** * @param {Object} options with format of {invitee: object, locusUrl: string} * @returns {Promise} * @throws {Error} if the options are not valid and complete, must have invitee with memberId AND locusUrl * @memberof MembersRequest */ cancelInviteByMemberId(options: any) { if (!options?.invitee?.memberId || !options?.locusUrl) { throw new ParameterError( 'invitee must be passed and the associated locus url for this meeting object must be defined.' ); } const requestParams = MembersUtil.generateCancelInviteByMemberIdRequestParams(options); return this.locusDeltaRequest(requestParams); } }