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,

142 lines (141 loc) 5.23 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 { TRTCVideoMirrorType, TRTCVideoRotation, TRTCVideoFillMode, TUIMediaDeviceType } from "@tencentcloud/tuiroom-engine-js"; import useRoomEngine from "../../../hooks/useRoomEngine.mjs"; import useDeviceManager from "../../../hooks/useDeviceManager.mjs"; import i18n from "../../../locales/index.mjs"; import MessageBox from "../../../components/common/base/MessageBox/index.mjs"; import renderMsg from "../../../components/common/base/Message/Message.mjs"; import { isWeChat } from "../../../utils/environment.mjs"; import { MediaDeviceState } from "../../type/MediaDeviceSetting.mjs"; import { WARNING_MESSAGE, MESSAGE_DURATION } from "../../../constants/message.mjs"; import "../../../services/main.mjs"; import { roomService } from "../../../services/roomService.mjs"; import "mitt"; import "../../../services/manager/roomActionManager.mjs"; import "@tencentcloud/tui-core"; import useVideoDeviceManagerState, { isCameraListInitiated } from "./videoDeviceManagerState.mjs"; import { initMediaDeviceList } from "./videoDeviceListHandler.mjs"; const { t } = i18n.global; const roomEngine = useRoomEngine(); const deviceManager = useDeviceManager(); const { currentCameraDevice, isFrontCamera, cameraState, isCameraTesting, isCameraTestLoading, localVideoQuality } = useVideoDeviceManagerState(); const _Camera = class _Camera { constructor() { if (!_Camera.instance) { _Camera.instance = this; } return _Camera.instance; } async startCameraDeviceTest(options) { var _a; if (!isCameraListInitiated) { await initMediaDeviceList(); } isCameraTestLoading.value = true; try { await ((_a = deviceManager.instance) == null ? void 0 : _a.startCameraDeviceTest(options)); isCameraTestLoading.value = false; isCameraTesting.value = true; } catch (error) { isCameraTestLoading.value = false; } } async stopCameraDeviceTest() { var _a; isCameraTestLoading.value = false; await ((_a = deviceManager.instance) == null ? void 0 : _a.stopCameraDeviceTest()); isCameraTesting.value = false; } async switchCamera(options) { var _a; await ((_a = deviceManager.instance) == null ? void 0 : _a.switchCamera(options)); isFrontCamera.value = options.isFrontCamera; } async switchMirror(options) { var _a; const trtcCloud = (_a = roomEngine.instance) == null ? void 0 : _a.getTRTCCloud(); trtcCloud == null ? void 0 : trtcCloud.setLocalRenderParams({ mirrorType: options.mirror ? TRTCVideoMirrorType.TRTCVideoMirrorType_Enable : TRTCVideoMirrorType.TRTCVideoMirrorType_Disable, rotation: TRTCVideoRotation.TRTCVideoRotation0, fillMode: TRTCVideoFillMode.TRTCVideoFillMode_Fill }); } async updateVideoQuality(options) { var _a; await ((_a = roomEngine.instance) == null ? void 0 : _a.updateVideoQuality(options)); localVideoQuality.value = options.quality; } async openLocalCamera() { var _a; if (cameraState.value === MediaDeviceState.NotSupportCapture && !isWeChat) { MessageBox({ title: t("Note"), message: t("The current browser does not support capturing video"), confirmButtonText: t("Sure") }); return; } if (cameraState.value === MediaDeviceState.NoDeviceDetected && !isWeChat) { MessageBox({ title: t("Note"), message: t("Camera not detected on current device"), confirmButtonText: t("Sure") }); return; } if (cameraState.value === MediaDeviceState.DeviceOffAndDisabled) { let warningMessage = ""; if (roomService.roomStore.isAudience) { warningMessage = WARNING_MESSAGE.UNMUTE_LOCAL_CAMERA_FAIL_AUDIENCE; } else if (roomService.roomStore.isCameraDisableForAllUser) { warningMessage = WARNING_MESSAGE.UNMUTE_LOCAL_CAMERA_FAIL_MUTE_ALL; } renderMsg({ type: "warning", message: t(warningMessage), duration: MESSAGE_DURATION.NORMAL }); return; } { await ((_a = roomEngine.instance) == null ? void 0 : _a.openLocalCamera({ isFrontCamera: isFrontCamera.value })); } } async closeLocalCamera() { var _a; await ((_a = roomEngine.instance) == null ? void 0 : _a.closeLocalCamera()); } async setCurrentDevice(options) { var _a, _b; const { deviceId } = options; await ((_a = deviceManager.instance) == null ? void 0 : _a.setCurrentDevice({ type: TUIMediaDeviceType.kMediaDeviceTypeVideoCamera, deviceId })); currentCameraDevice.value = (_b = deviceManager.instance) == null ? void 0 : _b.getCurrentDevice({ type: TUIMediaDeviceType.kMediaDeviceTypeVideoCamera }); } }; __publicField(_Camera, "instance"); let Camera = _Camera; const camera = new Camera(); function useVideoDeviceManager() { return { camera }; } export { useVideoDeviceManager as default };