@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,
108 lines (107 loc) • 4.35 kB
JavaScript
import { defineComponent, ref, onUnmounted, createBlock, openBlock, unref, withCtx, createElementVNode, toDisplayString, createVNode, createTextVNode } from "vue";
import TUIRoomEngine__default, { TUIRoomEvents, TUIRequestAction, TUIRole } from "@tencentcloud/tuiroom-engine-js";
import Dialog from "../../../components/common/base/Dialog/index.mjs";
import { TUIButton } from "@tencentcloud/uikit-base-component-vue3";
import { useRoomStore } from "../../../stores/room.mjs";
import { useI18n } from "../../../locales/index.mjs";
import useRoomEngine from "../../../hooks/useRoomEngine.mjs";
const _sfc_main = /* @__PURE__ */ defineComponent({
__name: "AudioRequestDialog",
setup(__props) {
const roomEngine = useRoomEngine();
const roomStore = useRoomStore();
const { t } = useI18n();
const dialogContent = ref("");
const showRequestOpenMicDialog = ref(false);
const requestOpenMicRequestId = ref("");
async function onRequestReceived(eventInfo) {
const { userId, requestAction, requestId } = eventInfo.request;
if (requestAction === TUIRequestAction.kRequestToOpenRemoteMicrophone) {
const userRole = roomStore.getUserRole(userId) === TUIRole.kRoomOwner ? t("RoomOwner") : t("Admin");
dialogContent.value = t("Sb invites you to turn on the microphone", {
role: userRole
});
requestOpenMicRequestId.value = requestId;
showRequestOpenMicDialog.value = true;
}
}
async function handleAccept() {
var _a;
await ((_a = roomEngine.instance) == null ? void 0 : _a.responseRemoteRequest({
requestId: requestOpenMicRequestId.value,
agree: true
}));
requestOpenMicRequestId.value = "";
showRequestOpenMicDialog.value = false;
}
async function handleReject() {
var _a;
await ((_a = roomEngine.instance) == null ? void 0 : _a.responseRemoteRequest({
requestId: requestOpenMicRequestId.value,
agree: false
}));
requestOpenMicRequestId.value = "";
showRequestOpenMicDialog.value = false;
}
async function onRequestCancelled(eventInfo) {
const { requestId } = eventInfo;
if (requestOpenMicRequestId.value === requestId) {
showRequestOpenMicDialog.value = false;
}
}
TUIRoomEngine__default.once("ready", () => {
var _a, _b;
(_a = roomEngine.instance) == null ? void 0 : _a.on(TUIRoomEvents.onRequestReceived, onRequestReceived);
(_b = roomEngine.instance) == null ? void 0 : _b.on(TUIRoomEvents.onRequestCancelled, onRequestCancelled);
});
onUnmounted(() => {
var _a, _b;
(_a = roomEngine.instance) == null ? void 0 : _a.off(TUIRoomEvents.onRequestReceived, onRequestReceived);
(_b = roomEngine.instance) == null ? void 0 : _b.off(
TUIRoomEvents.onRequestCancelled,
onRequestCancelled
);
});
return (_ctx, _cache) => {
return openBlock(), createBlock(unref(Dialog), {
modelValue: showRequestOpenMicDialog.value,
"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => showRequestOpenMicDialog.value = $event),
title: unref(t)("Tips"),
modal: true,
"show-close": false,
"close-on-click-modal": false,
width: "500px",
"append-to-room-container": true,
"confirm-button": unref(t)("Turn on the microphone"),
"cancel-button": unref(t)("Keep it closed"),
onConfirm: handleAccept,
onCancel: handleReject
}, {
footer: withCtx(() => [
createVNode(unref(TUIButton), {
onClick: handleAccept,
type: "primary"
}, {
default: withCtx(() => [
createTextVNode(toDisplayString(unref(t)("Turn on the microphone")), 1)
]),
_: 1
}),
createVNode(unref(TUIButton), { onClick: handleReject }, {
default: withCtx(() => [
createTextVNode(toDisplayString(unref(t)("Keep it closed")), 1)
]),
_: 1
})
]),
default: withCtx(() => [
createElementVNode("span", null, toDisplayString(dialogContent.value), 1)
]),
_: 1
}, 8, ["modelValue", "title", "confirm-button", "cancel-button"]);
};
}
});
export {
_sfc_main as default
};