@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,
208 lines (207 loc) • 7.93 kB
JavaScript
import { defineComponent, createElementBlock, openBlock, createVNode, unref, withCtx, createTextVNode, toDisplayString, isRef, createCommentVNode, createElementVNode, Fragment, renderList, createBlock } from "vue";
import { TUIButton } from "@tencentcloud/uikit-base-component-vue3";
import Select from "../../common/base/Select/index.mjs";
import OPtion from "../../common/base/Option/index.mjs";
import Dialog from "../../common/base/Dialog/index.mjs";
import { TUIRole } from "@tencentcloud/tuiroom-engine-js";
import useEndControl from "./useEndControlHooks.mjs";
import logger from "../../../utils/common/logger/index.mjs";
import "../../../services/main.mjs";
import { roomService } from "../../../services/roomService.mjs";
import "../../../locales/index.mjs";
import "../../../utils/environment.mjs";
import "mitt";
import "../../../services/manager/roomActionManager.mjs";
import "@tencentcloud/tui-core";
const _hoisted_1 = { class: "end-control-container" };
const _hoisted_2 = { key: 0 };
const _hoisted_3 = { key: 1 };
const _hoisted_4 = { key: 0 };
const _hoisted_5 = { key: 1 };
const _sfc_main = /* @__PURE__ */ defineComponent({
__name: "EndControlPC",
setup(__props) {
const {
t,
roomStore,
roomEngine,
stopMeeting,
cancel,
selectedUser,
DialogType,
showEndDialogContent,
logPrefix,
title,
showEndButtonContent,
currentDialogType,
visible,
resetState,
isMasterWithOneRemoteUser,
isMasterWithRemoteUser,
remoteEnteredUserList
} = useEndControl();
function handleEndBtnClick() {
stopMeeting();
}
function handleEndLeaveClick() {
if (!roomStore.isMaster || roomStore.isMaster && remoteEnteredUserList.value.length === 0) {
leaveRoom();
return;
}
if (isMasterWithRemoteUser.value) {
selectedUser.value = remoteEnteredUserList.value[0].userId;
if (isMasterWithOneRemoteUser.value) {
transferAndLeave();
return;
}
currentDialogType.value = DialogType.TransferDialog;
}
}
async function dismissRoom() {
try {
logger.log(`${logPrefix}dismissRoom: enter`);
resetState();
await roomService.dismissRoom();
} catch (error) {
logger.error(`${logPrefix}dismissRoom error:`, error);
}
}
async function leaveRoom() {
try {
resetState();
await roomService.leaveRoom();
} catch (error) {
logger.error(`${logPrefix}leaveRoom error:`, error);
}
}
async function transferAndLeave() {
var _a;
if (!selectedUser.value) {
return;
}
try {
const userId = selectedUser.value;
const changeUserRoleResponse = await ((_a = roomEngine.instance) == null ? void 0 : _a.changeUserRole({
userId,
userRole: TUIRole.kRoomOwner
}));
logger.log(`${logPrefix}transferAndLeave:`, changeUserRoleResponse);
resetState();
await roomService.leaveRoom();
} catch (error) {
logger.error(`${logPrefix}transferAndLeave error:`, error);
}
}
return (_ctx, _cache) => {
return openBlock(), createElementBlock("div", _hoisted_1, [
createVNode(unref(TUIButton), {
color: "red",
size: "large",
onClick: handleEndBtnClick
}, {
default: withCtx(() => [
createTextVNode(toDisplayString(unref(showEndButtonContent)), 1)
]),
_: 1
}),
createVNode(unref(Dialog), {
modelValue: unref(visible),
"onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => isRef(visible) ? visible.value = $event : null),
title: unref(title),
modal: true,
width: "480px",
"before-close": unref(cancel),
"close-on-click-modal": true,
"append-to-room-container": true
}, {
footer: withCtx(() => [
unref(currentDialogType) === unref(DialogType).BasicDialog ? (openBlock(), createElementBlock("div", _hoisted_4, [
unref(roomStore).isMaster ? (openBlock(), createBlock(unref(TUIButton), {
key: 0,
onClick: dismissRoom,
type: "primary",
style: { "min-width": "88px" }
}, {
default: withCtx(() => [
createTextVNode(toDisplayString(unref(t)("Dismiss")), 1)
]),
_: 1
})) : createCommentVNode("", true),
createVNode(unref(TUIButton), {
onClick: handleEndLeaveClick,
type: "primary",
style: { "min-width": "88px" }
}, {
default: withCtx(() => [
createTextVNode(toDisplayString(unref(t)("Leave")), 1)
]),
_: 1
}),
createVNode(unref(TUIButton), {
onClick: unref(cancel),
style: { "min-width": "88px" }
}, {
default: withCtx(() => [
createTextVNode(toDisplayString(unref(t)("Cancel")), 1)
]),
_: 1
}, 8, ["onClick"])
])) : createCommentVNode("", true),
unref(currentDialogType) === unref(DialogType).TransferDialog ? (openBlock(), createElementBlock("div", _hoisted_5, [
createVNode(unref(TUIButton), {
onClick: transferAndLeave,
type: "primary",
style: { "min-width": "88px" }
}, {
default: withCtx(() => [
createTextVNode(toDisplayString(unref(t)("Transfer and leave")), 1)
]),
_: 1
}),
createVNode(unref(TUIButton), {
onClick: unref(cancel),
style: { "min-width": "88px" }
}, {
default: withCtx(() => [
createTextVNode(toDisplayString(unref(t)("Cancel")), 1)
]),
_: 1
}, 8, ["onClick"])
])) : createCommentVNode("", true)
]),
default: withCtx(() => [
unref(currentDialogType) === unref(DialogType).BasicDialog ? (openBlock(), createElementBlock("div", _hoisted_2, [
createElementVNode("span", null, toDisplayString(unref(showEndDialogContent)), 1)
])) : createCommentVNode("", true),
unref(currentDialogType) === unref(DialogType).TransferDialog ? (openBlock(), createElementBlock("div", _hoisted_3, [
createElementVNode("div", null, toDisplayString(unref(t)("New host")), 1),
createElementVNode("div", null, [
createVNode(unref(Select), {
modelValue: unref(selectedUser),
"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => isRef(selectedUser) ? selectedUser.value = $event : null),
teleported: false,
"popper-append-to-body": false
}, {
default: withCtx(() => [
(openBlock(true), createElementBlock(Fragment, null, renderList(unref(remoteEnteredUserList), (user) => {
return openBlock(), createBlock(unref(OPtion), {
key: user.userId,
value: user.userId,
label: user.nameCard || user.userName
}, null, 8, ["value", "label"]);
}), 128))
]),
_: 1
}, 8, ["modelValue"])
])
])) : createCommentVNode("", true)
]),
_: 1
}, 8, ["modelValue", "title", "before-close"])
]);
};
}
});
export {
_sfc_main as default
};