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,

183 lines (182 loc) 6.9 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 { TUIConferenceListManagerEvents, TUIRoomType, TUIErrorCode } from "@tencentcloud/tuiroom-engine-js"; export * from "@tencentcloud/tuiroom-engine-js"; import { EventType } from "../types.mjs"; import mitt from "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(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( TUIConferenceListManagerEvents.onConferenceScheduled, this.onConferenceScheduled ); conferenceListManager.on( TUIConferenceListManagerEvents.onConferenceWillStart, this.onConferenceWillStart ); conferenceListManager.on( TUIConferenceListManagerEvents.onConferenceCancelled, this.onConferenceCancelled ); conferenceListManager.on( TUIConferenceListManagerEvents.onConferenceInfoChanged, this.onConferenceInfoChanged ); conferenceListManager.on( TUIConferenceListManagerEvents.onScheduleAttendeesChanged, this.onScheduleAttendeesChanged ); conferenceListManager.on( TUIConferenceListManagerEvents.onConferenceStatusChanged, this.onConferenceStatusChanged ); } unbindEvent() { var _a; const conferenceListManager = (_a = this.service.roomEngine) == null ? void 0 : _a.instance.getConferenceListManager(); conferenceListManager.off( TUIConferenceListManagerEvents.onConferenceScheduled, this.onConferenceScheduled ); conferenceListManager.off( TUIConferenceListManagerEvents.onConferenceWillStart, this.onConferenceWillStart ); conferenceListManager.off( TUIConferenceListManagerEvents.onConferenceCancelled, this.onConferenceCancelled ); conferenceListManager.off( TUIConferenceListManagerEvents.onConferenceInfoChanged, this.onConferenceInfoChanged ); conferenceListManager.off( TUIConferenceListManagerEvents.onScheduleAttendeesChanged, this.onScheduleAttendeesChanged ); conferenceListManager.off( TUIConferenceListManagerEvents.onConferenceStatusChanged, this.onConferenceStatusChanged ); } onConferenceScheduled(data) { this.emit(TUIConferenceListManagerEvents.onConferenceScheduled, data); } onConferenceWillStart(data) { this.emit(TUIConferenceListManagerEvents.onConferenceWillStart, data); } onConferenceCancelled(data) { this.emit(TUIConferenceListManagerEvents.onConferenceCancelled, data); } onConferenceInfoChanged(data) { this.emit(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(TUIConferenceListManagerEvents.onScheduleAttendeesChanged, data); } onConferenceStatusChanged(data) { this.emit(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: TUIRoomType.kConference })); return await this.generateRoomId(attempt + 1); } catch (err) { if ((err == null ? void 0 : err.code) === 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)); } } export { ScheduleConferenceManager };