UNPKG

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,

426 lines (425 loc) 15.1 kB
"use strict"; 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); Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); const TUIRoomEngine = require("@tencentcloud/tuiroom-engine-js"); const types = require("../types.js"); const environment = require("../../utils/environment.js"); const index$1 = require("../../utils/common/logger/index.js"); require("vue"); require("../../components/common/base/IconButton.vue2.js"); ;/* empty css */ ;/* empty css */ require("../../stores/room.js"); require("pinia"); ;/* empty css */ require("../../hooks/useZIndex.js"); require("../main.js"); require("../roomService.js"); require("../../locales/index.js"); require("mitt"); require("@tencentcloud/tui-core"); ;/* empty css */ ;/* empty css */ ;/* empty css */ ;/* empty css */ ;/* empty css */ const index = require("../../core/hooks/useAudioDeviceState/index.js"); ;/* empty css */ ;/* empty css */ require("@tencentcloud/uikit-base-component-vue3"); ;/* empty css */ require("../../stores/basic.js"); ;/* empty css */ ;/* empty css */ ;/* empty css */ require("../../hooks/useRoomEngine.js"); const index$2 = require("../../core/hooks/useVideoDeviceState/index.js"); ;/* empty css */ ;/* empty css */ ;/* empty css */ ;/* empty css */ ;/* empty css */ ;/* empty css */ ;/* empty css */ const { microphone, speaker } = index.useAudioDeviceState(); const { camera } = index$2.useVideoDeviceState(); const logPrefix = "[RoomService:roomActionManager]"; const smallParam = new TUIRoomEngine.TRTCVideoEncParam(); smallParam.videoResolution = TUIRoomEngine.TRTCVideoResolution.TRTCVideoResolution_640_360; smallParam.videoFps = 10; smallParam.videoBitrate = 550; class RoomActionManager { constructor(service) { __publicField(this, "service"); __publicField(this, "userListNextSequence", 0); __publicField(this, "hasMoreUsers", false); this.service = service; this.onRoomUserCountChanged = this.onRoomUserCountChanged.bind(this); this.bindRoomEngineEvents(); } onRoomUserCountChanged(eventInfo) { this.service.roomStore.setRoomMemberCount(eventInfo.userCount); } bindRoomEngineEvents() { TUIRoomEngine.once("ready", () => { var _a; (_a = this.service.roomEngine.instance) == null ? void 0 : _a.on( TUIRoomEngine.TUIRoomEvents.onRoomUserCountChanged, this.onRoomUserCountChanged ); }); } unbindRoomEngineEvents() { var _a; (_a = this.service.roomEngine.instance) == null ? void 0 : _a.off( TUIRoomEngine.TUIRoomEvents.onRoomUserCountChanged, this.onRoomUserCountChanged ); } async start(roomId, params = {}) { const { roomName, isSeatEnabled = false, isOpenCamera = false, isOpenMicrophone = false, defaultCameraId, defaultMicrophoneId, defaultSpeakerId, password } = params; const roomMode = isSeatEnabled ? "SpeakAfterTakingSeat" : "FreeToSpeak"; this.service.roomStore.resetRoomData(); await this.createRoom({ roomId, roomName, roomMode, roomParam: { isOpenCamera, isOpenMicrophone, defaultCameraId, defaultMicrophoneId, defaultSpeakerId, password } }); await this.enterRoom({ roomId, roomParam: { isOpenCamera, isOpenMicrophone, defaultCameraId, defaultMicrophoneId, defaultSpeakerId, password } }); this.service.emit(types.EventType.ROOM_START, { roomId }); } async join(roomId, params = {}) { const { isOpenCamera = false, isOpenMicrophone = false, defaultCameraId, defaultMicrophoneId, defaultSpeakerId, password } = params; this.service.roomStore.resetRoomData(); await this.enterRoom({ roomId, roomParam: { isOpenCamera, isOpenMicrophone, defaultCameraId, defaultMicrophoneId, defaultSpeakerId, password } }); this.service.emit(types.EventType.ROOM_JOIN, { roomId }); } async leaveRoom() { var _a; try { this.closeMediaBeforeLeave(); const response = await ((_a = this.service.roomEngine.instance) == null ? void 0 : _a.exitRoom()); this.service.resetStore(); index$1.default.log(`${logPrefix}leaveRoom:`, response); this.service.emit(types.EventType.ROOM_LEAVE, response); } catch (error) { index$1.default.error(`${logPrefix}leaveRoom error:`, error); } } async dismissRoom() { var _a; try { index$1.default.log(`${logPrefix}dismissRoom: enter`); this.closeMediaBeforeLeave(); await ((_a = this.service.roomEngine.instance) == null ? void 0 : _a.destroyRoom()); this.service.resetStore(); this.service.emit(types.EventType.ROOM_DISMISS, {}); } catch (error) { index$1.default.error(`${logPrefix}dismissRoom error:`, error); } } async createRoom(options) { try { const { roomId, roomName, roomMode, roomParam } = options; const roomParams = { roomId, roomName, roomType: TUIRoomEngine.TUIRoomType.kConference, isSeatEnabled: roomMode !== "FreeToSpeak", seatMode: roomMode === "SpeakAfterTakingSeat" ? TUIRoomEngine.TUISeatMode.kApplyToTake : void 0, password: (roomParam == null ? void 0 : roomParam.password) || "" }; await this.handleRoomCreation(roomParams, options); } catch (error) { index$1.default.error(`${logPrefix}createRoom error:`, error); this.service.errorHandler.handleError(error, "createRoom"); throw error; } } async handleRoomCreation(roomParams, options) { var _a; const { roomEngine } = this.service; if (!roomEngine.instance) { return; } this.service.basicStore.setRoomId(roomParams.roomId); index$1.default.debug(`${logPrefix}createRoom:`, roomParams, options); await ((_a = roomEngine.instance) == null ? void 0 : _a.createRoom(roomParams)); } async enterRoom(options) { var _a; try { const { roomId, roomParam } = options; const roomInfo = await this.doEnterRoom({ roomId, roomType: TUIRoomEngine.TUIRoomType.kConference, password: (roomParam == null ? void 0 : roomParam.password) || "" }); this.service.roomStore.setRoomInfo(roomInfo); await this.syncUserInfo(this.service.basicStore.userId); await this.fetchAttendeeList(roomId); await this.getInvitationList(roomId); if (roomInfo.isSeatEnabled) { await this.getSeatList(); this.service.roomStore.isMaster && await ((_a = this.service.roomEngine.instance) == null ? void 0 : _a.takeSeat({ seatIndex: -1, timeout: 0 })); } this.setRoomParams(roomParam); } catch (error) { index$1.default.error(`${logPrefix}enterRoom error:`, error); this.service.errorHandler.handleError(error, "enterRoom"); throw error; } } async setRoomParams(roomParam) { if (!roomParam) { return; } const { isOpenCamera, isOpenMicrophone, defaultCameraId, defaultMicrophoneId, defaultSpeakerId } = roomParam; if (defaultCameraId) { camera.setCurrentDevice({ deviceId: defaultCameraId }); } if (defaultMicrophoneId) { microphone.setCurrentDevice({ deviceId: defaultMicrophoneId }); } if (defaultSpeakerId) { speaker.setCurrentDevice({ deviceId: defaultSpeakerId }); } const { isMaster, isMicrophoneDisableForAllUser, isCameraDisableForAllUser, isFreeSpeakMode } = this.service.roomStore; const isCanOpenMicrophone = isMaster || !isMicrophoneDisableForAllUser && isFreeSpeakMode; if (isCanOpenMicrophone) { if (isOpenMicrophone) { await microphone.openLocalMicrophone(); await microphone.unmuteLocalAudio(); } else { await microphone.muteLocalAudio(); } } const isCanOpenCamera = isMaster || !isCameraDisableForAllUser && isFreeSpeakMode; if (isCanOpenCamera && isOpenCamera) { camera.openLocalCamera(); } } async doEnterRoom(params) { var _a, _b; const { roomEngine } = this.service; const { roomId, roomType, password } = params; this.service.basicStore.setRoomId(roomId); const isH5 = !environment.isWeChat; const trtcCloud = (_a = roomEngine.instance) == null ? void 0 : _a.getTRTCCloud(); trtcCloud == null ? void 0 : trtcCloud.setDefaultStreamRecvMode(true, false); const roomInfo = await ((_b = roomEngine.instance) == null ? void 0 : _b.enterRoom({ roomId, roomType, options: { password } })); trtcCloud == null ? void 0 : trtcCloud.enableSmallVideoStream(!isH5, smallParam); microphone.muteLocalAudio(); if (!roomInfo.isSeatEnabled) { microphone.openLocalMicrophone(); } return roomInfo; } async getUserList() { var _a; const { roomEngine } = this.service; try { const result = await ((_a = roomEngine.instance) == null ? void 0 : _a.getUserList({ nextSequence: 0 })); result.userInfoList.forEach((user) => { this.service.roomStore.addUserInfo( Object.assign(user, { isInRoom: true }) ); if (this.service.roomStore.isFreeSpeakMode) { this.service.roomStore.addStreamInfo( user.userId, TUIRoomEngine.TUIVideoStreamType.kCameraStream ); } }); this.userListNextSequence = result.nextSequence; this.hasMoreUsers = result.nextSequence !== 0; } catch (error) { index$1.default.error("TUIRoomEngine.getUserList", error.code, error.message); } } async loadMoreUsers() { var _a; if (!this.hasMoreUsers) return; const { roomEngine } = this.service; try { const result = await ((_a = roomEngine.instance) == null ? void 0 : _a.getUserList({ nextSequence: this.userListNextSequence })); result.userInfoList.forEach((user) => { this.service.roomStore.addUserInfo( Object.assign(user, { isInRoom: true }) ); if (this.service.roomStore.isFreeSpeakMode) { this.service.roomStore.addStreamInfo( user.userId, TUIRoomEngine.TUIVideoStreamType.kCameraStream ); } }); this.userListNextSequence = result.nextSequence; this.hasMoreUsers = result.nextSequence !== 0; } catch (error) { index$1.default.error("TUIRoomEngine.loadMoreUsers", error.code, error.message); } } async getInvitationList(roomId, cursor = "", result = []) { const res = await this.service.conferenceInvitationManager.getInvitationList({ roomId, cursor, count: 20 }); if (!(res == null ? void 0 : res.invitationList)) return []; result.push(...res == null ? void 0 : res.invitationList); if (res.cursor !== "") { await this.getInvitationList(roomId, res.cursor, result); } const list = result.map(({ invitee, status }) => ({ ...invitee, status })); this.service.roomStore.updateInviteeList(list); } async fetchAttendeeList(roomId, cursor = "", result = []) { const res = await this.service.scheduleConferenceManager.fetchAttendeeList({ roomId, cursor, count: 20 }); if (!(res == null ? void 0 : res.attendeeList)) return []; result.push(...res == null ? void 0 : res.attendeeList); if (res.cursor !== "") { await this.fetchAttendeeList(roomId, res.cursor, result); } const inviteeList = result.filter((user) => { return !this.service.roomStore.userList.some( (item) => item.userId === user.userId ); }); this.service.roomStore.updateInviteeList(inviteeList); } async syncUserInfo(userId) { var _a; const { roomEngine } = this.service; const userInfo = await ((_a = roomEngine.instance) == null ? void 0 : _a.getUserInfo({ userId })); const { isMessageDisabled } = userInfo; this.service.chatStore.setSendMessageDisableChanged(isMessageDisabled); } async getSeatList() { var _a; const { roomEngine } = this.service; try { const seatList = await ((_a = roomEngine.instance) == null ? void 0 : _a.getSeatList()); await Promise.all( seatList.map(async (seat) => { var _a2; const { userId } = seat; if (!userId) { return; } const user = this.service.roomStore.userInfoObj[userId]; if (user && user.userName) { this.service.roomStore.updateUserInfo({ userId, onSeat: true }); } else { const userInfo = await ((_a2 = roomEngine.instance) == null ? void 0 : _a2.getUserInfo({ userId })); this.service.roomStore.addUserInfo( Object.assign(userInfo, { onSeat: true, isInRoom: true }) ); } this.service.roomStore.addStreamInfo( userId, TUIRoomEngine.TUIVideoStreamType.kCameraStream ); }) ); } catch (error) { index$1.default.error("TUIRoomEngine.getSeatList", error.code, error.message); } } closeMediaBeforeLeave() { var _a, _b; const { roomEngine } = this.service; if (this.service.roomStore.localUser.hasAudioStream) { (_a = roomEngine.instance) == null ? void 0 : _a.closeLocalMicrophone(); } if (this.service.roomStore.localUser.hasVideoStream) { (_b = roomEngine.instance) == null ? void 0 : _b.closeLocalCamera(); } } async fetchRoomInfo(options) { var _a; return await ((_a = this.service.roomEngine.instance) == null ? void 0 : _a.fetchRoomInfo(options)); } } exports.RoomActionManager = RoomActionManager;