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,

157 lines (156 loc) 5.48 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 TUICore, { TUIConstants, TUILogin } from "@tencentcloud/tui-core"; import TUIChatEngine, { TUITranslateService } from "@tencentcloud/chat-uikit-engine"; import { TUIGlobal } from "@tencentcloud/universal-api"; import { isObject, isFunction } from "./utils/type-check.mjs"; import "./utils/env.mjs"; import messages from "./locales/index.mjs"; const _TUIChatKit = class _TUIChatKit { constructor() { __publicField(this, "chat"); __publicField(this, "SDKAppID"); __publicField(this, "TUICore"); __publicField(this, "TUIChatEngine"); __publicField(this, "TUIGlobal"); __publicField(this, "TUIComponents", {}); __publicField(this, "TUIPlugins", {}); this.TUICore = TUICore; this.TUIChatEngine = TUIChatEngine; this.TUIGlobal = TUIGlobal; this.SDKAppID = 0; this.TUIGlobal._isTIMCallKit = true; TUICore.registerEvent(TUIConstants.TUILogin.EVENT.LOGIN_STATE_CHANGED, TUIConstants.TUILogin.EVENT_SUB_KEY.USER_LOGIN_SUCCESS, this); TUICore.registerEvent(TUIConstants.TUITranslate.EVENT.LANGUAGE_CHANGED, TUIConstants.TUITranslate.EVENT_SUB_KEY.CHANGE_SUCCESS, this); TUICore.registerService(TUIConstants.TUITranslatePlugin.SERVICE.NAME, 1); TUICore.registerService(TUIConstants.TUIVoiceToTextPlugin.SERVICE.NAME, 1); } /** * Listen for the success notification of TUILogin.login */ onNotifyEvent(eventName, subKey, params) { if (eventName === TUIConstants.TUILogin.EVENT.LOGIN_STATE_CHANGED) { switch (subKey) { case TUIConstants.TUILogin.EVENT_SUB_KEY.USER_LOGIN_SUCCESS: this.login(); break; } } if (eventName === TUIConstants.TUITranslate.EVENT.LANGUAGE_CHANGED) { switch (subKey) { case TUIConstants.TUITranslate.EVENT_SUB_KEY.CHANGE_SUCCESS: if (params == null ? void 0 : params.language) { TUITranslateService.changeLanguage(params.language); } break; } } } /** * init */ init() { if (_TUIChatKit.isInitialized) { return; } _TUIChatKit.isInitialized = true; TUITranslateService.provideLanguages({ ...messages }); TUITranslateService.useI18n(); TUIGlobal.TUIComponents = this.TUIComponents; TUIGlobal.TUIPlugins = this.TUIPlugins; console.warn("[TUIChatKit]: init success."); } /** * login */ login() { const { chat, SDKAppID, userID, userSig } = TUILogin.getContext(); this.SDKAppID = SDKAppID; this.TUIChatEngine.login({ chat, SDKAppID, userID, userSig }); this.chat = chat; return this.TUIChatEngine; } /** * Single component mounting * * @param {string} componentName * @param {any} component * @param {any=} env * @returns {TUICore} mounted instance */ component(componentName, component, env) { var _a, _b; if ((_a = this == null ? void 0 : this.TUIComponents) == null ? void 0 : _a.componentName) { console.warn( `[TUIChatKit]: ${(_b = this == null ? void 0 : this.TUIComponents) == null ? void 0 : _b.componentName} component has already been applied to target TUIChatEngine.` ); } else { this.TUIComponents[componentName] = component; env == null ? void 0 : env.component(componentName, component); } if (env) { !TUIGlobal.Vue && (TUIGlobal.Vue = env); } return this.TUIChatEngine; } /** * Component list mount * * @param {object} components * @param {any=} env: Vue2/Vue3 environment * @returns {TUICore} mounted instance */ components(components, env) { var _a; if (!components || !isObject(components)) { console.warn("[TUIChatKit]: components is empty or not object."); } else { (_a = Object == null ? void 0 : Object.keys(components)) == null ? void 0 : _a.forEach((key) => { this.component(key, components[key], env); }); } return this.TUIChatEngine; } /** * Plugin Injection * * @param {any} TUIPlugin * @param {any} options * @returns {TUICore} mounted instance */ use(TUIPluginName, TUIPlugin, options) { if (!this.TUICore) { console.warn( `[TUIChatKit]: Plugin ${this.TUIPlugins[TUIPluginName]} can't be used before init.` ); return; } if (this.TUIPlugins[TUIPluginName]) { console.warn( `[TUIChatKit]: Plugin ${this.TUIPlugins[TUIPluginName]} has already been applied to target TUIChatEngine.` ); } else if (TUIPlugin && isFunction(TUIPlugin == null ? void 0 : TUIPlugin.plugin)) { this.TUIPlugins[TUIPluginName] = TUIPlugin; TUIPlugin == null ? void 0 : TUIPlugin.plugin(this, options); } else if (isFunction(TUIPlugin)) { this.TUIPlugins[TUIPluginName] = TUIPlugin; TUIPlugin(this, options); } else { console.warn( '[TUIChatKit]: A plugin must either be a function or an object with an "plugin" function.' + this.TUIPlugins[TUIPluginName] + "does not comply with the above rules." ); } return this.TUIChatEngine; } }; __publicField(_TUIChatKit, "isInitialized"); let TUIChatKit = _TUIChatKit; export { TUIChatKit as default };