UNPKG

fcr-core

Version:

Core APIs for building online scenes

1,056 lines (1,042 loc) 24.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FcrCoreServiceApi = void 0; require("core-js/modules/esnext.iterator.constructor.js"); require("core-js/modules/esnext.iterator.map.js"); var _imports = require("../imports"); var _type = require("../room-control/privilege-control/type"); var _type2 = require("../room-control/user-control/type"); var _logger = require("../utilities/logger"); class FcrCoreServiceApi { logger = (() => (0, _logger.getLogger)())(); constructor(_client, appId, region) { let pathIncludeRegion = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true; this._client = _client; let pathPrefix = `/conference/apps/${appId}`; if (pathIncludeRegion) { pathPrefix = `/${(0, _imports.toLower)(region)}${pathPrefix}`; } this.logger.info('[FcrCoreServiceApi] set path prefix for Core Service API:', pathPrefix); this._pathPrefix = pathPrefix; this._client.setPathPrefix(pathPrefix); } setRestfulClient(client) { this._client = client; this._client.setPathPrefix(this._pathPrefix); } async addGroups(params, opts) { const { data } = await this._client.fetch({ path: `/v2/rooms/${opts.roomId}/groups`, method: 'PUT', data: { groups: params.map(group => { return { groupName: group.groupName, users: group.userList, createGroupRequest: opts.startTime ? { roomProperties: { schedule: { startTime: opts.startTime } } } : undefined }; }) } }); } async updateGroups(params, opts) { const { data } = await this._client.fetch({ path: `/v2/rooms/${opts.roomId}/groups/info`, method: 'PATCH', data: { groups: params.map(group => { return { groupUuid: group.groupId, groupName: group.groupName }; }) } }); } async deleteGroups(groupIds, opts) { const { data } = await this._client.fetch({ path: `/v2/rooms/${opts.roomId}/groups/states/1`, method: 'DELETE', data: { removeGroupUuids: groupIds } }); } async deleteAllGroups(opts) { const { data } = await this._client.fetch({ path: `/v2/rooms/${opts.roomId}/groups/all`, method: 'DELETE' }); } async addUsers(userList, groupId, opts) { const { data } = await this._client.fetch({ path: `/v2/rooms/${opts.roomId}/groups/users`, method: 'PATCH', data: { groups: [{ groupUuid: groupId, addUsers: userList }], inProgress: opts.inProgress } }); } async removeUsers(userList, groupId, opts) { const { data } = await this._client.fetch({ path: `/v2/rooms/${opts.roomId}/groups/users`, method: 'PATCH', data: { groups: [{ groupUuid: groupId, removeUsers: userList }], inProgress: opts.inProgress } }); } async moveUsers(userList, fromGroupId, toGroupId, opts) { const { data } = await this._client.fetch({ path: `/v2/rooms/${opts.roomId}/groups/users`, method: 'PATCH', data: { groups: [{ groupUuid: toGroupId, addUsers: userList }], inProgress: opts.inProgress } }); } /*** merge audio ****/ async mergeAudioStream(userId, opts) { const res = await this._client.fetch({ path: `/v1/rooms/${opts.roomId}/users/${userId}/call/merge`, method: 'PUT', data: {} }); return res.data; } /*** split audio ****/ async splitAudioStream(userId, opts) { const res = await this._client.fetch({ path: `/v1/rooms/${opts.roomId}/users/${userId}/call/split`, method: 'PUT', data: {} }); return res.data; } /*** user control****/ async kickOut(userId, type, opts) { const body = {}; if (type === _type2.FcrUserKickedOutType.Forever) { body.duration = -1; } return this._client.fetch({ path: `/v1/rooms/${opts.roomId}/users/${userId}/ban/${type === _type2.FcrUserKickedOutType.Forever ? 1 : 0}`, method: 'PUT', data: body }); } async kickOutByUserRoles(type, opts, userRoles) { const body = { toRoles: userRoles }; if (type === _type2.FcrUserKickedOutType.Forever) { body.duration = -1; } const { data } = await this._client.fetch({ path: `/v1/rooms/${opts.roomId}/users/ban/${type === _type2.FcrUserKickedOutType.Forever ? 1 : 0}`, method: 'PUT', data: body }); } async kickOutByUserIds(userId, type, opts) { const body = { toUserUuids: userId }; if (type === _type2.FcrUserKickedOutType.Forever) { body.duration = -1; } const { data } = await this._client.fetch({ path: `/v1/rooms/${opts.roomId}/users/ban/${type === _type2.FcrUserKickedOutType.Forever ? 1 : 0}`, method: 'PUT', data: body }); } /** room control **/ async startRoom(roomId) { return this._client.fetch({ path: `/v1/rooms/${roomId}/states/1`, method: 'PUT' }); } async endRoom(roomId) { return this._client.fetch({ path: `/v1/rooms/${roomId}/states/2`, method: 'PUT' }); } async closeRoom(roomId) { return this._client.fetch({ path: `/v1/rooms/${roomId}/states/3`, method: 'PUT' }); } async startCloudRecording(config, roomId) { return this._client.fetch({ path: `/v1/rooms/${roomId}/records/states/1`, method: 'PUT', data: { mode: 'web', webRecordConfig: { // rootUrl: config.url, audioProfile: config.audioProfile, videoBitrate: config.videoEncoderConfig.bitrate, videoWidth: config.videoEncoderConfig.dimensions.width, videoHeight: config.videoEncoderConfig.dimensions.height, videoFps: config.videoEncoderConfig.frameRate } } }); } async pauseCloudRecording(roomId) { return this._client.fetch({ path: `/v1/rooms/${roomId}/records/states/1`, method: 'PATCH', data: { mode: 'web', webRecordConfig: { onhold: true } } }); } async resumeCloudRecording(roomId) { return this._client.fetch({ path: `/v1/rooms/${roomId}/records/states/1`, method: 'PATCH', data: { webRecordConfig: { onhold: false } } }); } async stopCloudRecording(roomId) { return this._client.fetch({ path: `/v1/rooms/${roomId}/records/states/0`, method: 'PUT' }); } async setCloudRecordingReady(roomId) { return this._client.fetch({ path: `/v1/rooms/${roomId}/records/ready`, method: 'PUT' }); } // async entryRoom(params: EntryRequestParams): Promise<AgoraRteEntryRoomResponse> { // this._observable.notifyObservers('beforeJoinRoom'); // const resp = await this._client.fetch({ // path: `/v2/rooms/${params.roomId}/users/${params.userId}/entry`, // method: 'POST', // data: params, // retryFallbackDomainsWhenFail: true, // }); // const statusCode = resp['__status']; // const { code } = resp; // this._observable.notifyObservers('afterJoinRoom', statusCode, code); // return resp.data; // } /** room session */ async updateRoomSession(params) { return this._client.fetch({ path: `/v1/users/${params.userId}/sessions/${params.sessionKey}/${params.sessionId}`, method: 'PUT', data: { target: 1, targetUuids: [params.targetId], payload: params.payload, duration: params.duration } }); } async deleteRoomSession(params) { return this._client.fetch({ path: `/v1/users/${params.userId}/sessions/${params.sessionKey}/${params.sessionId}`, method: 'DELETE', data: { target: 1, targetUuids: params.receiverIds, action: params.action, payload: params.payload } }); } /** peer session */ async updatePeerSession(params) { return this._client.fetch({ path: `/v1/users/${params.userId}/sessions/${params.sessionKey}/${params.sessionId}`, method: 'PUT', data: { target: 2, targetUuids: [params.targetId], payload: params.payload, duration: params.duration } }); } async deletePeerSession(params) { return this._client.fetch({ path: `/v1/users/${params.userId}/sessions/${params.sessionKey}/${params.sessionId}`, method: 'DELETE', data: { target: 2, targetUuids: params.receiverIds, action: params.action, payload: params.payload } }); } async checkIn(params) { const { data, ts } = await this._client.fetch({ path: `/v1/rooms/${params.roomId}/users/${params.userId}/entry`, method: 'PUT', data: { password: params.password, stream: params.stream, streams: params.streams, platform: params.platform, role: params.userRole, userName: params.userName, userProperties: params.userProperties, version: params.version, bypass: params.bypass, avatar: params.avatar }, retryFallbackDomainsWhenFail: true, maxRetryTimes: 10 }); return { data, ts }; } async checkInInternal(params) { const { data, ts } = await this._client.fetch({ path: `/v1/rooms/${params.roomId}/users/${params.userId}/internal/entry`, method: 'PUT', data: { password: params.password, stream: params.stream, streams: params.streams, platform: params.platform, role: params.userRole, userName: params.userName, userProperties: params.userProperties, version: params.version, ticket: params.ticket, bypass: params.bypass }, retryFallbackDomainsWhenFail: true, maxRetryTimes: 10 }); return { data, ts }; } async updateUserName(params) { const { userName, roomId, userId } = params; const res = await this._client.fetch({ path: `/v1/rooms/${roomId}/users/${userId}/info`, method: 'PATCH', data: { userName } }); return res.data; } async updateUserProperties(_ref) { let { roomId, userUuid, properties, increments, cause } = _ref; const data = { properties, cause, increments }; const res = await this._client.fetch({ path: `/v1/rooms/${roomId}/users/${userUuid}/properties`, method: 'PUT', data: data }); return res.data; } async deleteUserProperties(_ref2) { let { roomId, userUuid, properties, cause } = _ref2; const data = { properties, cause }; const res = await this._client.fetch({ path: `/v1/rooms/${roomId}/users/${userUuid}/properties`, method: 'DELETE', data: { users: data } }); return res.data; } async updateRoomProperties(_ref3) { let { roomId, properties, increments, cause } = _ref3; const data = { properties, cause, increments }; const res = await this._client.fetch({ path: `/v1/rooms/${roomId}/properties`, method: 'PUT', data: data }); return res.data; } async deleteRoomProperties(_ref4) { let { roomId, properties, cause } = _ref4; const data = { properties, cause }; const res = await this._client.fetch({ path: `/v1/rooms/${roomId}/properties`, method: 'DELETE', data: data }); return res.data; } async getChatRoomToken(roomId, userId) { const res = await this._client.fetch({ path: `/v1/rooms/${roomId}/users/${userId}/widgets/easemobIM/token`, method: 'GET' }); return res.data; } async getUserToken(userId) { const res = await this._client.fetch({ path: `/v1/users/${userId}/widgets/easemobIM/token`, method: 'GET' }); return res.data; } async enableLockedRoom(_ref5) { let { roomId, enable, targetRoles } = _ref5; const res = await this._client.fetch({ path: `/v1/rooms/${roomId}/lock/${enable ? 1 : 0}`, method: 'PUT', data: { targetRoles: targetRoles.map(role => _type.FcrPrivilegeUserRoleToStringMap[role]) } }); return res.data; } async enablePassword(_ref6) { let { roomId, enable, password } = _ref6; const res = await this._client.fetch({ path: `/v1/rooms/${roomId}/password/${enable ? 1 : 0}`, method: 'PUT', data: { password } }); return res.data; } async enableWaitingRoom(_ref7) { let { roomId, enable } = _ref7; const res = await this._client.fetch({ path: `/v1/rooms/${roomId}/waiting/${enable ? 1 : 0}`, method: 'PUT' }); return res.data; } async moveToWaitingRoomByUserIds(userIds, roomId) { const res = await this._client.fetch({ path: `/v1/rooms/${roomId}/waiting/users`, method: 'PUT', data: { toUserUuids: userIds } }); return res.data; } async moveToWaitingRoomByUserRoles(toRoles, roomId) { const res = await this._client.fetch({ path: `/v1/rooms/${roomId}/waiting/users`, method: 'PUT', data: { toRoles } }); return res.data; } async moveToMainRoomByUserIds(userIds, roomId) { const res = await this._client.fetch({ path: `/v1/rooms/${roomId}/waiting/users`, method: 'DELETE', data: { toUserUuids: userIds } }); return res.data; } async moveToMainRoomByUserRoles(toRoles, roomId) { const res = await this._client.fetch({ path: `/v1/rooms/${roomId}/waiting/users`, method: 'DELETE', data: { toRoles } }); return res.data; } async allowSendChat(_ref8) { let { roomId, enable, targetRoles, payload } = _ref8; const res = await this._client.fetch({ path: `/v1/rooms/${roomId}/security/chat/${enable ? 1 : 0}`, method: 'PUT', data: { targetRoles, payload: { public: payload?.public === undefined ? undefined : payload.public ? 1 : 0, private: payload?.private === undefined ? undefined : { host: payload.private.host ? 1 : 0, cohost: payload.private.cohost ? 1 : 0, participant: payload.private.participant ? 1 : 0 } } } }); return res.data; } async allowChangeName(_ref9) { let { roomId, enable, targetRoles } = _ref9; const res = await this._client.fetch({ path: `/v1/rooms/${roomId}/security/changeName/${enable ? 1 : 0}`, method: 'PUT', data: { targetRoles } }); return res.data; } async allowStartAudio(_ref0) { let { roomId, enable, targetRoles } = _ref0; const res = await this._client.fetch({ path: `/v1/rooms/${roomId}/security/unmuteAudio/${enable ? 1 : 0}`, method: 'PUT', data: { targetRoles } }); return res.data; } async allowWatermark(params) { const { roomId, enable, targetRoles, payload } = params; const res = await this._client.fetch({ path: `/v1/rooms/${roomId}/security/watermark/${enable ? 1 : 0}`, method: 'PUT', data: { targetRoles, payload: { ...payload } } }); return res.data; } async allowChangeUserName(params) { const { roomId, enable, targetRoles } = params; const res = await this._client.fetch({ path: `/v1/rooms/${roomId}/security/changeName/${enable ? 1 : 0}`, method: 'PUT', data: { targetRoles } }); return res.data; } async allowStartVideo(_ref1) { let { roomId, enable, targetRoles } = _ref1; const res = await this._client.fetch({ path: `/v1/rooms/${roomId}/security/openVideo/${enable ? 1 : 0}`, method: 'PUT', data: { targetRoles } }); return res.data; } async allowJoinWithMuteAudio(_ref10) { let { roomId, enable, targetRoles } = _ref10; const res = await this._client.fetch({ path: `/v1/rooms/${roomId}/security/joinWithMuteAudio/${enable ? 1 : 0}`, method: 'PUT', data: { targetRoles } }); return res.data; } async allowJoinWithMutedVideo(_ref11) { let { roomId, enable, targetRoles } = _ref11; const res = await this._client.fetch({ path: `/v1/rooms/${roomId}/security/joinWithCloseVideo/${enable ? 1 : 0}`, method: 'PUT', data: { targetRoles } }); return res.data; } async updateUserRole(_ref12) { let { roomId, localRole, remoteRole, userId } = _ref12; const res = await this._client.fetch({ path: `/v1/rooms/${roomId}/users/${userId}/role`, method: 'PUT', data: { remoteRole, localRole } }); return res.data; } async revokeUserRole(_ref13) { let { roomId, remoteRole, localRole, userId } = _ref13; const res = await this._client.fetch({ path: `/v1/rooms/${roomId}/users/${userId}/role`, method: 'DELETE', data: { remoteRole, localRole } }); return res.data; } async claimHost(_ref14) { let { roomId, userId, hostKey } = _ref14; const res = await this._client.fetch({ path: `/v1/rooms/${roomId}/users/${userId}/claim/host`, method: 'POST', data: { hostKey } }); return res.data; } async stopLiveStreaming(roomId) { const res = await this._client.fetch({ path: `/v1/rooms/${roomId}/live/states/0`, method: 'PUT' }); return res; } async updateLiveStreamingLayout(roomId, layoutType) { const res = await this._client.fetch({ path: `/v1/rooms/${roomId}/live/states/1`, method: 'PATCH', data: { layoutType: layoutType } }); return res; } async startLiveStreaming(roomId, data) { const res = await this._client.fetch({ path: `/v1/rooms/${roomId}/live/states/1`, method: 'PUT', data: { streamUrl: data.pushStreamingUrl, streamKey: data.pushStreamingKey, pageUrl: data.pullStreamingUrl, layoutType: data.layoutType } }); return res; } async callIp(_ref15) { let { roomId, callType, ipAddress } = _ref15; const res = await this._client.fetch({ path: `/v1/rooms/${roomId}/call/${callType}`, method: 'POST', data: { ipAddress } }); return res; } async callPstn(_ref16) { let { roomId, userName, userId, callNumber } = _ref16; const res = await this._client.fetch({ path: `/v1/rooms/${roomId}/call/pstn`, method: 'POST', data: { callNumber, userName, userUuid: userId } }); return res; } async hangup(_ref17) { let { roomId, userId, callId } = _ref17; const res = await this._client.fetch({ path: `/v1/rooms/${roomId}/users/${userId}/call/${callId}`, method: 'DELETE' }); return res; } /** * @description 获取白板信息 */ async getWhiteboardToken(_ref18) { let { roomId, userId } = _ref18; return this._client.fetch({ path: `/v1/rooms/${roomId}/users/${userId}/widgets/netlessBoard/token`, method: 'GET' }); } /** * @description 获取批注token */ async getAnnotationToken(_ref19) { let { roomId, userId } = _ref19; return this._client.fetch({ path: `/v1/rooms/${roomId}/users/${userId}/widgets/annotation/token`, method: 'GET' }); } /** * @description 开启/关闭屏幕共享标注权限 */ async toggleAnnotationActivityState(roomId, state) { return this._client.fetch({ path: `/v1/rooms/${roomId}/widgets/annotation/states/${state}`, method: 'PUT' }); } /** * @description 开启/关闭屏幕共享标注权限 */ async syncScreenShareOwnerAnnotationOpenDone(roomId) { return this._client.fetch({ path: `/v1/rooms/${roomId}/widgets/annotation/states/1`, method: 'PUT' }); } /** * @description 启用/禁用屏幕共享&白板 */ async toggleShareEnable(params) { const { roomId, enable, targetRoles, payload } = params; return this._client.fetch({ path: `/v1/rooms/${roomId}/security/sharing/${enable ? 1 : 0}`, method: 'PUT', data: { targetRoles, payload: { ...payload } } }); } /** * @description 开启 / 关闭屏幕共享 */ async toggleScreenShare(params) { const { roomId, userId, enable, data } = params; return this._client.fetch({ path: `/v1/rooms/${roomId}/users/${userId}/streams/screen/states/${enable ? 1 : 0}`, method: 'PUT', data }); } /** * @description 开 / 关白板 */ async toggleWhiteboardActivityState(roomId, state) { return this._client.fetch({ path: `/v1/rooms/${roomId}/widgets/netlessBoard/states/${state}`, method: 'PUT' }); } /** * @description 启用/禁用屏幕共享&白板 */ async toggleAnnotation(params) { const { roomId, enable, payload, targetRoles } = params; return this._client.fetch({ path: `/v1/rooms/${roomId}/security/annotation/${1}`, method: 'PUT', data: { targetRoles, payload: { ...payload } } }); } /** * @description 修改白板背景 */ async setBackgroundColor(params) { const { roomId, backgroundColor } = params; return this._client.fetch({ path: `/v1/rooms/${roomId}/widgets/netlessBoard/info`, method: 'PUT', data: { backgroundColor } }); } async startShareScreen(params) { const { roomId, userId, config } = params; const res = this._client.fetch({ path: `/v1/rooms/${roomId}/users/${userId}/streams/screen/states/1`, method: 'PUT', data: config }); return res; } async stopShareScreen(params) { const { roomId, userId } = params; const res = this._client.fetch({ path: `/v1/rooms/${roomId}/users/${userId}/streams/screen/states/0`, method: 'PUT' }); return res; } async openInterpreter(params) { const { roomId, data } = params; const res = this._client.fetch({ path: `/v1/rooms/${roomId}/interpreter/states/1`, method: 'PUT', data }); return res; } async updateInterpreter(params) { return this.openInterpreter(params); } async closeInterpreter(params) { const { roomId } = params; const res = this._client.fetch({ path: `/v1/rooms/${roomId}/interpreter/states/0`, method: 'PUT', data: {} }); return res; } async upsertStreamBatch(roomUuid, streams) { return await this._client.fetch({ path: `/v1/rooms/${roomUuid}/streams`, method: 'PUT', data: { streams } }); } async updateStreamBatchByCondition(_ref20) { let { roomUuid, videoState, audioState, includeRoles, excludeRoles, condition } = _ref20; return await this._client.fetch({ path: `/v1/rooms/${roomUuid}/conditions/streams`, method: 'PUT', data: { includeRoles, excludeRoles, stream: { videoState, audioState }, condition } }); } async deleteStreamBatch(roomUuid, streams) { return await this._client.fetch({ path: `/v1/rooms/${roomUuid}/streams`, method: 'DELETE', data: { streams } }); } } exports.FcrCoreServiceApi = FcrCoreServiceApi;