UNPKG

@tencentcloud/roomkit-electron-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,

159 lines (158 loc) 5.07 kB
import { defineComponent, ref, watch, createBlock, openBlock, withCtx, createElementBlock, Fragment, renderList } from "vue"; import { useRoomStore } from "../../stores/room.mjs"; import { storeToRefs } from "pinia"; import TuiSelect from "./base/Select/index.vue.mjs"; import TuiOption from "./base/Option/index.vue.mjs"; import { TUIMediaDeviceType } from "@tencentcloud/tuiroom-engine-electron"; import useDeviceManager from "../../hooks/useDeviceManager.mjs"; const _sfc_main = /* @__PURE__ */ defineComponent({ __name: "DeviceSelect", props: { deviceType: {}, onChange: { type: Function }, disabled: { type: Boolean } }, setup(__props) { const { deviceManager } = useDeviceManager(); const { deviceType, onChange, disabled = false } = __props; const roomStore = useRoomStore(); const { cameraList, microphoneList, speakerList, currentCameraId, currentMicrophoneId, currentSpeakerId } = storeToRefs(roomStore); const deviceList = ref(getDeviceList()); const currentDeviceId = ref(getInitDeviceId()); function getInitDeviceId() { if (deviceType === "camera") { return currentCameraId.value; } if (deviceType === "microphone") { return currentMicrophoneId.value; } if (deviceType === "speaker") { return currentSpeakerId.value; } return ""; } if (deviceType === "camera") { watch( currentCameraId, (val) => { if (currentDeviceId.value !== val) { currentDeviceId.value = val; } }, { immediate: true } ); } if (deviceType === "microphone") { watch( currentMicrophoneId, (val) => { if (currentDeviceId.value !== val) { currentDeviceId.value = val; } }, { immediate: true } ); } if (deviceType === "speaker") { watch( currentSpeakerId, (val) => { if (currentDeviceId.value !== val) { currentDeviceId.value = val; } }, { immediate: true } ); } function getDeviceList() { if (deviceType === "camera") { return cameraList; } if (deviceType === "microphone") { return microphoneList; } if (deviceType === "speaker") { return speakerList; } return []; } async function handleChange(deviceId) { var _a, _b, _c; onChange && onChange(deviceId); switch (deviceType) { case "camera": try { await ((_a = deviceManager.instance) == null ? void 0 : _a.setCurrentDevice({ type: TUIMediaDeviceType.kMediaDeviceTypeVideoCamera, deviceId })); roomStore.setCurrentCameraId(deviceId); } catch (error) { if (cameraList.value.map((item) => item.deviceId).includes(currentCameraId.value)) { currentDeviceId.value = currentCameraId.value; } } break; case "microphone": try { await ((_b = deviceManager.instance) == null ? void 0 : _b.setCurrentDevice({ type: TUIMediaDeviceType.kMediaDeviceTypeAudioInput, deviceId })); roomStore.setCurrentMicrophoneId(deviceId); } catch (error) { if (microphoneList.value.map((item) => item.deviceId).includes(currentMicrophoneId.value)) { currentDeviceId.value = currentMicrophoneId.value; } } break; case "speaker": try { await ((_c = deviceManager.instance) == null ? void 0 : _c.setCurrentDevice({ type: TUIMediaDeviceType.kMediaDeviceTypeAudioOutput, deviceId })); roomStore.setCurrentSpeakerId(deviceId); } catch (error) { if (speakerList.value.map((item) => item.deviceId).includes(currentSpeakerId.value)) { currentDeviceId.value = currentSpeakerId.value; } } break; } } return (_ctx, _cache) => { return openBlock(), createBlock(TuiSelect, { modelValue: currentDeviceId.value, "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => currentDeviceId.value = $event), placeholder: "placeholder", class: "select", disabled: _ctx.disabled, teleported: false, "popper-append-to-body": false, onChange: handleChange }, { default: withCtx(() => [ (openBlock(true), createElementBlock(Fragment, null, renderList(deviceList.value, (item) => { return openBlock(), createBlock(TuiOption, { key: item.deviceId, label: item.deviceName, value: item.deviceId }, null, 8, ["label", "value"]); }), 128)) ]), _: 1 }, 8, ["modelValue", "disabled"]); }; } }); export { _sfc_main as default };