server.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import TUICore, { TUIConstants } from '@tencentcloud/tui-core';
  2. import { TUIStore, StoreName } from '@tencentcloud/chat-uikit-engine';
  3. import { TUIGlobal } from '@tencentcloud/universal-api';
  4. import { isUniFrameWork } from '../../utils/env';
  5. export default class TUIContactServer {
  6. static instance: TUIContactServer;
  7. private onCallParamsMap: Map<string, any>;
  8. private onCallCallbackMap: Map<string, () => void>;
  9. public constants: typeof TUIConstants;
  10. constructor() {
  11. TUICore.registerService(TUIConstants.TUIContact.SERVICE.NAME, this);
  12. this.onCallParamsMap = new Map();
  13. this.onCallCallbackMap = new Map();
  14. this.constants = TUIConstants;
  15. }
  16. static getInstance(): TUIContactServer {
  17. if (!TUIContactServer.instance) {
  18. TUIContactServer.instance = new TUIContactServer();
  19. }
  20. return TUIContactServer.instance;
  21. }
  22. public getOnCallParams(method: string): any {
  23. return this.onCallParamsMap.get(method);
  24. }
  25. public getOnCallCallback(method: string) {
  26. return this.onCallCallbackMap.get(method);
  27. }
  28. public async onCall(method: string, params: Record<string, any>, callback: () => void): Promise<void> {
  29. this.onCallParamsMap.set(method, params);
  30. this.onCallCallbackMap.set(method, callback);
  31. if (method === TUIConstants.TUIContact.SERVICE.METHOD.SELECT_FRIEND) {
  32. TUIStore.update(StoreName.CUSTOM, 'isShowSelectFriendComponent', true);
  33. isUniFrameWork && TUIGlobal?.reLaunch({
  34. url: '/TUIKit/components/TUIContact/index',
  35. });
  36. }
  37. }
  38. }