UNPKG

@tencentcloud/roomkit-web-vue3

Version:

<h1 align="center"> TUIRoomKit</h1> Conference (TUIRoomKit) is a product suitable for multi-person audio and video conversation scenarios such as business meetings, webinars, and online education. By integrating this product, you can add room management,

168 lines (167 loc) 6.19 kB
var __defProp = Object.defineProperty; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); import useRoomEngine from "../../hooks/useRoomEngine.mjs"; import { TRTCVideoEncParam, TRTCVideoResolution, TUIMediaDevice } from "@tencentcloud/tuiroom-engine-js"; import { isMobile, isWeChat } from "../../utils/environment.mjs"; import RoomEventManager from "./roomEventManager.mjs"; import UserEventManager from "./userEventManger.mjs"; import RequestEventManager from "./requestEventManger.mjs"; import { RoomState } from "../type/Room.mjs"; const roomEngine = useRoomEngine(); const _RoomManager = class _RoomManager { constructor(options) { __publicField(this, "store"); if (!_RoomManager.instance) { _RoomManager.instance = this; this.store = options.store; new RoomEventManager(options); new UserEventManager(options); new RequestEventManager(options); } return _RoomManager.instance; } async createRoom(params) { var _a; try { this.store.setRoomState(RoomState.Loading); await ((_a = roomEngine.instance) == null ? void 0 : _a.createRoom(params)); this.store.setRoomState(RoomState.Running); } catch (error) { } } async enterRoom(params) { var _a; try { const roomInfo = await ((_a = roomEngine.instance) == null ? void 0 : _a.enterRoom(params)); this.disableSmallVideoStreamForH5(); return roomInfo; } catch (error) { console.error("error"); throw error; } } // 兼容情况,H5 不开启小流逻辑 disableSmallVideoStreamForH5() { var _a; const isH5 = isMobile && !isWeChat; const smallParam = new TRTCVideoEncParam(); smallParam.videoResolution = TRTCVideoResolution.TRTCVideoResolution_640_360; smallParam.videoFps = 10; smallParam.videoBitrate = 550; const trtcCloud = (_a = roomEngine.instance) == null ? void 0 : _a.getTRTCCloud(); trtcCloud == null ? void 0 : trtcCloud.enableSmallVideoStream(!isH5, smallParam); } async leaveRoom() { var _a; await ((_a = roomEngine.instance) == null ? void 0 : _a.exitRoom()); this.store.resetStore(); } async destroyRoom() { var _a; await ((_a = roomEngine.instance) == null ? void 0 : _a.destroyRoom()); this.store.resetStore(); } async fetchRoomInfo() { var _a; const roomInfo = await ((_a = roomEngine.instance) == null ? void 0 : _a.fetchRoomInfo()); roomInfo && this.store.setRoomInfo(roomInfo); return roomInfo; } async updateRoomNameByAdmin(options) { var _a; await ((_a = roomEngine.instance) == null ? void 0 : _a.updateRoomNameByAdmin(options)); this.store.setRoomInfo({ roomName: options.roomName }); } async updateRoomSeatModeByAdmin(options) { var _a; await ((_a = roomEngine.instance) == null ? void 0 : _a.updateRoomSeatModeByAdmin(options)); this.store.setRoomInfo({ seatMode: options.seatMode }); } async updateRoomPasswordByAdmin(options) { var _a; await ((_a = roomEngine.instance) == null ? void 0 : _a.updateRoomPasswordByAdmin(options)); this.store.setRoomInfo({ password: options.password }); } async disableDeviceForAllUserByAdmin(options) { var _a; await ((_a = roomEngine.instance) == null ? void 0 : _a.disableDeviceForAllUserByAdmin(options)); const { device, isDisable } = options; switch (device) { case TUIMediaDevice.kCamera: this.store.setRoomInfo({ isCameraDisableForAllUser: isDisable }); break; case TUIMediaDevice.kMicrophone: this.store.setRoomInfo({ isMicrophoneDisableForAllUser: isDisable }); break; case TUIMediaDevice.kScreen: this.store.setRoomInfo({ isScreenShareDisableForAllUser: isDisable }); break; } } async disableSendingMessageForAllUser(options) { var _a; await ((_a = roomEngine.instance) == null ? void 0 : _a.disableSendingMessageForAllUser(options)); this.store.setRoomInfo({ isMessageDisableForAllUser: options.isDisable }); } async changeUserRole(options) { var _a; await ((_a = roomEngine.instance) == null ? void 0 : _a.changeUserRole(options)); this.store.updateUserInfo(options); } async closeRemoteDeviceByAdmin(options) { var _a; await ((_a = roomEngine.instance) == null ? void 0 : _a.closeRemoteDeviceByAdmin(options)); } async openRemoteDeviceByAdmin(options) { var _a; const { userId, device, timeout, requestCallback } = options; const request = await ((_a = roomEngine.instance) == null ? void 0 : _a.openRemoteDeviceByAdmin({ userId, device, timeout, requestCallback: (callbackInfo) => { const currentUserInfo = this.store.getUserInfo({ userId }); if (request == null ? void 0 : request.requestId) { delete currentUserInfo.receivedRequestObj[request == null ? void 0 : request.requestId]; } requestCallback && requestCallback(callbackInfo); } })); if (request && request.requestId) { const currentUserInfo = this.store.getUserInfo({ userId }); currentUserInfo.receivedRequestObj[request.requestId] = request; } return request; } async disableSendingMessageByAdmin(options) { var _a; await ((_a = roomEngine.instance) == null ? void 0 : _a.disableSendingMessageByAdmin(options)); this.store.updateUserInfo({ userId: options.userId, isMessageDisabled: options.isDisable }); } async kickRemoteUserOutOfRoom(options) { var _a; await ((_a = roomEngine.instance) == null ? void 0 : _a.kickRemoteUserOutOfRoom(options)); this.store.removeUserInfo(options.userId); } async changeUserNameCard(options) { var _a; await ((_a = roomEngine.instance) == null ? void 0 : _a.changeUserNameCard(options)); } }; __publicField(_RoomManager, "instance"); let RoomManager = _RoomManager; export { RoomManager as default };