@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.21 kB
JavaScript
;
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const Vue = require("vue");
const room = require("../../stores/room.js");
const pinia = require("pinia");
const index = require("./base/Select/index.vue.js");
const index$1 = require("./base/Option/index.vue.js");
const TUIRoomEngine = require("@tencentcloud/tuiroom-engine-electron");
const useDeviceManager = require("../../hooks/useDeviceManager.js");
const _sfc_main = /* @__PURE__ */ Vue.defineComponent({
__name: "DeviceSelect",
props: {
deviceType: {},
onChange: { type: Function },
disabled: { type: Boolean }
},
setup(__props) {
const { deviceManager } = useDeviceManager.default();
const { deviceType, onChange, disabled = false } = __props;
const roomStore = room.useRoomStore();
const {
cameraList,
microphoneList,
speakerList,
currentCameraId,
currentMicrophoneId,
currentSpeakerId
} = pinia.storeToRefs(roomStore);
const deviceList = Vue.ref(getDeviceList());
const currentDeviceId = Vue.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") {
Vue.watch(
currentCameraId,
(val) => {
if (currentDeviceId.value !== val) {
currentDeviceId.value = val;
}
},
{ immediate: true }
);
}
if (deviceType === "microphone") {
Vue.watch(
currentMicrophoneId,
(val) => {
if (currentDeviceId.value !== val) {
currentDeviceId.value = val;
}
},
{ immediate: true }
);
}
if (deviceType === "speaker") {
Vue.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: TUIRoomEngine.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: TUIRoomEngine.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: TUIRoomEngine.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 Vue.openBlock(), Vue.createBlock(index.default, {
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: Vue.withCtx(() => [
(Vue.openBlock(true), Vue.createElementBlock(Vue.Fragment, null, Vue.renderList(deviceList.value, (item) => {
return Vue.openBlock(), Vue.createBlock(index$1.default, {
key: item.deviceId,
label: item.deviceName,
value: item.deviceId
}, null, 8, ["label", "value"]);
}), 128))
]),
_: 1
}, 8, ["modelValue", "disabled"]);
};
}
});
exports.default = _sfc_main;