UNPKG

fcr-core

Version:

Core APIs for building online scenes

1,213 lines (1,198 loc) 28.2 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, pathIncludeRegion = 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], targetRoles: params.targetRoles, 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: params.target, 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({ roomId, userUuid, properties, increments, cause }) { 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({ roomId, userUuid, properties, cause }) { 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({ roomId, properties, increments, cause }) { 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({ roomId, properties, cause }) { 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({ roomId, enable, targetRoles }) { 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({ roomId, enable, password }) { const res = await this._client.fetch({ path: `/v1/rooms/${roomId}/password/${enable ? 1 : 0}`, method: 'PUT', data: { password } }); return res.data; } async enableWaitingRoom({ roomId, enable }) { 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({ roomId, enable, targetRoles, payload }) { 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({ roomId, enable, targetRoles }) { const res = await this._client.fetch({ path: `/v1/rooms/${roomId}/security/changeName/${enable ? 1 : 0}`, method: 'PUT', data: { targetRoles } }); return res.data; } async allowStartAudio({ roomId, enable, targetRoles }) { 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 allowJoinWithPromptSound({ roomId, enable, targetRoles }) { const res = await this._client.fetch({ path: `/v1/rooms/${roomId}/security/joinWithPromptSound/${enable ? 1 : 0}`, method: 'PUT', data: { targetRoles } }); return res.data; } async allowStartVideo({ roomId, enable, targetRoles }) { const res = await this._client.fetch({ path: `/v1/rooms/${roomId}/security/openVideo/${enable ? 1 : 0}`, method: 'PUT', data: { targetRoles } }); return res.data; } async allowJoinWithMuteAudio({ roomId, enable, targetRoles }) { const res = await this._client.fetch({ path: `/v1/rooms/${roomId}/security/joinWithMuteAudio/${enable ? 1 : 0}`, method: 'PUT', data: { targetRoles } }); return res.data; } async allowJoinWithMutedVideo({ roomId, enable, targetRoles }) { const res = await this._client.fetch({ path: `/v1/rooms/${roomId}/security/joinWithCloseVideo/${enable ? 1 : 0}`, method: 'PUT', data: { targetRoles } }); return res.data; } async updateUserRole({ roomId, localRole, remoteRole, userId }) { const res = await this._client.fetch({ path: `/v1/rooms/${roomId}/users/${userId}/role`, method: 'PUT', data: { remoteRole, localRole } }); return res.data; } async revokeUserRole({ roomId, remoteRole, localRole, userId }) { const res = await this._client.fetch({ path: `/v1/rooms/${roomId}/users/${userId}/role`, method: 'DELETE', data: { remoteRole, localRole } }); return res.data; } async claimHost({ roomId, userId, hostKey }) { 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({ roomId, callType, ipAddress }) { const res = await this._client.fetch({ path: `/v1/rooms/${roomId}/call/${callType}`, method: 'POST', data: { ipAddress } }); return res; } async callPstn({ roomId, userName, userId, callNumber }) { const res = await this._client.fetch({ path: `/v1/rooms/${roomId}/call/pstn`, method: 'POST', data: { callNumber, userName, userUuid: userId } }); return res; } async hangup({ roomId, userId, callId }) { const res = await this._client.fetch({ path: `/v1/rooms/${roomId}/users/${userId}/call/${callId}`, method: 'DELETE' }); return res; } /** * @description 获取白板信息 */ async getWhiteboardToken({ roomId, userId }) { return this._client.fetch({ path: `/v1/rooms/${roomId}/users/${userId}/widgets/netlessBoard/token`, method: 'GET' }); } /** * @description 获取批注token */ async getAnnotationToken({ roomId, userId }) { 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', retryFallbackDomainsWhenFail: true }); } /** * @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 toggleShareEnableByUserIds(params) { const { roomId, enable, toUserUuids, payload } = params; return this._client.fetch({ path: `/v1/rooms/${roomId}/security/sharing/users/${enable ? 1 : 0}`, method: 'PUT', data: { toUserUuids, 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 createStreamBatch(roomUuid, streams) { return await this._client.fetch({ path: `/v1/rooms/${roomUuid}/streams`, method: 'POST', data: { streams } }); } async updateStreamBatch(roomUuid, streams) { return await this._client.fetch({ path: `/v1/rooms/${roomUuid}/streams`, method: 'PUT', data: { streams } }); } async updateStreamBatchByCondition({ roomUuid, videoState, audioState, includeRoles, excludeRoles, condition }) { 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 } }); } async startCaption(params) { const { roomUuid, userUuid, config } = params; return await this._client.fetch({ path: `/v1/rooms/${roomUuid}/users/${userUuid}/widgets/stt/caption/states/1`, method: 'PUT', data: { source: config.sourceLanguage, target: config.targetLanguage ? [config.targetLanguage] : undefined } }); } async stopCaption(params) { const { roomUuid, userUuid } = params; return await this._client.fetch({ path: `/v1/rooms/${roomUuid}/users/${userUuid}/widgets/stt/caption/states/0`, method: 'PUT' }); } async startTranscribing(params) { const { roomUuid, userUuid, config } = params; return await this._client.fetch({ path: `/v1/rooms/${roomUuid}/users/${userUuid}/widgets/stt/transcribe/states/1`, method: 'PUT', data: { source: config.sourceLanguage, target: config.targetLanguage ? [config.targetLanguage] : undefined } }); } async stopTranscribing(params) { const { roomUuid, userUuid } = params; return await this._client.fetch({ path: `/v1/rooms/${roomUuid}/users/${userUuid}/widgets/stt/transcribe/states/0`, method: 'PUT' }); } async updateSourceLanguage(params) { const { roomUuid, userUuid, language } = params; return await this._client.fetch({ path: `/v1/rooms/${roomUuid}/users/${userUuid}/widgets/stt/language/speech`, method: 'PATCH', data: { source: language } }); } async subscribeTranscribingLanguage(params) { const { roomUuid, userUuid, language } = params; return await this._client.fetch({ path: `/v1/rooms/${roomUuid}/users/${userUuid}/widgets/stt/language/subscribe/1`, method: 'PATCH', data: { target: [language] } }); } async unsubscribeTranscribingLanguage(params) { const { roomUuid, userUuid } = params; return await this._client.fetch({ path: `/v1/rooms/${roomUuid}/users/${userUuid}/widgets/stt/language/subscribe/0`, method: 'PATCH' }); } async allowStartCaption(params) { const { roomUuid, enable, targetRoles } = params; return await this._client.fetch({ path: `/v1/rooms/${roomUuid}/security/caption/${enable ? 1 : 0}`, method: 'PUT', data: { targetRoles } }); } async allowStartTranscribing(params) { const { roomUuid, enable, targetRoles } = params; return await this._client.fetch({ path: `/v1/rooms/${roomUuid}/security/transcribe/${enable ? 1 : 0}`, method: 'PUT', data: { targetRoles } }); } async allowUpdateSttSourceLanguage(params) { const { roomUuid, enable, targetRoles } = params; return await this._client.fetch({ path: `/v1/rooms/${roomUuid}/security/stt/${enable ? 1 : 0}`, method: 'PUT', data: { targetRoles, payload: { modify: enable ? 1 : 0 } } }); } } exports.FcrCoreServiceApi = FcrCoreServiceApi;