@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,
203 lines (202 loc) • 7.58 kB
JavaScript
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);
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const TUIRoomEngine = require("@tencentcloud/tuiroom-engine-js");
const MediaDeviceSetting = require("../../type/MediaDeviceSetting.js");
const useRoomEngine = require("../../../hooks/useRoomEngine.js");
const useDeviceManager = require("../../../hooks/useDeviceManager.js");
const environment = require("../../../utils/environment.js");
const index = require("../../../components/common/base/MessageBox/index.js");
const uikitBaseComponentVue3 = require("@tencentcloud/uikit-base-component-vue3");
const index$1 = require("../../../locales/index.js");
const message = require("../../../constants/message.js");
require("../../../services/main.js");
const roomService = require("../../../services/roomService.js");
require("mitt");
require("../../../services/manager/roomActionManager.js");
require("@tencentcloud/tui-core");
const audioDeviceManagerState = require("./audioDeviceManagerState.js");
const {
microphoneState,
currentMicrophoneDevice,
currentMicrophoneId,
currentSpeakerDevice,
currentSpeakerId,
isMicrophoneTesting,
isSpeakerTesting,
currentAudioRoute
} = audioDeviceManagerState.default();
const roomEngine = useRoomEngine.default();
const deviceManager = useDeviceManager.default();
const { t } = index$1.default.global;
const _Microphone = class _Microphone {
constructor() {
if (!_Microphone.instance) {
_Microphone.instance = this;
}
return _Microphone.instance;
}
onTestMicVolume(options) {
audioDeviceManagerState.testAudioVolume.value = options.volume;
}
async startMicDeviceTest(options) {
var _a, _b;
await ((_a = roomEngine.instance) == null ? void 0 : _a.startMicDeviceTest(options));
isMicrophoneTesting.value = true;
(_b = deviceManager.instance) == null ? void 0 : _b.on(
TUIRoomEngine.TUIRoomDeviceMangerEvents.onTestMicVolume,
this.onTestMicVolume
);
}
async stopMicDeviceTest() {
var _a, _b;
await ((_a = roomEngine.instance) == null ? void 0 : _a.stopMicDeviceTest());
isMicrophoneTesting.value = false;
(_b = deviceManager.instance) == null ? void 0 : _b.off(
TUIRoomEngine.TUIRoomDeviceMangerEvents.onTestMicVolume,
this.onTestMicVolume
);
}
async checkMicrophonePermission() {
const audioStream = await navigator.mediaDevices.getUserMedia({
audio: { deviceId: currentMicrophoneId.value }
});
audioStream.getAudioTracks()[0].stop();
}
async openLocalMicrophone() {
var _a;
if (microphoneState.value === MediaDeviceSetting.MediaDeviceState.NotSupportCapture && !environment.isWeChat) {
index.default({
title: t("Note"),
message: t("The current browser does not support capturing audio"),
confirmButtonText: t("Sure")
});
return;
}
if (microphoneState.value === MediaDeviceSetting.MediaDeviceState.NoDeviceDetected && !environment.isWeChat) {
index.default({
title: t("Note"),
message: t("Microphone not detected on current device"),
confirmButtonText: t("Sure")
});
return;
}
try {
await this.checkMicrophonePermission();
} catch (error) {
index.default({
title: t("Note"),
message: t(
"The current device is not authorized, please allow access to the device permissions",
{ deviceType: t("microphone") }
),
confirmButtonText: t("Sure")
});
return;
}
if (microphoneState.value === MediaDeviceSetting.MediaDeviceState.DeviceOffAndDisabled) {
let warningMessage = "";
if (roomService.roomService.roomStore.isAudience) {
warningMessage = message.WARNING_MESSAGE.UNMUTE_LOCAL_MIC_FAIL_AUDIENCE;
} else if (roomService.roomService.roomStore.isMicrophoneDisableForAllUser) {
warningMessage = message.WARNING_MESSAGE.UNMUTE_LOCAL_MIC_FAIL_MUTE_ALL;
}
uikitBaseComponentVue3.TUIToast({
type: uikitBaseComponentVue3.TOAST_TYPE.WARNING,
message: t(warningMessage),
duration: message.MESSAGE_DURATION.NORMAL
});
return;
}
try {
await ((_a = roomEngine.instance) == null ? void 0 : _a.openLocalMicrophone());
} catch (error) {
if (error.code === 0 && error.message === "you have already mute the audio") {
return;
}
throw error;
}
}
async closeLocalMicrophone() {
var _a;
await ((_a = roomEngine.instance) == null ? void 0 : _a.closeLocalMicrophone());
}
async muteLocalAudio() {
var _a;
await ((_a = roomEngine.instance) == null ? void 0 : _a.muteLocalAudio());
}
async unmuteLocalAudio() {
var _a;
await ((_a = roomEngine.instance) == null ? void 0 : _a.unmuteLocalAudio());
}
async setCurrentDevice(options) {
var _a, _b;
const { deviceId } = options;
await ((_a = deviceManager.instance) == null ? void 0 : _a.setCurrentDevice({
type: TUIRoomEngine.TUIMediaDeviceType.kMediaDeviceTypeAudioInput,
deviceId
}));
currentMicrophoneDevice.value = ((_b = deviceManager.instance) == null ? void 0 : _b.getCurrentDevice({
type: TUIRoomEngine.TUIMediaDeviceType.kMediaDeviceTypeAudioInput
})) || null;
}
};
__publicField(_Microphone, "instance");
let Microphone = _Microphone;
class Speaker {
constructor() {
__publicField(this, "speakerTestPlayer", null);
}
async startSpeakerDeviceTest(options) {
var _a, _b;
if (environment.isElectron) {
(_a = deviceManager.instance) == null ? void 0 : _a.startSpeakerDeviceTest(options);
return;
}
this.speakerTestPlayer = document == null ? void 0 : document.createElement("audio");
if (this.speakerTestPlayer && typeof this.speakerTestPlayer.loop !== "undefined") {
this.speakerTestPlayer.loop = true;
}
await ((_b = this.speakerTestPlayer) == null ? void 0 : _b.setSinkId(currentSpeakerId.value));
this.speakerTestPlayer.src = options.filePath;
this.speakerTestPlayer.play();
isSpeakerTesting.value = true;
}
async stopSpeakerDeviceTest() {
var _a;
if (environment.isElectron) {
(_a = deviceManager.instance) == null ? void 0 : _a.stopSpeakerDeviceTest();
return;
}
if (this.speakerTestPlayer) {
this.speakerTestPlayer.pause();
this.speakerTestPlayer.currentTime = 0;
}
isSpeakerTesting.value = false;
}
async setCurrentDevice(options) {
var _a, _b;
const { deviceId } = options;
await ((_a = deviceManager.instance) == null ? void 0 : _a.setCurrentDevice({
type: TUIRoomEngine.TUIMediaDeviceType.kMediaDeviceTypeAudioOutput,
deviceId
}));
currentSpeakerDevice.value = ((_b = deviceManager.instance) == null ? void 0 : _b.getCurrentDevice({
type: TUIRoomEngine.TUIMediaDeviceType.kMediaDeviceTypeAudioOutput
})) || null;
}
async setAudioRoute(options) {
var _a;
await ((_a = deviceManager.instance) == null ? void 0 : _a.setAudioRoute(options));
currentAudioRoute.value = options.route;
}
}
function useAudioDeviceManager() {
return {
microphone: new Microphone(),
speaker: new Speaker()
};
}
exports.default = useAudioDeviceManager;
;