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,

188 lines (187 loc) 7.43 kB
"use strict"; 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 TUIRoomEngine = require("@tencentcloud/tuiroom-engine-js"); const types = require("../types.js"); const mitt = require("mitt"); const MAX_ATTEMPTS = 5; class ScheduleConferenceManager { constructor(service) { __publicField(this, "service"); __publicField(this, "customFriendList"); __publicField(this, "emitter", mitt()); this.service = service; this.bindEventContext(); this.service.on(types.EventType.SERVICE_READY, () => { this.bindEvent(); }); } dispose() { this.unbindEvent(); } on(eventType, callback) { this.emitter.on(eventType, callback); } off(eventType, callback) { this.emitter.off(eventType, callback); } emit(eventType, data) { this.emitter.emit(eventType, data); } bindEventContext() { this.onConferenceScheduled = this.onConferenceScheduled.bind(this); this.onConferenceWillStart = this.onConferenceWillStart.bind(this); this.onConferenceCancelled = this.onConferenceCancelled.bind(this); this.onConferenceInfoChanged = this.onConferenceInfoChanged.bind(this); this.onScheduleAttendeesChanged = this.onScheduleAttendeesChanged.bind(this); this.onConferenceStatusChanged = this.onConferenceStatusChanged.bind(this); } bindEvent() { var _a; const conferenceListManager = (_a = this.service.roomEngine) == null ? void 0 : _a.instance.getConferenceListManager(); conferenceListManager.on( TUIRoomEngine.TUIConferenceListManagerEvents.onConferenceScheduled, this.onConferenceScheduled ); conferenceListManager.on( TUIRoomEngine.TUIConferenceListManagerEvents.onConferenceWillStart, this.onConferenceWillStart ); conferenceListManager.on( TUIRoomEngine.TUIConferenceListManagerEvents.onConferenceCancelled, this.onConferenceCancelled ); conferenceListManager.on( TUIRoomEngine.TUIConferenceListManagerEvents.onConferenceInfoChanged, this.onConferenceInfoChanged ); conferenceListManager.on( TUIRoomEngine.TUIConferenceListManagerEvents.onScheduleAttendeesChanged, this.onScheduleAttendeesChanged ); conferenceListManager.on( TUIRoomEngine.TUIConferenceListManagerEvents.onConferenceStatusChanged, this.onConferenceStatusChanged ); } unbindEvent() { var _a; const conferenceListManager = (_a = this.service.roomEngine) == null ? void 0 : _a.instance.getConferenceListManager(); conferenceListManager.off( TUIRoomEngine.TUIConferenceListManagerEvents.onConferenceScheduled, this.onConferenceScheduled ); conferenceListManager.off( TUIRoomEngine.TUIConferenceListManagerEvents.onConferenceWillStart, this.onConferenceWillStart ); conferenceListManager.off( TUIRoomEngine.TUIConferenceListManagerEvents.onConferenceCancelled, this.onConferenceCancelled ); conferenceListManager.off( TUIRoomEngine.TUIConferenceListManagerEvents.onConferenceInfoChanged, this.onConferenceInfoChanged ); conferenceListManager.off( TUIRoomEngine.TUIConferenceListManagerEvents.onScheduleAttendeesChanged, this.onScheduleAttendeesChanged ); conferenceListManager.off( TUIRoomEngine.TUIConferenceListManagerEvents.onConferenceStatusChanged, this.onConferenceStatusChanged ); } onConferenceScheduled(data) { this.emit(TUIRoomEngine.TUIConferenceListManagerEvents.onConferenceScheduled, data); } onConferenceWillStart(data) { this.emit(TUIRoomEngine.TUIConferenceListManagerEvents.onConferenceWillStart, data); } onConferenceCancelled(data) { this.emit(TUIRoomEngine.TUIConferenceListManagerEvents.onConferenceCancelled, data); } onConferenceInfoChanged(data) { this.emit(TUIRoomEngine.TUIConferenceListManagerEvents.onConferenceInfoChanged, data); const { roomId, roomName } = data.conferenceModifyInfo.basicRoomInfo; const isCurrentRoom = this.service.basicStore.roomId === roomId; if (!isCurrentRoom) return; roomName !== void 0 && roomName !== null && this.service.roomStore.setRoomInfo({ roomName }); } onScheduleAttendeesChanged(data) { this.emit(TUIRoomEngine.TUIConferenceListManagerEvents.onScheduleAttendeesChanged, data); } onConferenceStatusChanged(data) { this.emit(TUIRoomEngine.TUIConferenceListManagerEvents.onConferenceStatusChanged, data); } async fetchFriendList() { var _a; if (this.customFriendList) return this.customFriendList; const tim = (_a = this.service.roomEngine.instance) == null ? void 0 : _a.getTIM(); const { data } = await tim.getFriendList(); return data; } replaceFriendList(userList) { this.customFriendList = userList; } async generateRoomId(attempt = 1) { var _a; if (attempt > MAX_ATTEMPTS) { throw new Error( "Failed to generate a unique room ID after maximum attempts." ); } const roomId = String(Math.ceil(Math.random() * 1e6)); try { await ((_a = this.service.roomActionManager) == null ? void 0 : _a.fetchRoomInfo({ roomId, roomType: TUIRoomEngine.TUIRoomType.kConference })); return await this.generateRoomId(attempt + 1); } catch (err) { if ((err == null ? void 0 : err.code) === TUIRoomEngine.TUIErrorCode.ERR_ROOM_ID_NOT_EXIST) { return roomId; } throw err; } } async scheduleConference(options) { var _a; return await ((_a = this.service.roomEngine.instance) == null ? void 0 : _a.getConferenceListManager().scheduleConference(options)); } async cancelConference(options) { var _a; return await ((_a = this.service.roomEngine.instance) == null ? void 0 : _a.getConferenceListManager().cancelConference(options)); } async updateConferenceInfo(options) { var _a; return await ((_a = this.service.roomEngine.instance) == null ? void 0 : _a.getConferenceListManager().updateConferenceInfo(options)); } async fetchScheduledConferenceList(options) { var _a; return await ((_a = this.service.roomEngine.instance) == null ? void 0 : _a.getConferenceListManager().fetchScheduledConferenceList(options)); } async fetchAttendeeList(options) { var _a; return await ((_a = this.service.roomEngine.instance) == null ? void 0 : _a.getConferenceListManager().fetchAttendeeList(options)); } async addAttendeesByAdmin(options) { var _a; return await ((_a = this.service.roomEngine.instance) == null ? void 0 : _a.getConferenceListManager().addAttendeesByAdmin(options)); } async removeAttendeesByAdmin(options) { var _a; return await ((_a = this.service.roomEngine.instance) == null ? void 0 : _a.getConferenceListManager().removeAttendeesByAdmin(options)); } } exports.ScheduleConferenceManager = ScheduleConferenceManager; Object.keys(TUIRoomEngine).forEach((k) => { if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, { enumerable: true, get: () => TUIRoomEngine[k] }); });