UNPKG

@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,

89 lines (88 loc) 2.59 kB
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); import mitt from "mitt"; import { EventType } from "../types.mjs"; class LifeCycleManager { constructor(service) { __publicField(this, "service"); __publicField(this, "eventCallbacks", {}); __publicField(this, "emitter", mitt()); this.service = service; } start() { this.stop(); this.addEventListeners(); } stop() { this.removeEventListeners(); } on(eventType, callback) { this.emitter.on(eventType, callback); } off(eventType, callback) { this.emitter.off(eventType, callback); } emit(eventType, data) { this.emitter.emit(eventType, data); } addEventListeners() { const handleMount = (reason) => this.emit("mount", { reason }); const handleUnmount = (reason) => this.emit("unmount", { reason }); const handleCallback = (type, reason) => { const callback = type === "mount" ? handleMount : handleUnmount; return callback.bind(this, reason); }; const eventReasonMap = { [EventType.ROOM_START]: { reason: "room start", type: "mount" }, [EventType.ROOM_JOIN]: { reason: "room join", type: "mount" }, [EventType.USER_LOGOUT]: { reason: "room logout", type: "unmount" }, [EventType.ROOM_LEAVE]: { reason: "room leave", type: "unmount" }, [EventType.ROOM_DISMISS]: { reason: "room destroy", type: "unmount" }, [EventType.KICKED_OFFLINE]: { reason: "room kicked offline", type: "unmount" }, [EventType.KICKED_OUT]: { reason: "room kicked out", type: "unmount" }, [EventType.USER_SIG_EXPIRED]: { reason: "room user sig expired", type: "unmount" }, [EventType.ROOM_ERROR]: { reason: "room error", type: "unmount" } }; Object.entries(eventReasonMap).forEach(([event, { reason, type }]) => { const callback = handleCallback(type, reason); this.eventCallbacks[event] = callback; this.service.on(event, callback); }); } removeEventListeners() { Object.entries(this.eventCallbacks).forEach(([event, callback]) => { this.service.off(event, callback); }); } } export { LifeCycleManager };