@ethora/chat-component-rn 26.5.13 → 26.5.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/README.md +1 -0
  2. package/lib/commonjs/components/MainComponents/ChatHeader.js +4 -1
  3. package/lib/commonjs/components/MainComponents/ChatHeader.js.map +1 -1
  4. package/lib/commonjs/components/MainComponents/ChatWrapper.js +12 -0
  5. package/lib/commonjs/components/MainComponents/ChatWrapper.js.map +1 -1
  6. package/lib/commonjs/helpers/buildSeedRoom.js +18 -0
  7. package/lib/commonjs/helpers/buildSeedRoom.js.map +1 -0
  8. package/lib/commonjs/roomStore/Middleware/unreadMidlleware.js +20 -1
  9. package/lib/commonjs/roomStore/Middleware/unreadMidlleware.js.map +1 -1
  10. package/lib/commonjs/roomStore/index.js +5 -4
  11. package/lib/commonjs/roomStore/index.js.map +1 -1
  12. package/lib/commonjs/utils/clientRegistry.js +19 -16
  13. package/lib/commonjs/utils/clientRegistry.js.map +1 -1
  14. package/lib/module/components/MainComponents/ChatHeader.js +4 -1
  15. package/lib/module/components/MainComponents/ChatHeader.js.map +1 -1
  16. package/lib/module/components/MainComponents/ChatWrapper.js +13 -1
  17. package/lib/module/components/MainComponents/ChatWrapper.js.map +1 -1
  18. package/lib/module/helpers/buildSeedRoom.js +13 -0
  19. package/lib/module/helpers/buildSeedRoom.js.map +1 -0
  20. package/lib/module/roomStore/Middleware/unreadMidlleware.js +20 -1
  21. package/lib/module/roomStore/Middleware/unreadMidlleware.js.map +1 -1
  22. package/lib/module/roomStore/index.js +5 -4
  23. package/lib/module/roomStore/index.js.map +1 -1
  24. package/lib/module/utils/clientRegistry.js +19 -16
  25. package/lib/module/utils/clientRegistry.js.map +1 -1
  26. package/lib/typescript/components/MainComponents/ChatHeader.d.ts.map +1 -1
  27. package/lib/typescript/components/MainComponents/ChatWrapper.d.ts.map +1 -1
  28. package/lib/typescript/helpers/buildSeedRoom.d.ts +3 -0
  29. package/lib/typescript/helpers/buildSeedRoom.d.ts.map +1 -0
  30. package/lib/typescript/roomStore/Middleware/unreadMidlleware.d.ts.map +1 -1
  31. package/lib/typescript/roomStore/index.d.ts +1 -1
  32. package/lib/typescript/roomStore/index.d.ts.map +1 -1
  33. package/lib/typescript/types/types.d.ts +1 -0
  34. package/lib/typescript/types/types.d.ts.map +1 -1
  35. package/lib/typescript/utils/clientRegistry.d.ts.map +1 -1
  36. package/package.json +1 -1
  37. package/src/components/MainComponents/ChatHeader.tsx +3 -2
  38. package/src/components/MainComponents/ChatWrapper.tsx +19 -0
  39. package/src/helpers/buildSeedRoom.ts +12 -0
  40. package/src/roomStore/Middleware/unreadMidlleware.tsx +25 -1
  41. package/src/roomStore/index.ts +51 -39
  42. package/src/types/types.ts +1 -0
  43. package/src/utils/clientRegistry.ts +32 -16
@@ -1,9 +1,23 @@
1
1
  import XmppClient from '../networking/xmppClient';
2
2
  import { xmppSettingsInterface } from '../types/types';
3
3
 
4
- let currentClient: XmppClient | null = null;
5
- let currentClientKey = '';
6
- const initLocks = new Map<string, Promise<XmppClient>>();
4
+ interface XmppRegistryState {
5
+ currentClient: XmppClient | null;
6
+ currentClientKey: string;
7
+ initLocks: Map<string, Promise<XmppClient>>;
8
+ }
9
+
10
+ const globalScope = globalThis as typeof globalThis & {
11
+ __XMPP_REGISTRY__?: XmppRegistryState;
12
+ };
13
+
14
+ const registry: XmppRegistryState =
15
+ globalScope.__XMPP_REGISTRY__ ||
16
+ (globalScope.__XMPP_REGISTRY__ = {
17
+ currentClient: null,
18
+ currentClientKey: '',
19
+ initLocks: new Map<string, Promise<XmppClient>>(),
20
+ });
7
21
 
8
22
  const DEFAULT_DEV_SERVER = 'xmpp.chat.ethora.com';
9
23
 
@@ -26,46 +40,48 @@ export function setGlobalXmppClient(
26
40
  client: XmppClient | null,
27
41
  key?: string
28
42
  ): void {
29
- currentClient = client;
30
- currentClientKey = client ? key || currentClientKey || '' : '';
43
+ registry.currentClient = client;
44
+ registry.currentClientKey = client
45
+ ? key || registry.currentClientKey || ''
46
+ : '';
31
47
  }
32
48
 
33
49
  export function getGlobalXmppClient(): XmppClient | null {
34
- return currentClient;
50
+ return registry.currentClient;
35
51
  }
36
52
 
37
53
  export function getGlobalXmppClientKey(): string {
38
- return currentClientKey;
54
+ return registry.currentClientKey;
39
55
  }
40
56
 
41
57
  export function getReusableXmppClientByKey(key: string): XmppClient | null {
42
- if (!key || key !== currentClientKey) {return null;}
43
- if (!isXmppClientReusable(currentClient)) {return null;}
44
- return currentClient;
58
+ if (!key || key !== registry.currentClientKey) {return null;}
59
+ if (!isXmppClientReusable(registry.currentClient)) {return null;}
60
+ return registry.currentClient;
45
61
  }
46
62
 
47
63
  export async function withXmppClientInitLock(
48
64
  key: string,
49
65
  init: () => Promise<XmppClient>
50
66
  ): Promise<XmppClient> {
51
- const existing = initLocks.get(key);
67
+ const existing = registry.initLocks.get(key);
52
68
  if (existing) {return existing;}
53
69
 
54
70
  const createdPromise = init().finally(() => {
55
- if (initLocks.get(key) === createdPromise) {
56
- initLocks.delete(key);
71
+ if (registry.initLocks.get(key) === createdPromise) {
72
+ registry.initLocks.delete(key);
57
73
  }
58
74
  });
59
75
 
60
- initLocks.set(key, createdPromise);
76
+ registry.initLocks.set(key, createdPromise);
61
77
  return createdPromise;
62
78
  }
63
79
 
64
80
  export function requireXmppClient(): XmppClient {
65
- if (!currentClient) {
81
+ if (!registry.currentClient) {
66
82
  throw new Error('XMPP client is not initialized');
67
83
  }
68
- return currentClient;
84
+ return registry.currentClient;
69
85
  }
70
86
 
71
87
  export default {