Skip to content

Commit

Permalink
feat(webinar): add webcast API (#4040)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tianhui-Han authored Dec 26, 2024
1 parent 0b897d0 commit f306d42
Show file tree
Hide file tree
Showing 3 changed files with 487 additions and 2 deletions.
7 changes: 7 additions & 0 deletions packages/@webex/plugin-meetings/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,13 @@ export const EVENT_TYPES = {
ERROR: 'error',
};

export const HEADERS = {
CONTENT_TYPE: 'Content-Type',
CONTENT_TYPE_VALUE: {
APPLICATION_JSON: 'application/json',
},
};

// Handles the reason when meeting gets destroyed
// host removed you from the meeting
// You are the host and you left the meeting
Expand Down
166 changes: 164 additions & 2 deletions packages/@webex/plugin-meetings/src/webinar/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/*!
* Copyright (c) 2015-2023 Cisco Systems, Inc. See LICENSE file.
*/
import {WebexPlugin} from '@webex/webex-core';
import {WebexPlugin, config} from '@webex/webex-core';
import uuid from 'uuid';
import {get} from 'lodash';
import {HTTP_VERBS, MEETINGS, SELF_ROLES} from '../constants';
import {HEADERS, HTTP_VERBS, MEETINGS, SELF_ROLES} from '../constants';

import WebinarCollection from './collection';
import LoggerProxy from '../common/logs/logger-proxy';
Expand Down Expand Up @@ -103,6 +104,167 @@ const Webinar = WebexPlugin.extend({
updatePracticeSessionStatus(payload) {
this.set('practiceSessionEnabled', payload.enabled);
},

/**
* start webcast mode for webinar
* @param {object} meeting
* @param {object} layout
* @returns {Promise}
*/
async startWebcast(meeting, layout) {
if (!meeting) {
LoggerProxy.logger.error(
`Meeting:webinar#startWebcast failed --> meeting parameter : ${meeting}`
);
throw new Error('Meeting parameter does not meet expectations');
}

return this.request({
method: HTTP_VERBS.PUT,
uri: `${this.webcastInstanceUrl}/streaming`,
headers: {
authorization: await this.webex.credentials.getUserToken(),
trackingId: `${config.trackingIdPrefix}_${uuid.v4().toString()}`,
[HEADERS.CONTENT_TYPE]: HEADERS.CONTENT_TYPE_VALUE.APPLICATION_JSON,
},
body: {
action: 'start',
meetingInfo: {
locusId: meeting.locusId,
correlationId: meeting.correlationId,
},
layout,
},
}).catch((error) => {
LoggerProxy.logger.error('Meeting:webinar#startWebcast failed', error);
throw error;
});
},

/**
* stop webcast mode for webinar
* @returns {Promise}
*/
async stopWebcast() {
return this.request({
method: HTTP_VERBS.PUT,
uri: `${this.webcastInstanceUrl}/streaming`,
headers: {
authorization: await this.webex.credentials.getUserToken(),
trackingId: `${config.trackingIdPrefix}_${uuid.v4().toString()}`,
[HEADERS.CONTENT_TYPE]: HEADERS.CONTENT_TYPE_VALUE.APPLICATION_JSON,
},
body: {
action: 'stop',
},
}).catch((error) => {
LoggerProxy.logger.error('Meeting:webinar#stopWebcast failed', error);
throw error;
});
},

/**
* query webcast layout for webinar
* @returns {Promise}
*/
async queryWebcastLayout() {
return this.request({
method: HTTP_VERBS.GET,
uri: `${this.webcastInstanceUrl}/layout`,
headers: {
authorization: await this.webex.credentials.getUserToken(),
trackingId: `${config.trackingIdPrefix}_${uuid.v4().toString()}`,
},
}).catch((error) => {
LoggerProxy.logger.error('Meeting:webinar#queryWebcastLayout failed', error);
throw error;
});
},

/**
* update webcast layout for webinar
* @param {object} layout
* @returns {Promise}
*/
async updateWebcastLayout(layout) {
return this.request({
method: HTTP_VERBS.PUT,
uri: `${this.webcastInstanceUrl}/layout`,
headers: {
authorization: await this.webex.credentials.getUserToken(),
trackingId: `${config.trackingIdPrefix}_${uuid.v4().toString()}`,
[HEADERS.CONTENT_TYPE]: HEADERS.CONTENT_TYPE_VALUE.APPLICATION_JSON,
},
body: {
layout: {
videoLayout: layout.videoLayout,
contentLayout: layout.contentLayout,
syncStageLayout: layout.syncStageLayout,
syncStageInMeeting: layout.syncStageInMeeting,
},
},
}).catch((error) => {
LoggerProxy.logger.error('Meeting:webinar#updateWebcastLayout failed', error);
throw error;
});
},

/**
* view all webcast attendees
* @param {string} queryString
* @returns {Promise}
*/
async viewAllWebcastAttendees() {
return this.request({
method: HTTP_VERBS.GET,
uri: `${this.webcastInstanceUrl}/attendees`,
headers: {
authorization: await this.webex.credentials.getUserToken(),
trackingId: `${config.trackingIdPrefix}_${uuid.v4().toString()}`,
},
}).catch((error) => {
LoggerProxy.logger.error('Meeting:webinar#viewAllWebcastAttendees failed', error);
throw error;
});
},

/**
* search webcast attendees by query string
* @param {string} queryString
* @returns {Promise}
*/
async searchWebcastAttendees(queryString = '') {
return this.request({
method: HTTP_VERBS.GET,
uri: `${this.webcastInstanceUrl}/attendees?keyword=${encodeURIComponent(queryString)}`,
headers: {
authorization: await this.webex.credentials.getUserToken(),
trackingId: `${config.trackingIdPrefix}_${uuid.v4().toString()}`,
},
}).catch((error) => {
LoggerProxy.logger.error('Meeting:webinar#searchWebcastAttendees failed', error);
throw error;
});
},

/**
* expel webcast attendee by participantId
* @param {string} participantId
* @returns {Promise}
*/
async expelWebcastAttendee(participantId) {
return this.request({
method: HTTP_VERBS.DELETE,
uri: `${this.webcastInstanceUrl}/attendees/${participantId}`,
headers: {
authorization: await this.webex.credentials.getUserToken(),
trackingId: `${config.trackingIdPrefix}_${uuid.v4().toString()}`,
},
}).catch((error) => {
LoggerProxy.logger.error('Meeting:webinar#expelWebcastAttendee failed', error);
throw error;
});
},
});

export default Webinar;
Loading

0 comments on commit f306d42

Please sign in to comment.