@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,
127 lines (126 loc) • 5.29 kB
JavaScript
"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const TUIRoomEngine = require("@tencentcloud/tuiroom-engine-electron");
const useRoomEngine = require("./useRoomEngine.js");
const room = require("../stores/room.js");
const index$2 = require("../utils/common/logger/index.js");
const Vue = require("vue");
const index = require("../locales/index.js");
const index$1 = require("../components/common/base/MessageBox/index.js");
const environment = require("../utils/environment.js");
const roomEngine = useRoomEngine.default();
const deviceManager = {
instance: null
};
TUIRoomEngine.once("ready", () => {
var _a;
deviceManager.instance = (_a = roomEngine.instance) == null ? void 0 : _a.getMediaDeviceManager();
});
function useDeviceManager(options) {
const roomStore = room.useRoomStore();
const { t } = index.default.global;
async function initMediaDeviceList() {
var _a, _b, _c, _d, _e, _f;
if (!deviceManager.instance) {
return;
}
const cameraList = await ((_a = deviceManager.instance) == null ? void 0 : _a.getDevicesList({
type: TUIRoomEngine.TUIMediaDeviceType.kMediaDeviceTypeVideoCamera
}));
const microphoneList = await ((_b = deviceManager.instance) == null ? void 0 : _b.getDevicesList({
type: TUIRoomEngine.TUIMediaDeviceType.kMediaDeviceTypeAudioInput
}));
const speakerList = await ((_c = deviceManager.instance) == null ? void 0 : _c.getDevicesList({
type: TUIRoomEngine.TUIMediaDeviceType.kMediaDeviceTypeAudioOutput
}));
if (!environment.isWeChat) {
const hasCameraDevice = cameraList && cameraList.length > 0;
const hasMicrophoneDevice = microphoneList && microphoneList.length > 0;
let alertMessage = "";
if (hasCameraDevice && !hasMicrophoneDevice) {
alertMessage = "Microphone not detected on current device";
} else if (!hasCameraDevice && hasMicrophoneDevice) {
alertMessage = "Camera not detected on current device";
} else if (!hasCameraDevice && !hasMicrophoneDevice) {
alertMessage = "Camera And Microphone not detected on current device";
}
if (alertMessage) {
index$1.default({
title: t("Note"),
message: t(alertMessage),
confirmButtonText: t("Sure")
});
}
}
cameraList && roomStore.setCameraList(cameraList);
microphoneList && roomStore.setMicrophoneList(microphoneList);
speakerList && roomStore.setSpeakerList(speakerList);
const cameraInfo = (_d = deviceManager.instance) == null ? void 0 : _d.getCurrentDevice({
type: TUIRoomEngine.TUIMediaDeviceType.kMediaDeviceTypeVideoCamera
});
const micInfo = (_e = deviceManager.instance) == null ? void 0 : _e.getCurrentDevice({
type: TUIRoomEngine.TUIMediaDeviceType.kMediaDeviceTypeAudioInput
});
const speakerInfo = (_f = deviceManager.instance) == null ? void 0 : _f.getCurrentDevice({
type: TUIRoomEngine.TUIMediaDeviceType.kMediaDeviceTypeAudioOutput
});
if (cameraInfo && cameraInfo.deviceId) {
roomStore.setCurrentCameraId(cameraInfo.deviceId);
}
if (micInfo && micInfo.deviceId) {
roomStore.setCurrentMicrophoneId(micInfo.deviceId);
}
if (speakerInfo && speakerInfo.deviceId) {
roomStore.setCurrentSpeakerId(speakerInfo.deviceId);
}
}
async function onDeviceChanged(eventInfo) {
var _a, _b;
if (!deviceManager.instance) {
return;
}
const stateList = ["add", "remove", "active"];
const deviceTypeList = ["mic", "speaker", "camera"];
const { deviceId, type, state } = eventInfo;
index$2.default.log(
`onDeviceChanged: deviceId: ${deviceId}, type: ${deviceTypeList[type]}, state: ${stateList[state]}`
);
const deviceList = await ((_a = deviceManager.instance) == null ? void 0 : _a.getDevicesList({ type }));
deviceList && roomStore.setDeviceList(type, deviceList);
if (state === TUIRoomEngine.TUIMediaDeviceState.kMediaDeviceStateActive) {
roomStore.setCurrentDeviceId(type, deviceId);
}
if (environment.isElectron && state === TUIRoomEngine.TUIMediaDeviceState.kMediaDeviceStateRemove && type === TUIRoomEngine.TUIMediaDeviceType.kMediaDeviceTypeVideoCamera) {
const currentCameraInfo = (_b = deviceManager.instance) == null ? void 0 : _b.getCurrentDevice({
type: TUIRoomEngine.TUIMediaDeviceType.kMediaDeviceTypeVideoCamera
});
if (currentCameraInfo && currentCameraInfo.deviceId) {
roomStore.setCurrentCameraId(currentCameraInfo.deviceId);
}
}
}
TUIRoomEngine.once("ready", () => {
var _a;
if (options && options.listenForDeviceChange) {
initMediaDeviceList();
(_a = deviceManager.instance) == null ? void 0 : _a.on(
TUIRoomEngine.TUIRoomDeviceMangerEvents.onDeviceChanged,
onDeviceChanged
);
}
});
Vue.onUnmounted(() => {
var _a;
if (options && options.listenForDeviceChange) {
(_a = deviceManager.instance) == null ? void 0 : _a.off(
TUIRoomEngine.TUIRoomDeviceMangerEvents.onDeviceChanged,
onDeviceChanged
);
}
});
return {
deviceManager,
initMediaDeviceList
};
}
exports.default = useDeviceManager;