@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.74 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.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const mitt = require("mitt");
const types = require("../types.js");
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 = {
[types.EventType.ROOM_START]: {
reason: "room start",
type: "mount"
},
[types.EventType.ROOM_JOIN]: {
reason: "room join",
type: "mount"
},
[types.EventType.USER_LOGOUT]: {
reason: "room logout",
type: "unmount"
},
[types.EventType.ROOM_LEAVE]: {
reason: "room leave",
type: "unmount"
},
[types.EventType.ROOM_DISMISS]: {
reason: "room destroy",
type: "unmount"
},
[types.EventType.KICKED_OFFLINE]: {
reason: "room kicked offline",
type: "unmount"
},
[types.EventType.KICKED_OUT]: {
reason: "room kicked out",
type: "unmount"
},
[types.EventType.USER_SIG_EXPIRED]: {
reason: "room user sig expired",
type: "unmount"
},
[types.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);
});
}
}
exports.LifeCycleManager = LifeCycleManager;
;