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,

457 lines (456 loc) 15.5 kB
import { defineStore } from "pinia"; import { TUISeatMode, TUIRole, TUIVideoStreamType, TUIInvitationStatus } from "@tencentcloud/tuiroom-engine-js"; import { useBasicStore } from "./basic.mjs"; import { set, del } from "../utils/vue.mjs"; import "../services/main.mjs"; import { roomService } from "../services/roomService.mjs"; import "../locales/index.mjs"; import "../utils/environment.mjs"; import "mitt"; import "../services/manager/roomActionManager.mjs"; import "@tencentcloud/tui-core"; function getNewStreamInfo(userId, streamType) { const newStreamInfo = { userId, hasAudioStream: false, hasVideoStream: false, streamType: streamType || TUIVideoStreamType.kCameraStream, isLoading: false, playDomMap: /* @__PURE__ */ new Map(), timestamp: Date.now() }; return newStreamInfo; } function getNewUserInfo(userId) { const newUserInfo = { userId, userName: "", avatarUrl: "", nameCard: "", hasAudioStream: false, hasVideoStream: false, hasScreenStream: false, isMessageDisabled: false, userRole: TUIRole.kGeneralUser, onSeat: false, isUserApplyingToAnchor: false, isInvitingUserToAnchor: false, isInRoom: false, status: TUIInvitationStatus.kNone, timestamp: Date.now() }; return newUserInfo; } function getRecordStreamType(streamType) { if (streamType === TUIVideoStreamType.kCameraStreamLow) { return TUIVideoStreamType.kCameraStream; } return streamType; } const useRoomStore = defineStore("room", { state: () => ({ userInfoObj: {}, streamInfoObj: {}, userVolumeObj: {}, currentSpeakerInfo: { speakerUserId: "", remoteSpeakerUserId: "" }, masterUserId: "", isMicrophoneDisableForAllUser: false, isCameraDisableForAllUser: false, isScreenShareDisableForAllUser: false, isSeatEnabled: void 0, seatMode: TUISeatMode.kFreeToTake, maxMembersCount: 5, // Includes local streams and screen shares, above which subsequent streams are played maxSeatCount: 20, password: "", roomName: "", isOnStateTabActive: true, isLocalUserSharing: false, isWhiteboardVisible: false, isSharingScreen: false, isAnnotationVisible: false }), getters: { localUser(state) { const basicStore = useBasicStore(); return state.userInfoObj[basicStore.userId] || getNewUserInfo(basicStore.userId); }, localStream(state) { const basicStore = useBasicStore(); if (this.isFreeSpeakMode || this.localUser.onSeat) { return state.streamInfoObj[`${basicStore.userId}_${TUIVideoStreamType.kCameraStream}`] || getNewStreamInfo(basicStore.userId, TUIVideoStreamType.kCameraStream); } }, localScreenStream(state) { const basicStore = useBasicStore(); return state.streamInfoObj[`${basicStore.userId}_${TUIVideoStreamType.kScreenStream}`]; }, isMaster(state) { return this.localUser.userId === state.masterUserId; }, isAdmin() { return this.localUser.userRole === TUIRole.kAdministrator; }, isGeneralUser() { return this.localUser.userRole === TUIRole.kGeneralUser; }, isFreeSpeakMode() { return this.isSeatEnabled === false; }, isSpeakAfterTakingSeatMode() { return Boolean(this.isSeatEnabled) && this.seatMode === TUISeatMode.kApplyToTake; }, // Whether the current user is on the stage isAnchor() { if (this.isFreeSpeakMode) { return true; } if (this.isSpeakAfterTakingSeatMode) { return this.localUser.onSeat; } }, // Whether the current user is under the stage isAudience() { if (this.isFreeSpeakMode) { return false; } if (this.isSpeakAfterTakingSeatMode) { return !this.localUser.onSeat; } }, streamList() { let streamList = []; if (this.isFreeSpeakMode) { streamList = Object.values(this.streamInfoObj); } else { streamList = Object.values(this.streamInfoObj).filter((item) => { return this.userInfoObj[item.userId].onSeat; }); } return streamList.sort( roomService.userManager.getStreamListSortComparator() ); }, remoteStreamList() { const basicStore = useBasicStore(); return this.streamList.filter((item) => item.userId !== basicStore.userId); }, cameraStreamList() { return this.streamList.filter( (stream) => stream.streamType === TUIVideoStreamType.kCameraStream ); }, remoteScreenStream() { return this.remoteStreamList.find( (stream) => stream.streamType === TUIVideoStreamType.kScreenStream && stream.hasVideoStream ); }, streamNumber() { return this.streamList.length; }, userList() { return [...Object.values(this.userInfoObj)].sort( roomService.userManager.getUserListSortComparator() ); }, userNumber() { return this.userList.filter((item) => item.isInRoom).length; }, remoteUserList() { const basicStore = useBasicStore(); return [...Object.values(this.userInfoObj)].filter( (item) => item.userId !== basicStore.userId ); }, remoteEnteredUserList() { return this.remoteUserList.filter((item) => item.isInRoom); }, remoteNotEnteredUserList() { return this.userList.filter((item) => !item.isInRoom); }, remoteAnchorList() { return this.remoteUserList.filter((item) => item.onSeat); }, generalUserScreenStreamList() { return this.remoteUserList.filter( (item) => item.hasScreenStream && item.userRole === TUIRole.kGeneralUser ); }, anchorUserList() { return this.userList.filter((item) => item.onSeat); }, applyToAnchorList() { return this.remoteUserList.filter((item) => item.isUserApplyingToAnchor).sort( (item1, item2) => ((item1 == null ? void 0 : item1.applyToAnchorTimestamp) || 0) - ((item2 == null ? void 0 : item2.applyToAnchorTimestamp) || 0) ) || []; }, defaultStreamType() { return Object.values(this.streamInfoObj).filter( (stream) => stream.hasVideoStream ).length > this.maxMembersCount ? TUIVideoStreamType.kCameraStreamLow : TUIVideoStreamType.kCameraStream; }, getDisplayName() { return (userId) => { const userInfo = this.userInfoObj[userId]; if (userInfo) { const { nameCard, userName, userId: userId2 } = userInfo; return nameCard || userName || userId2; } return userId; }; } }, actions: { getUserName(userId) { var _a, _b; return ((_a = this.userInfoObj[userId]) == null ? void 0 : _a.nameCard) || ((_b = this.userInfoObj[userId]) == null ? void 0 : _b.userName) || userId; }, getUserRole(userId) { var _a; return (_a = this.userInfoObj[userId]) == null ? void 0 : _a.userRole; }, addUserInfo(userInfo) { const { userId } = userInfo; if (!userId) { return; } if (this.userInfoObj[userId]) { Object.assign(this.userInfoObj[userId], userInfo); } else { const newUserInfo = Object.assign(getNewUserInfo(userId), userInfo); set(this.userInfoObj, userId, newUserInfo); } }, // todo: can use addUserInfo instead addRemoteUser(userInfo) { const { userId } = userInfo; const basicStore = useBasicStore(); if (!userId || userId === basicStore.userId) { return; } if (this.userInfoObj[userId]) { Object.assign(this.userInfoObj[userId], userInfo, { isInRoom: true }); } else { const newUserInfo = Object.assign(getNewUserInfo(userId), userInfo, { isInRoom: true }); set(this.userInfoObj, userId, newUserInfo); } }, updateUserInfo(userInfo) { if (!userInfo.userId) { return; } Object.assign(this.userInfoObj[userInfo.userId], userInfo); }, removeUserInfo(userId) { const basicStore = useBasicStore(); if (!userId || userId === basicStore.userId) { return; } if (this.userInfoObj[userId]) { del(this.userInfoObj, userId); } }, addStreamInfo(userId, streamType) { const recordStreamType = getRecordStreamType(streamType); if (this.streamInfoObj[`${userId}_${recordStreamType}`]) { return; } const newStreamInfo = getNewStreamInfo(userId, recordStreamType); set(this.streamInfoObj, `${userId}_${recordStreamType}`, newStreamInfo); }, updateStreamInfo(streamInfo) { const { userId, streamType } = streamInfo; const recordStreamType = getRecordStreamType(streamType); if (!this.streamInfoObj[`${userId}_${recordStreamType}`]) { return; } if (streamType !== recordStreamType) { Object.assign(streamInfo, { streamType: recordStreamType }); } set( this.streamInfoObj, `${userId}_${recordStreamType}`, Object.assign( this.streamInfoObj[`${userId}_${recordStreamType}`], streamInfo ) ); }, removeStreamInfo(userId, streamType) { const recordStreamType = getRecordStreamType(streamType); if (this.streamInfoObj[`${userId}_${recordStreamType}`]) { del(this.streamInfoObj, `${userId}_${recordStreamType}`); } }, getStreamInfo(userId, streamType) { const recordStreamType = getRecordStreamType(streamType); if (this.streamInfoObj[`${userId}_${recordStreamType}`]) { return this.streamInfoObj[`${userId}_${recordStreamType}`]; } }, setAudioVolume(audioVolumeArray) { const basicStore = useBasicStore(); audioVolumeArray.forEach((audioVolumeItem) => { let { userId } = audioVolumeItem; const { volume } = audioVolumeItem; if (userId === "") { userId = basicStore.userId; } set(this.userVolumeObj, userId, volume); }); }, setCurrentSpeakerInfo(speakerInfo) { Object.assign(this.currentSpeakerInfo, speakerInfo); }, setRoomInfo(roomInfo) { if (!roomInfo) return; const { roomOwner = this.masterUserId, isMicrophoneDisableForAllUser = this.isMicrophoneDisableForAllUser, isCameraDisableForAllUser = this.isCameraDisableForAllUser, isScreenShareDisableForAllUser = this.isScreenShareDisableForAllUser, isSeatEnabled = this.isSeatEnabled, seatMode = this.seatMode, maxSeatCount = this.maxSeatCount, password = this.password, roomName = this.roomName } = roomInfo; if (this.localUser.userId === roomOwner) { this.localUser.userRole = TUIRole.kRoomOwner; } this.masterUserId = roomOwner; this.isMicrophoneDisableForAllUser = isMicrophoneDisableForAllUser; this.isCameraDisableForAllUser = isCameraDisableForAllUser; this.isScreenShareDisableForAllUser = isScreenShareDisableForAllUser; this.isSeatEnabled = isSeatEnabled; this.seatMode = seatMode; this.maxSeatCount = maxSeatCount; this.password = password; this.roomName = roomName; }, setDisableMicrophoneForAllUserByAdmin(isDisable) { this.isMicrophoneDisableForAllUser = isDisable; }, setDisableCameraForAllUserByAdmin(isDisable) { this.isCameraDisableForAllUser = isDisable; }, setDisableScreenShareForAllUserByAdmin(isDisable) { this.isScreenShareDisableForAllUser = isDisable; }, setMasterUserId(userId) { this.masterUserId = userId; }, // Moderator individually modifies the mute status of a user's outgoing text messages setMuteUserChat(userId, muted) { const remoteUserInfo = this.userInfoObj[userId]; if (remoteUserInfo) { remoteUserInfo.isMessageDisabled = muted; } }, setRemoteUserRole(userId, role) { const remoteUserInfo = this.userInfoObj[userId]; if (remoteUserInfo) { remoteUserInfo.userRole = role; } }, setRequestUserOpenMic(options) { const { userId, isRequesting, requestId } = options; const remoteUserInfo = this.userInfoObj[userId]; if (remoteUserInfo) { remoteUserInfo.isRequestingUserOpenMic = isRequesting; remoteUserInfo.requestUserOpenMicRequestId = isRequesting ? requestId : ""; } }, setRequestUserOpenCamera(options) { const { userId, isRequesting, requestId } = options; const remoteUserInfo = this.userInfoObj[userId]; if (remoteUserInfo) { remoteUserInfo.isRequestingUserOpenCamera = isRequesting; remoteUserInfo.requestUserOpenCameraRequestId = isRequesting ? requestId : ""; } }, addApplyToAnchorUser(options) { const { userId, requestId, timestamp } = options; const remoteUserInfo = this.userInfoObj[userId]; if (remoteUserInfo) { remoteUserInfo.isUserApplyingToAnchor = true; remoteUserInfo.applyToAnchorRequestId = requestId; remoteUserInfo.applyToAnchorTimestamp = timestamp; } }, removeApplyToAnchorUser(requestId) { const applyToAnchorItem = Object.values(this.userInfoObj).find( (item) => item.isUserApplyingToAnchor && item.applyToAnchorRequestId === requestId ); if (applyToAnchorItem) { applyToAnchorItem.isUserApplyingToAnchor = false; applyToAnchorItem.applyToAnchorRequestId = ""; applyToAnchorItem.applyToAnchorTimestamp = 0; } }, addInviteToAnchorUser(options) { const { userId, requestId } = options; const remoteUserInfo = this.userInfoObj[userId]; if (remoteUserInfo) { remoteUserInfo.isInvitingUserToAnchor = true; remoteUserInfo.inviteToAnchorRequestId = requestId; } }, removeInviteToAnchorUser(userId) { const remoteUserInfo = this.userInfoObj[userId]; if (remoteUserInfo) { remoteUserInfo.isInvitingUserToAnchor = false; remoteUserInfo.inviteToAnchorRequestId = ""; } }, setOnStageTabStatus(isOnStateTabActive) { this.isOnStateTabActive = isOnStateTabActive; }, updateInviteeList(userList) { userList.forEach((user) => { if (this.userInfoObj[user.userId]) { Object.assign(this.userInfoObj[user.userId], user); } else { const newUserInfo = Object.assign(getNewUserInfo(user.userId), user); set(this.userInfoObj, user.userId, newUserInfo); } }); }, reset() { this.resetRoomData(); }, resetRoomData() { this.streamInfoObj = {}; this.userInfoObj = {}; this.userVolumeObj = {}; this.currentSpeakerInfo = { speakerUserId: "", remoteSpeakerUserId: "" }; this.masterUserId = ""; this.isMicrophoneDisableForAllUser = false; this.isCameraDisableForAllUser = false; this.isScreenShareDisableForAllUser = false; this.isSeatEnabled = void 0; this.seatMode = TUISeatMode.kFreeToTake; this.isOnStateTabActive = true; this.maxSeatCount = 20; this.password = ""; this.roomName = ""; this.isLocalUserSharing = false; this.isWhiteboardVisible = false; this.isSharingScreen = false; this.isAnnotationVisible = false; } } }); export { getNewStreamInfo, getNewUserInfo, useRoomStore };