@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,
166 lines (165 loc) • 6.46 kB
JavaScript
import { defineComponent, computed, onMounted, onUnmounted, createElementBlock, openBlock, createVNode, unref, withCtx, createBlock } from "vue";
import { TRTCScreenCaptureSourceType } from "@tencentcloud/tuiroom-engine-electron";
import { storeToRefs } from "pinia";
import { ipcRenderer } from "electron";
import IconButton from "../common/base/IconButton.vue.mjs";
import ScreenShareIcon from "../common/icons/ScreenShareIcon.vue.mjs";
import StopScreenShareIcon from "../common/icons/StopScreenShareIcon.vue.mjs";
import renderMsg from "../common/base/Message/Message.mjs";
import { useRoomStore } from "../../stores/room.mjs";
import { useI18n } from "../../locales/index.mjs";
import bus from "../../hooks/useMitt.mjs";
import "../../services/main.mjs";
import { roomService, roomEngine } from "../../services/roomService.mjs";
import { EventType } from "../../services/types.mjs";
import "../../utils/environment.mjs";
import "mitt";
import "../../services/manager/roomActionManager.mjs";
import "@tencentcloud/tui-core";
import { MetricsKey } from "../../services/manager/dataReportManager.mjs";
import { MESSAGE_DURATION } from "../../constants/message.mjs";
const _hoisted_1 = { class: "whiteboard-control-container" };
const _sfc_main = /* @__PURE__ */ defineComponent({
__name: "WhiteboardControl",
setup(__props) {
const { t } = useI18n();
const roomStore = useRoomStore();
const {
isAudience,
remoteScreenStream,
isLocalUserSharing,
isWhiteboardVisible,
isAnnotationVisible
} = storeToRefs(roomStore);
const whiteboardDisabled = computed(
() => isAudience.value || isLocalUserSharing.value
);
const title = computed(
() => isWhiteboardVisible.value ? t("Close whiteboard") : t("Open whiteboard")
);
function handleWhiteboardDialog() {
if (isWhiteboardVisible.value) {
stopShareWhiteboard();
} else {
startShareWhiteboard();
}
}
async function startShareWhiteboard() {
var _a;
if (isWhiteboardVisible.value) {
return;
}
if (isAudience.value) {
renderMsg({
type: "warning",
message: t(
"You currently do not have whiteboard permission, please raise your hand to apply for whiteboard permission first"
),
duration: MESSAGE_DURATION.LONG
});
return;
}
if (whiteboardDisabled.value) {
renderMsg({
type: "warning",
message: t(
"Screen sharing is currently active, cannot start the whiteboard."
),
duration: MESSAGE_DURATION.LONG
});
return;
}
if (remoteScreenStream.value) {
renderMsg({
type: "warning",
message: t(
"Another user is currently sharing the screen, screen sharing is not possible."
),
duration: MESSAGE_DURATION.LONG
});
return;
}
showWhiteboardWindow();
const screenAndWindowsList = await ((_a = roomEngine.instance) == null ? void 0 : _a.getScreenSharingTarget());
const windowList = screenAndWindowsList.filter(
(screen) => screen.type === TRTCScreenCaptureSourceType.TRTCScreenCaptureSourceTypeWindow
);
windowList.forEach((info) => {
var _a2;
if (info.sourceName.includes("Whiteboard window")) {
(_a2 = roomEngine.instance) == null ? void 0 : _a2.startScreenSharingElectron({
targetId: info.sourceId
});
}
});
}
function stopShareWhiteboard() {
var _a;
(_a = roomEngine.instance) == null ? void 0 : _a.stopScreenSharing();
if (isWhiteboardVisible.value) {
roomService.dataReportManager.reportCount(MetricsKey.stopSharingWhiteboard);
}
if (isAnnotationVisible.value) {
roomService.dataReportManager.reportCount(MetricsKey.stopAnnotating);
}
isWhiteboardVisible.value = false;
isAnnotationVisible.value = false;
hideAllWhiteboardWindow();
}
function hideAllWhiteboardWindow() {
ipcRenderer.send("annotation:hide");
ipcRenderer.send("whiteboard:hide-window");
}
function showWhiteboardWindow() {
isWhiteboardVisible.value = true;
ipcRenderer.send("whiteboard:show-window");
roomService.dataReportManager.reportCount(MetricsKey.startSharingWhiteboard);
}
ipcRenderer.on("whiteboard:window-closed", () => {
stopShareWhiteboard();
});
ipcRenderer.on("whiteboard:stop-from-whiteboard-window", () => {
stopShareWhiteboard();
});
ipcRenderer.on("whiteboard:save-from-whiteboard-window", () => {
roomService.dataReportManager.reportCount(MetricsKey.saveWhiteboard);
});
onMounted(() => {
bus.on("ScreenShare:stopScreenShare", stopShareWhiteboard);
roomService.on(EventType.KICKED_OUT, stopShareWhiteboard);
roomService.on(EventType.USER_SIG_EXPIRED, stopShareWhiteboard);
roomService.on(EventType.KICKED_OFFLINE, stopShareWhiteboard);
roomService.on(EventType.ROOM_LEAVE, stopShareWhiteboard);
roomService.on(EventType.ROOM_DISMISS, stopShareWhiteboard);
roomService.on(EventType.USER_LOGOUT, stopShareWhiteboard);
});
onUnmounted(() => {
bus.off("ScreenShare:stopScreenShare", stopShareWhiteboard);
roomService.off(EventType.KICKED_OUT, stopShareWhiteboard);
roomService.off(EventType.USER_SIG_EXPIRED, stopShareWhiteboard);
roomService.off(EventType.KICKED_OFFLINE, stopShareWhiteboard);
roomService.off(EventType.ROOM_LEAVE, stopShareWhiteboard);
roomService.off(EventType.ROOM_DISMISS, stopShareWhiteboard);
roomService.off(EventType.USER_LOGOUT, stopShareWhiteboard);
roomService.resetStore();
});
return (_ctx, _cache) => {
return openBlock(), createElementBlock("div", _hoisted_1, [
createVNode(IconButton, {
"is-active": unref(isWhiteboardVisible),
title: title.value,
disabled: whiteboardDisabled.value,
onClickIcon: handleWhiteboardDialog
}, {
default: withCtx(() => [
unref(isWhiteboardVisible) ? (openBlock(), createBlock(StopScreenShareIcon, { key: 0 })) : (openBlock(), createBlock(ScreenShareIcon, { key: 1 }))
]),
_: 1
}, 8, ["is-active", "title", "disabled"])
]);
};
}
});
export {
_sfc_main as default
};