cbcore-ts 1.0.57 → 1.0.61

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.
@@ -8,6 +8,56 @@ declare interface CBDialogViewShower {
8
8
  showActionIndicatorDialog(message: string, dismissCallback?: Function): void;
9
9
  hideActionIndicatorDialog(): void;
10
10
  }
11
+ /**
12
+ * CBCore — Application session model and library entry point.
13
+ *
14
+ * CBCore is a general-purpose library class. It must not contain any
15
+ * project-specific business logic. To extend it for a specific project,
16
+ * subclass CBCore and register the subclass as the singleton before any
17
+ * other code accesses `CBCore.sharedInstance`.
18
+ *
19
+ * ## Extension pattern
20
+ *
21
+ * 1. Subclass CBCore in your project:
22
+ *
23
+ * ```typescript
24
+ * class MyAppCore extends CBCore {
25
+ *
26
+ * // Additional session-level state goes here.
27
+ * mySessionData: MySessionData | undefined = undefined
28
+ *
29
+ * // Override didSetUserProfile to fetch session data before the
30
+ * // userDidLogIn broadcast fires. Call super only after your data
31
+ * // is ready so that every listener receives a fully populated core.
32
+ * override async didSetUserProfile() {
33
+ * if (IS(this.userProfile)) {
34
+ * this.mySessionData = await fetchMySessionData()
35
+ * }
36
+ * else {
37
+ * this.mySessionData = undefined
38
+ * }
39
+ * super.didSetUserProfile()
40
+ * }
41
+ *
42
+ * // Expose a typed singleton so callers never need CBCore.sharedInstance.
43
+ * static override get sharedInstance(): MyAppCore {
44
+ * return CBCore.sharedInstance as MyAppCore
45
+ * }
46
+ *
47
+ * }
48
+ * ```
49
+ *
50
+ * 2. Register the subclass at app startup, before UICore is initialised:
51
+ *
52
+ * ```typescript
53
+ * CBCore.setSharedInstance(new MyAppCore())
54
+ * CBCore.initIfNeededWithViewCore(new UICore(...))
55
+ * ```
56
+ *
57
+ * 3. From that point on, every call to `CBCore.sharedInstance` — including
58
+ * calls made internally by the library — returns the MyAppCore instance.
59
+ * Project code should call `MyAppCore.sharedInstance` for the typed version.
60
+ */
11
61
  export declare class CBCore extends UIObject {
12
62
  private static _sharedInstance;
13
63
  viewCores: UICore[];
@@ -20,7 +70,31 @@ export declare class CBCore extends UIObject {
20
70
  dialogViewShowerClass: CBDialogViewShower;
21
71
  constructor();
22
72
  static initIfNeededWithViewCore(viewCore: UICore): void;
73
+ /**
74
+ * Returns the shared singleton instance.
75
+ *
76
+ * If `setSharedInstance` was called before this getter was first accessed,
77
+ * that instance is returned. Otherwise a default `CBCore` is created.
78
+ * Library-internal code always goes through this getter, so registering a
79
+ * subclass via `setSharedInstance` is sufficient to replace the singleton
80
+ * for the entire session.
81
+ */
23
82
  static get sharedInstance(): CBCore;
83
+ /**
84
+ * Registers a subclass instance as the application singleton.
85
+ *
86
+ * Call this once at app startup, before `CBCore.sharedInstance` or
87
+ * `CBCore.initIfNeededWithViewCore` are first accessed. Calling it after
88
+ * the singleton has already been created has no effect and will throw in
89
+ * development to catch accidental misuse.
90
+ *
91
+ * ```typescript
92
+ * // App entry point — must be the very first thing that runs.
93
+ * CBCore.setSharedInstance(new MyAppCore())
94
+ * CBCore.initIfNeededWithViewCore(new UICore("root", RootViewController))
95
+ * ```
96
+ */
97
+ static setSharedInstance(instance: CBCore): void;
24
98
  static broadcastEventName: {
25
99
  readonly userDidLogIn: "UserDidLogIn";
26
100
  readonly userDidLogOut: "UserDidLogOut";
@@ -35,6 +109,29 @@ export declare class CBCore extends UIObject {
35
109
  private _userProfile;
36
110
  get userProfile(): CBUserProfile;
37
111
  set userProfile(userProfile: CBUserProfile);
112
+ /**
113
+ * Called whenever `userProfile` is assigned.
114
+ *
115
+ * The default implementation derives `isUserLoggedIn` from the profile
116
+ * and triggers the login/logout broadcast via `didSetIsUserLoggedIn`.
117
+ *
118
+ * Subclasses may override this to fetch additional session data before
119
+ * the broadcast fires. The override must be `async` and must call
120
+ * `super.didSetUserProfile()` after it has finished populating any
121
+ * extra state, so that all broadcast listeners receive a complete core:
122
+ *
123
+ * ```typescript
124
+ * override async didSetUserProfile() {
125
+ * if (IS(this.userProfile)) {
126
+ * this.companyStatus = (await SocketClient.CurrentUserStatusInCompany()).result
127
+ * }
128
+ * else {
129
+ * this.companyStatus = undefined
130
+ * }
131
+ * super.didSetUserProfile() // broadcast fires here
132
+ * }
133
+ * ```
134
+ */
38
135
  didSetUserProfile(): void;
39
136
  set languageKey(languageKey: string);
40
137
  get languageKey(): string;
@@ -53,12 +53,44 @@ const _CBCore = class _CBCore extends import_uicore_ts2.UIObject {
53
53
  static initIfNeededWithViewCore(viewCore) {
54
54
  _CBCore.sharedInstance.viewCores.push(viewCore);
55
55
  }
56
+ /**
57
+ * Returns the shared singleton instance.
58
+ *
59
+ * If `setSharedInstance` was called before this getter was first accessed,
60
+ * that instance is returned. Otherwise a default `CBCore` is created.
61
+ * Library-internal code always goes through this getter, so registering a
62
+ * subclass via `setSharedInstance` is sufficient to replace the singleton
63
+ * for the entire session.
64
+ */
56
65
  static get sharedInstance() {
57
66
  if (!_CBCore._sharedInstance) {
58
67
  _CBCore._sharedInstance = new _CBCore();
59
68
  }
60
69
  return _CBCore._sharedInstance;
61
70
  }
71
+ /**
72
+ * Registers a subclass instance as the application singleton.
73
+ *
74
+ * Call this once at app startup, before `CBCore.sharedInstance` or
75
+ * `CBCore.initIfNeededWithViewCore` are first accessed. Calling it after
76
+ * the singleton has already been created has no effect and will throw in
77
+ * development to catch accidental misuse.
78
+ *
79
+ * ```typescript
80
+ * // App entry point — must be the very first thing that runs.
81
+ * CBCore.setSharedInstance(new MyAppCore())
82
+ * CBCore.initIfNeededWithViewCore(new UICore("root", RootViewController))
83
+ * ```
84
+ */
85
+ static setSharedInstance(instance) {
86
+ if (_CBCore._sharedInstance) {
87
+ throw new Error(
88
+ "CBCore.setSharedInstance must be called before sharedInstance is first accessed. Move the call to the very top of your app entry point."
89
+ );
90
+ return;
91
+ }
92
+ _CBCore._sharedInstance = instance;
93
+ }
62
94
  broadcastMessageInRootViewTree(message) {
63
95
  this.viewCores.everyElement.rootViewController.view.broadcastEventInSubtree(message);
64
96
  }
@@ -111,6 +143,29 @@ const _CBCore = class _CBCore extends import_uicore_ts2.UIObject {
111
143
  this._userProfile = userProfile;
112
144
  this.didSetUserProfile();
113
145
  }
146
+ /**
147
+ * Called whenever `userProfile` is assigned.
148
+ *
149
+ * The default implementation derives `isUserLoggedIn` from the profile
150
+ * and triggers the login/logout broadcast via `didSetIsUserLoggedIn`.
151
+ *
152
+ * Subclasses may override this to fetch additional session data before
153
+ * the broadcast fires. The override must be `async` and must call
154
+ * `super.didSetUserProfile()` after it has finished populating any
155
+ * extra state, so that all broadcast listeners receive a complete core:
156
+ *
157
+ * ```typescript
158
+ * override async didSetUserProfile() {
159
+ * if (IS(this.userProfile)) {
160
+ * this.companyStatus = (await SocketClient.CurrentUserStatusInCompany()).result
161
+ * }
162
+ * else {
163
+ * this.companyStatus = undefined
164
+ * }
165
+ * super.didSetUserProfile() // broadcast fires here
166
+ * }
167
+ * ```
168
+ */
114
169
  didSetUserProfile() {
115
170
  this.isUserLoggedIn = (0, import_uicore_ts2.IS)(this.userProfile);
116
171
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../scripts/CBCore.ts"],
4
- "sourcesContent": ["import { ManagerOptions, SocketOptions } from \"socket.io-client\"\nimport { NO } from \"uicore-ts\"\nimport { FIRST, IS, IS_NOT, nil, UICore, UILink, UIObject, UIRoute, UIViewBroadcastEvent, YES } from \"../../uicore-ts\"\nimport { CBLocalizedTextObject, CBUserProfile } from \"./CBDataInterfaces\"\nimport { CBLanguageService } from \"./CBLanguageService\"\nimport { CBServerClient } from \"./CBServerClient\"\nimport { CBSocketClient } from \"./CBSocketClient\"\n\n\ndeclare interface CBDialogViewShower {\n \n alert(text: string, dismissCallback?: Function): void\n \n localizedAlert(textObject: CBLocalizedTextObject, dismissCallback?: Function): void\n \n showActionIndicatorDialog(message: string, dismissCallback?: Function): void\n \n hideActionIndicatorDialog(): void\n \n}\n\n\ndeclare const CBCoreInitializerObject: any\n\n\nexport class CBCore extends UIObject {\n \n private static _sharedInstance: CBCore\n \n viewCores: UICore[] = []\n \n _isUserLoggedIn = NO\n _cachedMinimizedChatInquiryIDs: string[] = nil\n _socketClient: CBSocketClient = new CBSocketClient(this)\n _serverClient: CBServerClient = new CBServerClient(this)\n \n _functionsToCallForEachSocketClient: (() => void)[] = []\n \n _models: any[] = []\n \n dialogViewShowerClass: CBDialogViewShower = nil\n \n constructor() {\n \n super()\n \n if (CBCoreInitializerObject) {\n \n CBLanguageService.useStoredLanguageValues(CBCoreInitializerObject.languageValues)\n \n }\n \n \n window.addEventListener(\"storage\", function (this: CBCore, event: StorageEvent) {\n \n if (event.newValue == event.oldValue) {\n return\n }\n \n //console.log(\"\" + event.key + \" changed to \" + event.newValue + \" from \" + event.oldValue);\n \n \n if (event.key == \"CBLanguageKey\") {\n this.didSetLanguageKey()\n }\n \n }.bind(this))\n \n \n //this.checkIfUserIsAuthenticated();\n \n this.didSetLanguageKey()\n \n \n }\n \n \n static initIfNeededWithViewCore(\n viewCore: UICore\n ) {\n CBCore.sharedInstance.viewCores.push(viewCore)\n }\n \n \n static get sharedInstance() {\n if (!CBCore._sharedInstance) {\n CBCore._sharedInstance = new CBCore()\n }\n return CBCore._sharedInstance\n }\n \n \n static broadcastEventName = {\n \n \"userDidLogIn\": \"UserDidLogIn\",\n \"userDidLogOut\": \"UserDidLogOut\"\n \n } as const\n \n broadcastMessageInRootViewTree(message: UIViewBroadcastEvent) {\n \n this.viewCores.everyElement.rootViewController.view.broadcastEventInSubtree(message)\n \n }\n \n \n get socketClient() {\n return this._socketClient\n }\n \n get serverClient() {\n return this._serverClient\n }\n \n \n set isUserLoggedIn(isUserLoggedIn: boolean) {\n const previousValue = this.isUserLoggedIn\n this._isUserLoggedIn = isUserLoggedIn\n this.didSetIsUserLoggedIn(previousValue)\n }\n \n didSetIsUserLoggedIn(previousValue: boolean) {\n \n const isUserLoggedIn = this.isUserLoggedIn\n \n if (isUserLoggedIn && previousValue != isUserLoggedIn) {\n \n // Send message to views\n this.broadcastMessageInRootViewTree({\n name: CBCore.broadcastEventName.userDidLogIn,\n parameters: nil\n })\n \n this.updateLinkTargets()\n \n }\n else if (previousValue != isUserLoggedIn) {\n \n this.performFunctionWithDelay(0.01, function (this: CBCore) {\n \n UIRoute.currentRoute.routeByRemovingComponentsOtherThanOnesNamed([\n \"settings\"\n ]).apply()\n \n this.broadcastMessageInRootViewTree({\n name: CBCore.broadcastEventName.userDidLogOut,\n parameters: nil\n })\n \n this.updateLinkTargets()\n \n }.bind(this))\n \n }\n \n }\n \n updateLinkTargets() {\n this.viewCores.everyElement.rootViewController.view.forEachViewInSubtree(function (view) {\n if (view instanceof UILink) {\n view.updateTarget()\n }\n })\n }\n \n get isUserLoggedIn() {\n return this._isUserLoggedIn\n }\n \n \n private _userProfile: CBUserProfile\n \n get userProfile() {\n return this._userProfile\n }\n \n set userProfile(userProfile: CBUserProfile) {\n this._userProfile = userProfile\n this.didSetUserProfile()\n }\n \n didSetUserProfile() {\n this.isUserLoggedIn = IS(this.userProfile)\n }\n \n \n set languageKey(languageKey: string) {\n if (IS_NOT(languageKey)) {\n localStorage.removeItem(\"CBLanguageKey\")\n }\n localStorage.setItem(\"CBLanguageKey\", JSON.stringify(languageKey))\n this.didSetLanguageKey()\n }\n \n get languageKey() {\n return FIRST(localStorage.getItem(\"CBLanguageKey\"), CBLanguageService.defaultLanguageKey).replace(\n \"\\\"\",\n \"\"\n ).replace(\"\\\"\", \"\")\n }\n \n didSetLanguageKey() {\n UIRoute.currentRoute.routeWithComponent(\n \"settings\",\n { \"language\": this.languageKey },\n YES\n ).applyByReplacingCurrentRouteInHistory()\n }\n \n \n reloadSocketConnection() {\n \n // @ts-ignore\n this.socketClient.socket.disconnect()\n \n const messagesToBeSent = this.socketClient._messagesToBeSent.filter(function (messageItem, index, array) {\n \n return (!messageItem.isBoundToUserWithID || messageItem.isBoundToUserWithID ==\n CBCore.sharedInstance.userProfile?._id)\n \n })\n \n this._socketClient = new CBSocketClient(this)\n this._socketClient._messagesToBeSent = messagesToBeSent\n \n const socketClient = this._socketClient\n \n this._models.forEach(function (model, index, array) {\n \n model.setSocketClient(socketClient)\n \n })\n \n this._functionsToCallForEachSocketClient.forEach(function (functionToCall, index, array) {\n \n functionToCall()\n \n })\n \n \n }\n \n \n callFunctionForEachSocketClient(functionToCall: () => void) {\n this._functionsToCallForEachSocketClient.push(functionToCall)\n functionToCall()\n }\n \n \n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,uBAAmB;AACnB,IAAAA,oBAAqG;AAErG,+BAAkC;AAClC,4BAA+B;AAC/B,4BAA+B;AAmBxB,MAAM,UAAN,MAAM,gBAAe,2BAAS;AAAA,EAiBjC,cAAc;AAEV,UAAM;AAfV,qBAAsB,CAAC;AAEvB,2BAAkB;AAClB,0CAA2C;AAC3C,yBAAgC,IAAI,qCAAe,IAAI;AACvD,yBAAgC,IAAI,qCAAe,IAAI;AAEvD,+CAAsD,CAAC;AAEvD,mBAAiB,CAAC;AAElB,iCAA4C;AAMxC,QAAI,yBAAyB;AAEzB,iDAAkB,wBAAwB,wBAAwB,cAAc;AAAA,IAEpF;AAGA,WAAO,iBAAiB,WAAW,SAAwB,OAAqB;AAE5E,UAAI,MAAM,YAAY,MAAM,UAAU;AAClC;AAAA,MACJ;AAKA,UAAI,MAAM,OAAO,iBAAiB;AAC9B,aAAK,kBAAkB;AAAA,MAC3B;AAAA,IAEJ,EAAE,KAAK,IAAI,CAAC;AAKZ,SAAK,kBAAkB;AAAA,EAG3B;AAAA,EAGA,OAAO,yBACH,UACF;AACE,YAAO,eAAe,UAAU,KAAK,QAAQ;AAAA,EACjD;AAAA,EAGA,WAAW,iBAAiB;AACxB,QAAI,CAAC,QAAO,iBAAiB;AACzB,cAAO,kBAAkB,IAAI,QAAO;AAAA,IACxC;AACA,WAAO,QAAO;AAAA,EAClB;AAAA,EAUA,+BAA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{ ManagerOptions, SocketOptions } from \"socket.io-client\"\nimport { NO } from \"uicore-ts\"\nimport { FIRST, IS, IS_NOT, nil, UICore, UILink, UIObject, UIRoute, UIViewBroadcastEvent, YES } from \"../../uicore-ts\"\nimport { CBLocalizedTextObject, CBUserProfile } from \"./CBDataInterfaces\"\nimport { CBLanguageService } from \"./CBLanguageService\"\nimport { CBServerClient } from \"./CBServerClient\"\nimport { CBSocketClient } from \"./CBSocketClient\"\n\n\ndeclare interface CBDialogViewShower {\n \n alert(text: string, dismissCallback?: Function): void\n \n localizedAlert(textObject: CBLocalizedTextObject, dismissCallback?: Function): void\n \n showActionIndicatorDialog(message: string, dismissCallback?: Function): void\n \n hideActionIndicatorDialog(): void\n \n}\n\n\ndeclare const CBCoreInitializerObject: any\n\n\n/**\n * CBCore \u2014 Application session model and library entry point.\n *\n * CBCore is a general-purpose library class. It must not contain any\n * project-specific business logic. To extend it for a specific project,\n * subclass CBCore and register the subclass as the singleton before any\n * other code accesses `CBCore.sharedInstance`.\n *\n * ## Extension pattern\n *\n * 1. Subclass CBCore in your project:\n *\n * ```typescript\n * class MyAppCore extends CBCore {\n *\n * // Additional session-level state goes here.\n * mySessionData: MySessionData | undefined = undefined\n *\n * // Override didSetUserProfile to fetch session data before the\n * // userDidLogIn broadcast fires. Call super only after your data\n * // is ready so that every listener receives a fully populated core.\n * override async didSetUserProfile() {\n * if (IS(this.userProfile)) {\n * this.mySessionData = await fetchMySessionData()\n * }\n * else {\n * this.mySessionData = undefined\n * }\n * super.didSetUserProfile()\n * }\n *\n * // Expose a typed singleton so callers never need CBCore.sharedInstance.\n * static override get sharedInstance(): MyAppCore {\n * return CBCore.sharedInstance as MyAppCore\n * }\n *\n * }\n * ```\n *\n * 2. Register the subclass at app startup, before UICore is initialised:\n *\n * ```typescript\n * CBCore.setSharedInstance(new MyAppCore())\n * CBCore.initIfNeededWithViewCore(new UICore(...))\n * ```\n *\n * 3. From that point on, every call to `CBCore.sharedInstance` \u2014 including\n * calls made internally by the library \u2014 returns the MyAppCore instance.\n * Project code should call `MyAppCore.sharedInstance` for the typed version.\n */\nexport class CBCore extends UIObject {\n \n private static _sharedInstance: CBCore\n \n viewCores: UICore[] = []\n \n _isUserLoggedIn = NO\n _cachedMinimizedChatInquiryIDs: string[] = nil\n _socketClient: CBSocketClient = new CBSocketClient(this)\n _serverClient: CBServerClient = new CBServerClient(this)\n \n _functionsToCallForEachSocketClient: (() => void)[] = []\n \n _models: any[] = []\n \n dialogViewShowerClass: CBDialogViewShower = nil\n \n constructor() {\n \n super()\n \n if (CBCoreInitializerObject) {\n \n CBLanguageService.useStoredLanguageValues(CBCoreInitializerObject.languageValues)\n \n }\n \n \n window.addEventListener(\"storage\", function (this: CBCore, event: StorageEvent) {\n \n if (event.newValue == event.oldValue) {\n return\n }\n \n if (event.key == \"CBLanguageKey\") {\n this.didSetLanguageKey()\n }\n \n }.bind(this))\n \n \n this.didSetLanguageKey()\n \n \n }\n \n \n static initIfNeededWithViewCore(\n viewCore: UICore\n ) {\n CBCore.sharedInstance.viewCores.push(viewCore)\n }\n \n \n /**\n * Returns the shared singleton instance.\n *\n * If `setSharedInstance` was called before this getter was first accessed,\n * that instance is returned. Otherwise a default `CBCore` is created.\n * Library-internal code always goes through this getter, so registering a\n * subclass via `setSharedInstance` is sufficient to replace the singleton\n * for the entire session.\n */\n static get sharedInstance() {\n if (!CBCore._sharedInstance) {\n CBCore._sharedInstance = new CBCore()\n }\n return CBCore._sharedInstance\n }\n \n \n /**\n * Registers a subclass instance as the application singleton.\n *\n * Call this once at app startup, before `CBCore.sharedInstance` or\n * `CBCore.initIfNeededWithViewCore` are first accessed. Calling it after\n * the singleton has already been created has no effect and will throw in\n * development to catch accidental misuse.\n *\n * ```typescript\n * // App entry point \u2014 must be the very first thing that runs.\n * CBCore.setSharedInstance(new MyAppCore())\n * CBCore.initIfNeededWithViewCore(new UICore(\"root\", RootViewController))\n * ```\n */\n static setSharedInstance(instance: CBCore) {\n \n if (CBCore._sharedInstance) {\n /// #if DEV\n throw new Error(\n \"CBCore.setSharedInstance must be called before sharedInstance is first accessed. \" +\n \"Move the call to the very top of your app entry point.\"\n )\n /// #endif\n return\n }\n \n CBCore._sharedInstance = instance\n \n }\n \n \n static broadcastEventName = {\n \n \"userDidLogIn\": \"UserDidLogIn\",\n \"userDidLogOut\": \"UserDidLogOut\"\n \n } as const\n \n broadcastMessageInRootViewTree(message: UIViewBroadcastEvent) {\n \n this.viewCores.everyElement.rootViewController.view.broadcastEventInSubtree(message)\n \n }\n \n \n get socketClient() {\n return this._socketClient\n }\n \n get serverClient() {\n return this._serverClient\n }\n \n \n set isUserLoggedIn(isUserLoggedIn: boolean) {\n const previousValue = this.isUserLoggedIn\n this._isUserLoggedIn = isUserLoggedIn\n this.didSetIsUserLoggedIn(previousValue)\n }\n \n didSetIsUserLoggedIn(previousValue: boolean) {\n \n const isUserLoggedIn = this.isUserLoggedIn\n \n if (isUserLoggedIn && previousValue != isUserLoggedIn) {\n \n // Send message to views\n this.broadcastMessageInRootViewTree({\n name: CBCore.broadcastEventName.userDidLogIn,\n parameters: nil\n })\n \n this.updateLinkTargets()\n \n }\n else if (previousValue != isUserLoggedIn) {\n \n this.performFunctionWithDelay(0.01, function (this: CBCore) {\n \n UIRoute.currentRoute.routeByRemovingComponentsOtherThanOnesNamed([\n \"settings\"\n ]).apply()\n \n this.broadcastMessageInRootViewTree({\n name: CBCore.broadcastEventName.userDidLogOut,\n parameters: nil\n })\n \n this.updateLinkTargets()\n \n }.bind(this))\n \n }\n \n }\n \n updateLinkTargets() {\n this.viewCores.everyElement.rootViewController.view.forEachViewInSubtree(function (view) {\n if (view instanceof UILink) {\n view.updateTarget()\n }\n })\n }\n \n get isUserLoggedIn() {\n return this._isUserLoggedIn\n }\n \n \n private _userProfile: CBUserProfile\n \n get userProfile() {\n return this._userProfile\n }\n \n set userProfile(userProfile: CBUserProfile) {\n this._userProfile = userProfile\n this.didSetUserProfile()\n }\n \n /**\n * Called whenever `userProfile` is assigned.\n *\n * The default implementation derives `isUserLoggedIn` from the profile\n * and triggers the login/logout broadcast via `didSetIsUserLoggedIn`.\n *\n * Subclasses may override this to fetch additional session data before\n * the broadcast fires. The override must be `async` and must call\n * `super.didSetUserProfile()` after it has finished populating any\n * extra state, so that all broadcast listeners receive a complete core:\n *\n * ```typescript\n * override async didSetUserProfile() {\n * if (IS(this.userProfile)) {\n * this.companyStatus = (await SocketClient.CurrentUserStatusInCompany()).result\n * }\n * else {\n * this.companyStatus = undefined\n * }\n * super.didSetUserProfile() // broadcast fires here\n * }\n * ```\n */\n didSetUserProfile() {\n this.isUserLoggedIn = IS(this.userProfile)\n }\n \n \n set languageKey(languageKey: string) {\n if (IS_NOT(languageKey)) {\n localStorage.removeItem(\"CBLanguageKey\")\n }\n localStorage.setItem(\"CBLanguageKey\", JSON.stringify(languageKey))\n this.didSetLanguageKey()\n }\n \n get languageKey() {\n return FIRST(localStorage.getItem(\"CBLanguageKey\"), CBLanguageService.defaultLanguageKey).replace(\n \"\\\"\",\n \"\"\n ).replace(\"\\\"\", \"\")\n }\n \n didSetLanguageKey() {\n UIRoute.currentRoute.routeWithComponent(\n \"settings\",\n { \"language\": this.languageKey },\n YES\n ).applyByReplacingCurrentRouteInHistory()\n }\n \n \n reloadSocketConnection() {\n \n // @ts-ignore\n this.socketClient.socket.disconnect()\n \n const messagesToBeSent = this.socketClient._messagesToBeSent.filter(function (messageItem, index, array) {\n \n return (!messageItem.isBoundToUserWithID || messageItem.isBoundToUserWithID ==\n CBCore.sharedInstance.userProfile?._id)\n \n })\n \n this._socketClient = new CBSocketClient(this)\n this._socketClient._messagesToBeSent = messagesToBeSent\n \n const socketClient = this._socketClient\n \n this._models.forEach(function (model, index, array) {\n \n model.setSocketClient(socketClient)\n \n })\n \n this._functionsToCallForEachSocketClient.forEach(function (functionToCall, index, array) {\n \n functionToCall()\n \n })\n \n \n }\n \n \n callFunctionForEachSocketClient(functionToCall: () => void) {\n this._functionsToCallForEachSocketClient.push(functionToCall)\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oC,KAAK,cAAc;AAC5D,mBAAe;AAAA,EACnB;AAGJ;AA1Ra,QAsGF,qBAAqB;AAAA,EAExB,gBAAgB;AAAA,EAChB,iBAAiB;AAErB;AA3GG,IAAM,SAAN;",
6
6
  "names": ["import_uicore_ts"]
7
7
  }
@@ -232,6 +232,7 @@ class CBSocketCallbackHolder extends import_uicore_ts.UIObject {
232
232
  this.keysForIdentifiers[messageToSend.identifier] = descriptorKey;
233
233
  }
234
234
  socketDidReceiveMessageForKey(key, message, sendResponseFunction) {
235
+ var _a;
235
236
  if (!this.isValid) {
236
237
  return;
237
238
  }
@@ -252,7 +253,16 @@ class CBSocketCallbackHolder extends import_uicore_ts.UIObject {
252
253
  const responseDataHash = message.messageDataHash;
253
254
  if (!message.keepWaitingForResponses) {
254
255
  delete this.keysForIdentifiers[message.inResponseToIdentifier];
255
- delete this.messageDescriptors[descriptorKey];
256
+ }
257
+ if (document.cbsocketclientlogmessages) {
258
+ console.log(
259
+ "Callback holder is handling message. [",
260
+ (_a = descriptorsForKey.firstElement) == null ? void 0 : _a.key,
261
+ "] ",
262
+ message,
263
+ " Descriptors for key is ",
264
+ ...descriptorsForKey
265
+ );
256
266
  }
257
267
  const callCompletionFunction = (descriptor, storedResponseCondition = import_uicore_ts.NO) => {
258
268
  var messageData = message.messageData;
@@ -343,6 +353,9 @@ class CBSocketCallbackHolder extends import_uicore_ts.UIObject {
343
353
  descriptorsForKey.removeElement(descriptor);
344
354
  }
345
355
  }.bind(this));
356
+ if (!message.keepWaitingForResponses && descriptorsForKey.length === 0) {
357
+ delete this.messageDescriptors[descriptorKey];
358
+ }
346
359
  }
347
360
  }
348
361
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../scripts/CBSocketCallbackHolder.ts"],
4
- "sourcesContent": ["import objectHash from \"object-hash\"\nimport { FIRST, IS, IS_NOT, nil, NO, UIObject, YES } from \"../../uicore-ts\"\nimport {\n CBSocketMessage,\n CBSocketMessageCompletionFunction,\n CBSocketMessageHandlerFunction, CBSocketMessageSendResponseFunction, CBSocketMultipleMessage,\n CBSocketMultipleMessagecompletionFunction, CBSocketMultipleMessageObject\n} from \"./CBDataInterfaces\"\nimport { CBSocketClient } from \"./CBSocketClient\"\n\n\n\n\n\ninterface CBSocketCallbackHolderMessageDescriptor {\n \n key: string;\n message: {\n identifier: string;\n inResponseToIdentifier?: string;\n keepWaitingForResponses?: boolean;\n }\n \n \n sentAtTime: number;\n \n //completionTriggered: boolean;\n \n messageDataHash: string;\n \n responseDataHash?: string;\n \n mainResponseReceived: boolean;\n \n anyMainResponseReceived: boolean;\n \n completionPolicy: string;\n completionFunction: CBSocketMessageCompletionFunction;\n \n}\n\n\ninterface CBSocketCallbackHolderStoredResponseObject {\n \n messageKey: string;\n messageData: any;\n messageDataHash: string;\n \n}\n\n\n\n\nexport class CBSocketCallbackHolder extends UIObject {\n \n messageDescriptors: {\n \n [x: string]: CBSocketCallbackHolderMessageDescriptor[]\n \n } = {}\n \n handlers: {\n [x: string]: CBSocketMessageHandlerFunction[]\n } = {}\n \n onetimeHandlers: {\n [x: string]: CBSocketMessageHandlerFunction[]\n } = {}\n \n keysForIdentifiers: {\n \n [x: string]: string\n \n } = {}\n \n \n isValid = YES\n _storeableResponseKeys: string[] = []\n _storedResponseHashesDictionary: {\n \n [x: string]: {\n \n hash: string,\n validityDate: number\n \n }\n \n } = {}\n _verifiedResponseHashesDictionary: {\n \n [x: string]: boolean\n \n } = {}\n \n _socketClient: CBSocketClient\n \n \n \n \n \n constructor(socketClient: CBSocketClient, previousCallbackHolder?: CBSocketCallbackHolder) {\n \n super()\n \n \n this._socketClient = socketClient\n \n if (IS(previousCallbackHolder)) {\n \n this.handlers = previousCallbackHolder.handlers\n this._verifiedResponseHashesDictionary = previousCallbackHolder._verifiedResponseHashesDictionary\n \n }\n \n \n \n \n \n }\n \n \n \n \n \n triggerDisconnectHandlers() {\n \n this.messageDescriptors.forEach(function (descriptor: CBSocketCallbackHolderMessageDescriptor, key: string) {\n \n if (descriptor.mainResponseReceived) {\n \n descriptor.completionFunction(CBSocketClient.disconnectionMessage, nil)\n \n }\n \n })\n \n }\n \n \n \n \n \n registerHandler(key: string, handlerFunction: CBSocketMessageHandlerFunction) {\n \n \n if (!this.handlers[key]) {\n \n this.handlers[key] = []\n \n }\n \n this.handlers[key].push(handlerFunction)\n \n \n \n }\n \n registerOnetimeHandler(key: string, handlerFunction: CBSocketMessageHandlerFunction) {\n \n \n if (!this.onetimeHandlers[key]) {\n \n this.onetimeHandlers[key] = []\n \n }\n \n this.onetimeHandlers[key].push(handlerFunction)\n \n \n \n }\n \n \n \n \n \n get storedResponseHashesDictionary() {\n \n if (IS_NOT(this._storedResponseHashesDictionary)) {\n \n this._storedResponseHashesDictionary = JSON.parse(localStorage[\"CBSocketResponseHashesDictionary\"] || \"{}\")\n \n }\n \n return this._storedResponseHashesDictionary\n \n }\n \n storedResponseHashObjectForKey(requestKey: string, requestDataHash: string) {\n \n const localStorageKey = this.keyForRequestKeyAndRequestDataHash(requestKey, requestDataHash)\n \n const hashObject = this.storedResponseHashesDictionary[localStorageKey]\n \n const result = FIRST(hashObject, {} as any)\n \n \n \n return result\n \n }\n \n storedResponseForKey(requestKey: string, requestDataHash: string) {\n \n const localStorageKey = this.keyForRequestKeyAndRequestDataHash(requestKey, requestDataHash)\n \n const storedObject = JSON.parse(localStorage[localStorageKey] || \"{}\")\n \n return storedObject.responseMessageData\n \n }\n \n keyForRequestKeyAndRequestDataHash(requestKey: string, requestDataHash: string) {\n \n const result = \"_CBSCH_LS_key_\" + requestKey + \"_\" + requestDataHash\n \n return result\n \n }\n \n storeResponse(\n requestKey: string,\n requestDataHash: string,\n responseMessage: CBSocketMessage<any>,\n responseDataHash: string\n ) {\n \n \n if (!responseMessage.canBeStoredAsResponse ||\n (IS_NOT(responseMessage.messageData) && IS_NOT(responseMessage.messageDataHash))) {\n \n return\n \n }\n \n \n const localStorageKey = this.keyForRequestKeyAndRequestDataHash(requestKey, requestDataHash)\n \n \n var validityDate: number\n \n if (responseMessage.responseValidityDuration) {\n \n validityDate = Date.now() + responseMessage.responseValidityDuration\n \n }\n \n const storedResponseHashesDictionary = this.storedResponseHashesDictionary\n storedResponseHashesDictionary[localStorageKey] = {\n \n hash: responseDataHash,\n validityDate: validityDate!\n \n }\n \n this.saveInLocalStorage(localStorageKey, {\n \n responseMessageData: responseMessage.messageData,\n responseHash: responseDataHash\n \n })\n \n \n this.saveStoredResponseHashesDictionary(storedResponseHashesDictionary)\n \n }\n \n \n \n \n \n private saveStoredResponseHashesDictionary(storedResponseHashesDictionary: { [x: string]: { hash: string; validityDate: number; }; }) {\n \n this.saveInLocalStorage(\"CBSocketResponseHashesDictionary\", storedResponseHashesDictionary)\n \n }\n \n saveInLocalStorage(key: string, object: any) {\n \n \n const stringToSave = JSON.stringify(object)\n \n if (stringToSave != localStorage[key]) {\n \n localStorage[key] = stringToSave\n \n }\n \n \n }\n \n \n \n \n \n socketShouldSendMessage(\n key: string,\n message: CBSocketMessage<any>,\n completionPolicy: string,\n completionFunction: CBSocketMessageCompletionFunction\n ) {\n \n \n \n var result = YES\n \n var triggerStoredResponseImmediately = NO\n \n \n const messageDataHash = objectHash(message.messageData || nil)\n \n const descriptorKey = \"socketMessageDescriptor_\" + key + messageDataHash\n \n this.messageDescriptors[descriptorKey] = (this.messageDescriptors[descriptorKey] || [])\n \n \n const hashObject = this.storedResponseHashObjectForKey(key, messageDataHash)\n message.storedResponseHash = hashObject.hash\n \n \n \n if (completionPolicy == CBSocketClient.completionPolicy.first) {\n \n const descriptorsForKey = (this.messageDescriptors[descriptorKey] || [])\n \n const matchingDescriptor = descriptorsForKey.find(function (descriptor, index, array) {\n return (descriptor.messageDataHash == messageDataHash)\n })\n \n if (matchingDescriptor) {\n \n result = NO\n \n }\n \n }\n \n if (completionPolicy == CBSocketClient.completionPolicy.storedOrFirst) {\n \n const descriptorsForKey = (this.messageDescriptors[descriptorKey] || [])\n \n const matchingDescriptor = descriptorsForKey.find(function (descriptor, index, array) {\n return (descriptor.messageDataHash == messageDataHash)\n })\n \n const storedResponse = IS(message.storedResponseHash)\n \n if (matchingDescriptor ||\n (storedResponse && this._verifiedResponseHashesDictionary[message.storedResponseHash!])) {\n \n result = NO\n \n triggerStoredResponseImmediately = YES\n \n }\n \n }\n \n if (completionPolicy == CBSocketClient.completionPolicy.firstOnly) {\n \n const descriptorsForKey = (this.messageDescriptors[descriptorKey] || [])\n \n const matchingDescriptor = descriptorsForKey.find(function (descriptor, index, array) {\n return (descriptor.messageDataHash == messageDataHash)\n })\n \n if (matchingDescriptor) {\n \n return NO\n \n }\n \n }\n \n \n if (hashObject && hashObject.hash && hashObject.validityDate && message.storedResponseHash &&\n this._verifiedResponseHashesDictionary[message.storedResponseHash] && hashObject.validityDate >\n Date.now()) {\n \n result = NO\n \n triggerStoredResponseImmediately = YES\n \n }\n \n \n if (IS(completionFunction)) {\n \n this.messageDescriptors[descriptorKey].push({\n \n key: key,\n message: {\n \n identifier: message.identifier,\n inResponseToIdentifier: message.inResponseToIdentifier,\n keepWaitingForResponses: message.keepWaitingForResponses\n \n },\n \n sentAtTime: Date.now(),\n \n //completionTriggered: NO,\n \n \n messageDataHash: messageDataHash,\n \n mainResponseReceived: NO,\n anyMainResponseReceived: NO,\n \n \n completionPolicy: completionPolicy,\n completionFunction: completionFunction\n \n })\n \n this.keysForIdentifiers[message.identifier] = descriptorKey\n \n }\n \n \n if (triggerStoredResponseImmediately) {\n \n this.socketDidReceiveMessageForKey(\n CBSocketClient.responseMessageKey,\n {\n \n identifier: nil,\n messageData: nil,\n completionPolicy: CBSocketClient.completionPolicy.directOnly,\n \n inResponseToIdentifier: message.identifier,\n \n useStoredResponse: YES\n \n },\n nil\n )\n \n }\n \n \n return result\n \n \n }\n \n \n \n \n \n static defaultMultipleMessagecompletionFunction(responseMessages: any[], callcompletionFunctions: () => void) {\n callcompletionFunctions()\n }\n \n \n socketWillSendMultipleMessage(\n messageToSend: CBSocketMultipleMessage,\n completionFunction: CBSocketMultipleMessagecompletionFunction = CBSocketCallbackHolder.defaultMultipleMessagecompletionFunction\n ) {\n \n \n \n const key = CBSocketClient.multipleMessageKey\n \n \n const messageDataHash = objectHash(messageToSend.messageData || nil)\n \n const descriptorKey = \"socketMessageDescriptor_\" + key + messageDataHash\n \n this.messageDescriptors[descriptorKey] = (this.messageDescriptors[descriptorKey] || [])\n \n \n messageToSend.storedResponseHash = this.storedResponseHashObjectForKey(key, messageDataHash).hash\n \n \n \n \n \n this.messageDescriptors[descriptorKey].push({\n \n key: key,\n message: {\n \n identifier: messageToSend.identifier,\n inResponseToIdentifier: messageToSend.inResponseToIdentifier,\n keepWaitingForResponses: messageToSend.keepWaitingForResponses\n \n },\n \n sentAtTime: Date.now(),\n \n //completionTriggered: NO,\n \n \n messageDataHash: messageDataHash,\n \n mainResponseReceived: NO,\n anyMainResponseReceived: NO,\n \n \n completionPolicy: CBSocketClient.completionPolicy.directOnly,\n completionFunction: function (\n this: CBSocketCallbackHolder,\n responseMessage: CBSocketMultipleMessageObject[],\n respondWithMessage: any\n ) {\n \n completionFunction(\n responseMessage.map(function (messageObject, index, array) {\n \n return messageObject.message.messageData\n \n }),\n function (this: CBSocketCallbackHolder) {\n \n //console.log(\"Received multiple message response with length of \" + responseMessage.length + \".\");\n \n // Call all completion functions\n responseMessage.forEach(function (\n this: CBSocketCallbackHolder,\n messageObject: CBSocketMultipleMessageObject,\n index: number,\n array: CBSocketMultipleMessageObject[]\n ) {\n \n this._socketClient.didReceiveMessageForKey(messageObject.key, messageObject.message)\n \n }.bind(this))\n \n }.bind(this)\n )\n \n }.bind(this)\n \n })\n \n this.keysForIdentifiers[messageToSend.identifier] = descriptorKey\n \n \n }\n \n \n \n \n \n socketDidReceiveMessageForKey(\n key: string,\n message: CBSocketMessage<any>,\n sendResponseFunction: CBSocketMessageSendResponseFunction\n ) {\n \n \n if (!this.isValid) {\n \n return\n \n }\n \n \n // Call static handlers\n if (this.handlers[key]) {\n \n this.handlers[key].forEach(function (\n this: CBSocketCallbackHolder,\n handler: CBSocketMessageHandlerFunction,\n index: any,\n array: any\n ) {\n \n handler(message.messageData, sendResponseFunction)\n \n }.bind(this))\n \n }\n \n if (this.onetimeHandlers[key]) {\n \n this.onetimeHandlers[key].forEach(function (\n this: CBSocketCallbackHolder,\n handler: CBSocketMessageHandlerFunction\n ) {\n \n handler(message.messageData, sendResponseFunction)\n \n }.bind(this))\n \n delete this.onetimeHandlers[key]\n \n }\n \n \n \n // Temporary response handlers are evaluated here\n if (message.inResponseToIdentifier &&\n (CBSocketClient.responseMessageKey == key || CBSocketClient.multipleMessageKey == key)) {\n \n // Find descriptors for the key of the message that is being responded to\n const descriptorKey = this.keysForIdentifiers[message.inResponseToIdentifier]\n const descriptorsForKey = (this.messageDescriptors[descriptorKey] || [])\n \n // Find response data hash to check for differences\n const responseDataHash = message.messageDataHash\n \n // Remove identifier from dictionary\n if (!message.keepWaitingForResponses) {\n \n delete this.keysForIdentifiers[message.inResponseToIdentifier]\n \n delete this.messageDescriptors[descriptorKey]\n \n }\n \n \n // Function to call completion function\n const callCompletionFunction = (descriptor: CBSocketCallbackHolderMessageDescriptor, storedResponseCondition = NO) => {\n \n var messageData = message.messageData\n \n if (message.useStoredResponse && storedResponseCondition) {\n \n messageData = this.storedResponseForKey(descriptor.key, descriptor.messageDataHash)\n \n const responseHash = this.storedResponseHashObjectForKey(\n descriptor.key,\n descriptor.messageDataHash\n ).hash\n \n const localStorageKey = this.keyForRequestKeyAndRequestDataHash(\n descriptor.key,\n descriptor.messageDataHash\n )\n \n if (message.responseValidityDuration && this.storedResponseHashesDictionary[localStorageKey]) {\n \n this.storedResponseHashesDictionary[localStorageKey].validityDate = Date.now() +\n message.responseValidityDuration\n \n this.saveStoredResponseHashesDictionary(this.storedResponseHashesDictionary)\n \n }\n \n this._verifiedResponseHashesDictionary[responseHash] = YES\n \n console.log(\"Using stored response.\")\n \n }\n \n // Call completionFunction and set response data hash\n descriptor.completionFunction(messageData, sendResponseFunction)\n descriptor.responseDataHash = responseDataHash\n \n }\n \n \n descriptorsForKey.copy().forEach(function (\n this: CBSocketCallbackHolder,\n descriptor: CBSocketCallbackHolderMessageDescriptor,\n index: number,\n array: CBSocketCallbackHolderMessageDescriptor[]\n ) {\n \n \n if ((descriptor.completionPolicy == CBSocketClient.completionPolicy.directOnly &&\n descriptor.message.identifier == message.inResponseToIdentifier) || descriptor.completionPolicy ==\n CBSocketClient.completionPolicy.first || descriptor.completionPolicy ==\n CBSocketClient.completionPolicy.firstOnly || descriptor.completionPolicy ==\n CBSocketClient.completionPolicy.storedOrFirst) {\n \n // Calling completion function and removing descriptor\n \n if (!message.keepWaitingForResponses) {\n \n this.storeResponse(descriptor.key, descriptor.messageDataHash, message, responseDataHash!)\n \n descriptorsForKey.removeElement(descriptor)\n \n sendResponseFunction.respondingToMainResponse = YES\n \n }\n \n callCompletionFunction(descriptor, !message.keepWaitingForResponses)\n \n }\n else if (descriptor.completionPolicy == CBSocketClient.completionPolicy.all) {\n \n // Calling completion function\n callCompletionFunction(descriptor, !message.keepWaitingForResponses)\n \n // Marking descriptor as having been responded to\n if (!message.keepWaitingForResponses) {\n \n if (message.inResponseToIdentifier == descriptor.message.identifier) {\n \n sendResponseFunction.respondingToMainResponse = YES\n descriptor.mainResponseReceived = YES\n descriptorsForKey.removeElement(descriptor)\n \n }\n \n descriptor.anyMainResponseReceived = YES\n \n }\n \n \n \n }\n else if (descriptor.completionPolicy == CBSocketClient.completionPolicy.allDifferent) {\n \n // Calling completionFunction if messageData is different from previous\n if (descriptor.responseDataHash != responseDataHash) {\n \n callCompletionFunction(descriptor, !message.keepWaitingForResponses)\n \n }\n \n // Marking descriptor as having been responded to\n if (!message.keepWaitingForResponses) {\n \n if (message.inResponseToIdentifier == descriptor.message.identifier) {\n \n sendResponseFunction.respondingToMainResponse = YES\n descriptor.mainResponseReceived = YES\n descriptorsForKey.removeElement(descriptor)\n \n }\n \n descriptor.anyMainResponseReceived = YES\n \n }\n \n }\n else if (descriptor.completionPolicy == CBSocketClient.completionPolicy.last &&\n descriptor.message.identifier == message.inResponseToIdentifier) {\n \n if (!message.keepWaitingForResponses) {\n \n // Marking descriptor as having been responded to\n descriptor.mainResponseReceived = YES\n descriptor.anyMainResponseReceived = YES\n \n sendResponseFunction.respondingToMainResponse = YES\n \n }\n else {\n \n descriptor.completionFunction(message.messageData, sendResponseFunction)\n \n }\n \n }\n else if (descriptor.completionPolicy == CBSocketClient.completionPolicy.firstAndLast ||\n descriptor.completionPolicy == CBSocketClient.completionPolicy.firstAndLastIfDifferent) {\n \n if (!message.keepWaitingForResponses) {\n \n // Only calling completionFunction once as a first response call\n if (!descriptor.anyMainResponseReceived) {\n \n callCompletionFunction(descriptor, !message.keepWaitingForResponses)\n \n }\n \n // Marking descriptor as having been responded to\n if (descriptor.message.identifier == message.inResponseToIdentifier) {\n \n descriptor.mainResponseReceived = YES\n sendResponseFunction.respondingToMainResponse = YES\n \n }\n \n descriptor.anyMainResponseReceived = YES\n \n }\n else if (descriptor.message.identifier == message.inResponseToIdentifier &&\n message.keepWaitingForResponses) {\n \n descriptor.completionFunction(message.messageData, sendResponseFunction)\n \n }\n \n }\n \n }.bind(this))\n \n \n \n \n \n // Last message completion policies\n \n const allResponsesReceived = descriptorsForKey.allMatch(function (descriptorObject, index, array) {\n return descriptorObject.mainResponseReceived\n })\n \n descriptorsForKey.copy().forEach(function (\n this: CBSocketCallbackHolder,\n descriptor: CBSocketCallbackHolderMessageDescriptor,\n index: number,\n array: CBSocketCallbackHolderMessageDescriptor[]\n ) {\n \n if ((descriptor.completionPolicy == CBSocketClient.completionPolicy.last ||\n descriptor.completionPolicy == CBSocketClient.completionPolicy.firstAndLast) &&\n allResponsesReceived && !message.keepWaitingForResponses) {\n \n // Calling completionFunction\n callCompletionFunction(descriptor, !message.keepWaitingForResponses)\n \n // Cleaning up\n descriptorsForKey.removeElement(descriptor)\n \n }\n else if (descriptor.completionPolicy == CBSocketClient.completionPolicy.firstAndLastIfDifferent &&\n allResponsesReceived && !message.keepWaitingForResponses) {\n \n // Calling completionFunction if needed\n if (descriptor.responseDataHash != responseDataHash) {\n \n callCompletionFunction(descriptor, !message.keepWaitingForResponses)\n \n }\n \n // Cleaning up\n descriptorsForKey.removeElement(descriptor)\n \n }\n \n }.bind(this))\n \n \n }\n \n \n \n \n \n }\n \n \n \n \n \n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAAuB;AACvB,uBAA0D;AAO1D,4BAA+B;AA6CxB,MAAM,+BAA+B,0BAAS;AAAA,EA+CjD,YAAY,cAA8B,wBAAiD;AAEvF,UAAM;AA/CV,8BAII,CAAC;AAEL,oBAEI,CAAC;AAEL,2BAEI,CAAC;AAEL,8BAII,CAAC;AAGL,mBAAU;AACV,kCAAmC,CAAC;AACpC,2CASI,CAAC;AACL,6CAII,CAAC;AAaD,SAAK,gBAAgB;AAErB,YAAI,qBAAG,sBAAsB,GAAG;AAE5B,WAAK,WAAW,uBAAuB;AACvC,WAAK,oCAAoC,uBAAuB;AAAA,IAEpE;AAAA,EAMJ;AAAA,EAMA,4BAA4B;AAExB,SAAK,mBAAmB,QAAQ,SAAU,YAAqD,KAAa;AAExG,UAAI,WAAW,sBAAsB;AAEjC,mBAAW,mBAAmB,qCAAe,sBAAsB,oBAAG;AAAA,MAE1E;AAAA,IAEJ,CAAC;AAAA,EAEL;AAAA,EAMA,gBAAgB,KAAa,iBAAiD;AAG1E,QAAI,CAAC,KAAK,SAAS,GAAG,GAAG;AAErB,WAAK,SAAS,GAAG,IAAI,CAAC;AAAA,IAE1B;AAEA,SAAK,SAAS,GAAG,EAAE,KAAK,eAAe;AAAA,EAI3C;AAAA,EAEA,uBAAuB,KAAa,iBAAiD;AAGjF,QAAI,CAAC,KAAK,gBAAgB,GAAG,GAAG;AAE5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icore-ts\"\nimport {\n CBSocketMessage,\n CBSocketMessageCompletionFunction,\n CBSocketMessageHandlerFunction, CBSocketMessageSendResponseFunction, CBSocketMultipleMessage,\n CBSocketMultipleMessagecompletionFunction, CBSocketMultipleMessageObject\n} from \"./CBDataInterfaces\"\nimport { CBSocketClient } from \"./CBSocketClient\"\n\n\ninterface CBSocketCallbackHolderMessageDescriptor {\n \n key: string;\n message: {\n identifier: string;\n inResponseToIdentifier?: string;\n keepWaitingForResponses?: boolean;\n }\n \n \n sentAtTime: number;\n \n //completionTriggered: boolean;\n \n messageDataHash: string;\n \n responseDataHash?: string;\n \n mainResponseReceived: boolean;\n \n anyMainResponseReceived: boolean;\n \n completionPolicy: string;\n completionFunction: CBSocketMessageCompletionFunction;\n \n}\n\n\ninterface CBSocketCallbackHolderStoredResponseObject {\n \n messageKey: string;\n messageData: any;\n messageDataHash: string;\n \n}\n\n\nexport class CBSocketCallbackHolder extends UIObject {\n \n messageDescriptors: {\n \n [x: string]: CBSocketCallbackHolderMessageDescriptor[]\n \n } = {}\n \n handlers: {\n [x: string]: CBSocketMessageHandlerFunction[]\n } = {}\n \n onetimeHandlers: {\n [x: string]: CBSocketMessageHandlerFunction[]\n } = {}\n \n keysForIdentifiers: {\n \n [x: string]: string\n \n } = {}\n \n \n isValid = YES\n _storeableResponseKeys: string[] = []\n _storedResponseHashesDictionary: {\n \n [x: string]: {\n \n hash: string,\n validityDate: number\n \n }\n \n } = {}\n _verifiedResponseHashesDictionary: {\n \n [x: string]: boolean\n \n } = {}\n \n _socketClient: CBSocketClient\n \n \n constructor(socketClient: CBSocketClient, previousCallbackHolder?: CBSocketCallbackHolder) {\n \n super()\n \n \n this._socketClient = socketClient\n \n if (IS(previousCallbackHolder)) {\n \n this.handlers = previousCallbackHolder.handlers\n this._verifiedResponseHashesDictionary = previousCallbackHolder._verifiedResponseHashesDictionary\n \n }\n \n \n }\n \n \n triggerDisconnectHandlers() {\n \n this.messageDescriptors.forEach(function (descriptor: CBSocketCallbackHolderMessageDescriptor, key: string) {\n \n if (descriptor.mainResponseReceived) {\n \n descriptor.completionFunction(CBSocketClient.disconnectionMessage, nil)\n \n }\n \n })\n \n }\n \n \n registerHandler(key: string, handlerFunction: CBSocketMessageHandlerFunction) {\n \n \n if (!this.handlers[key]) {\n \n this.handlers[key] = []\n \n }\n \n this.handlers[key].push(handlerFunction)\n \n \n }\n \n registerOnetimeHandler(key: string, handlerFunction: CBSocketMessageHandlerFunction) {\n \n \n if (!this.onetimeHandlers[key]) {\n \n this.onetimeHandlers[key] = []\n \n }\n \n this.onetimeHandlers[key].push(handlerFunction)\n \n \n }\n \n \n get storedResponseHashesDictionary() {\n \n if (IS_NOT(this._storedResponseHashesDictionary)) {\n \n this._storedResponseHashesDictionary = JSON.parse(localStorage[\"CBSocketResponseHashesDictionary\"] || \"{}\")\n \n }\n \n return this._storedResponseHashesDictionary\n \n }\n \n storedResponseHashObjectForKey(requestKey: string, requestDataHash: string) {\n \n const localStorageKey = this.keyForRequestKeyAndRequestDataHash(requestKey, requestDataHash)\n \n const hashObject = this.storedResponseHashesDictionary[localStorageKey]\n \n const result = FIRST(hashObject, {} as any)\n \n \n return result\n \n }\n \n storedResponseForKey(requestKey: string, requestDataHash: string) {\n \n const localStorageKey = this.keyForRequestKeyAndRequestDataHash(requestKey, requestDataHash)\n \n const storedObject = JSON.parse(localStorage[localStorageKey] || \"{}\")\n \n return storedObject.responseMessageData\n \n }\n \n keyForRequestKeyAndRequestDataHash(requestKey: string, requestDataHash: string) {\n \n const result = \"_CBSCH_LS_key_\" + requestKey + \"_\" + requestDataHash\n \n return result\n \n }\n \n storeResponse(\n requestKey: string,\n requestDataHash: string,\n responseMessage: CBSocketMessage<any>,\n responseDataHash: string\n ) {\n \n \n if (!responseMessage.canBeStoredAsResponse ||\n (IS_NOT(responseMessage.messageData) && IS_NOT(responseMessage.messageDataHash))) {\n \n return\n \n }\n \n \n const localStorageKey = this.keyForRequestKeyAndRequestDataHash(requestKey, requestDataHash)\n \n \n var validityDate: number\n \n if (responseMessage.responseValidityDuration) {\n \n validityDate = Date.now() + responseMessage.responseValidityDuration\n \n }\n \n const storedResponseHashesDictionary = this.storedResponseHashesDictionary\n storedResponseHashesDictionary[localStorageKey] = {\n \n hash: responseDataHash,\n validityDate: validityDate!\n \n }\n \n this.saveInLocalStorage(localStorageKey, {\n \n responseMessageData: responseMessage.messageData,\n responseHash: responseDataHash\n \n })\n \n \n this.saveStoredResponseHashesDictionary(storedResponseHashesDictionary)\n \n }\n \n \n private saveStoredResponseHashesDictionary(storedResponseHashesDictionary: {\n [x: string]: { hash: string; validityDate: number; };\n }) {\n \n this.saveInLocalStorage(\"CBSocketResponseHashesDictionary\", storedResponseHashesDictionary)\n \n }\n \n saveInLocalStorage(key: string, object: any) {\n \n \n const stringToSave = JSON.stringify(object)\n \n if (stringToSave != localStorage[key]) {\n \n localStorage[key] = stringToSave\n \n }\n \n \n }\n \n \n socketShouldSendMessage(\n key: string,\n message: CBSocketMessage<any>,\n completionPolicy: string,\n completionFunction: CBSocketMessageCompletionFunction\n ) {\n \n \n var result = YES\n \n var triggerStoredResponseImmediately = NO\n \n \n const messageDataHash = objectHash(message.messageData || nil)\n \n const descriptorKey = \"socketMessageDescriptor_\" + key + messageDataHash\n \n this.messageDescriptors[descriptorKey] = (this.messageDescriptors[descriptorKey] || [])\n \n \n const hashObject = this.storedResponseHashObjectForKey(key, messageDataHash)\n message.storedResponseHash = hashObject.hash\n \n \n if (completionPolicy == CBSocketClient.completionPolicy.first) {\n \n const descriptorsForKey = (this.messageDescriptors[descriptorKey] || [])\n \n const matchingDescriptor = descriptorsForKey.find(function (descriptor, index, array) {\n return (descriptor.messageDataHash == messageDataHash)\n })\n \n if (matchingDescriptor) {\n \n result = NO\n \n }\n \n }\n \n if (completionPolicy == CBSocketClient.completionPolicy.storedOrFirst) {\n \n const descriptorsForKey = (this.messageDescriptors[descriptorKey] || [])\n \n const matchingDescriptor = descriptorsForKey.find(function (descriptor, index, array) {\n return (descriptor.messageDataHash == messageDataHash)\n })\n \n const storedResponse = IS(message.storedResponseHash)\n \n if (matchingDescriptor ||\n (storedResponse && this._verifiedResponseHashesDictionary[message.storedResponseHash!])) {\n \n result = NO\n \n triggerStoredResponseImmediately = YES\n \n }\n \n }\n \n if (completionPolicy == CBSocketClient.completionPolicy.firstOnly) {\n \n const descriptorsForKey = (this.messageDescriptors[descriptorKey] || [])\n \n const matchingDescriptor = descriptorsForKey.find(function (descriptor, index, array) {\n return (descriptor.messageDataHash == messageDataHash)\n })\n \n if (matchingDescriptor) {\n \n return NO\n \n }\n \n }\n \n \n if (hashObject && hashObject.hash && hashObject.validityDate && message.storedResponseHash &&\n this._verifiedResponseHashesDictionary[message.storedResponseHash] && hashObject.validityDate >\n Date.now()) {\n \n result = NO\n \n triggerStoredResponseImmediately = YES\n \n }\n \n \n if (IS(completionFunction)) {\n \n this.messageDescriptors[descriptorKey].push({\n \n key: key,\n message: {\n \n identifier: message.identifier,\n inResponseToIdentifier: message.inResponseToIdentifier,\n keepWaitingForResponses: message.keepWaitingForResponses\n \n },\n \n sentAtTime: Date.now(),\n \n //completionTriggered: NO,\n \n \n messageDataHash: messageDataHash,\n \n mainResponseReceived: NO,\n anyMainResponseReceived: NO,\n \n \n completionPolicy: completionPolicy,\n completionFunction: completionFunction\n \n })\n \n this.keysForIdentifiers[message.identifier] = descriptorKey\n \n }\n \n \n if (triggerStoredResponseImmediately) {\n \n this.socketDidReceiveMessageForKey(\n CBSocketClient.responseMessageKey,\n {\n \n identifier: nil,\n messageData: nil,\n completionPolicy: CBSocketClient.completionPolicy.directOnly,\n \n inResponseToIdentifier: message.identifier,\n \n useStoredResponse: YES\n \n },\n nil\n )\n \n }\n \n \n return result\n \n \n }\n \n \n static defaultMultipleMessagecompletionFunction(responseMessages: any[], callcompletionFunctions: () => void) {\n callcompletionFunctions()\n }\n \n \n socketWillSendMultipleMessage(\n messageToSend: CBSocketMultipleMessage,\n completionFunction: CBSocketMultipleMessagecompletionFunction = CBSocketCallbackHolder.defaultMultipleMessagecompletionFunction\n ) {\n \n \n const key = CBSocketClient.multipleMessageKey\n \n \n const messageDataHash = objectHash(messageToSend.messageData || nil)\n \n const descriptorKey = \"socketMessageDescriptor_\" + key + messageDataHash\n \n this.messageDescriptors[descriptorKey] = (this.messageDescriptors[descriptorKey] || [])\n \n \n messageToSend.storedResponseHash = this.storedResponseHashObjectForKey(key, messageDataHash).hash\n \n \n this.messageDescriptors[descriptorKey].push({\n \n key: key,\n message: {\n \n identifier: messageToSend.identifier,\n inResponseToIdentifier: messageToSend.inResponseToIdentifier,\n keepWaitingForResponses: messageToSend.keepWaitingForResponses\n \n },\n \n sentAtTime: Date.now(),\n \n //completionTriggered: NO,\n \n \n messageDataHash: messageDataHash,\n \n mainResponseReceived: NO,\n anyMainResponseReceived: NO,\n \n \n completionPolicy: CBSocketClient.completionPolicy.directOnly,\n completionFunction: function (\n this: CBSocketCallbackHolder,\n responseMessage: CBSocketMultipleMessageObject[],\n respondWithMessage: any\n ) {\n \n completionFunction(\n responseMessage.map(function (messageObject, index, array) {\n \n return messageObject.message.messageData\n \n }),\n function (this: CBSocketCallbackHolder) {\n \n //console.log(\"Received multiple message response with length of \" + responseMessage.length +\n // \".\");\n \n // Call all completion functions\n responseMessage.forEach(function (\n this: CBSocketCallbackHolder,\n messageObject: CBSocketMultipleMessageObject,\n index: number,\n array: CBSocketMultipleMessageObject[]\n ) {\n \n this._socketClient.didReceiveMessageForKey(messageObject.key, messageObject.message)\n \n }.bind(this))\n \n }.bind(this)\n )\n \n }.bind(this)\n \n })\n \n this.keysForIdentifiers[messageToSend.identifier] = descriptorKey\n \n \n }\n \n \n socketDidReceiveMessageForKey(\n key: string,\n message: CBSocketMessage<any>,\n sendResponseFunction: CBSocketMessageSendResponseFunction\n ) {\n \n \n if (!this.isValid) {\n \n return\n \n }\n \n \n // Call static handlers\n if (this.handlers[key]) {\n \n this.handlers[key].forEach(function (\n this: CBSocketCallbackHolder,\n handler: CBSocketMessageHandlerFunction,\n index: any,\n array: any\n ) {\n \n handler(message.messageData, sendResponseFunction)\n \n }.bind(this))\n \n }\n \n if (this.onetimeHandlers[key]) {\n \n this.onetimeHandlers[key].forEach(function (\n this: CBSocketCallbackHolder,\n handler: CBSocketMessageHandlerFunction\n ) {\n \n handler(message.messageData, sendResponseFunction)\n \n }.bind(this))\n \n delete this.onetimeHandlers[key]\n \n }\n \n \n // Temporary response handlers are evaluated here\n if (message.inResponseToIdentifier &&\n (CBSocketClient.responseMessageKey == key || CBSocketClient.multipleMessageKey == key)) {\n \n // Find descriptors for the key of the message that is being responded to\n const descriptorKey = this.keysForIdentifiers[message.inResponseToIdentifier]\n const descriptorsForKey = (this.messageDescriptors[descriptorKey] || [])\n \n // Find response data hash to check for differences\n const responseDataHash = message.messageDataHash\n \n // Remove identifier from dictionary\n if (!message.keepWaitingForResponses) {\n \n delete this.keysForIdentifiers[message.inResponseToIdentifier]\n \n // Do NOT delete the entire descriptorKey bucket here \u2014 multiple descriptors\n // with identical messageData (e.g. two concurrent requests with undefined payload)\n // share the same bucket. The per-descriptor removeElement() calls below handle\n // individual cleanup. We only delete the bucket once it is fully empty.\n \n }\n \n \n // @ts-ignore\n if (document.cbsocketclientlogmessages) {\n console.log(\n \"Callback holder is handling message. [\", descriptorsForKey.firstElement?.key, \"] \",\n message,\n \" Descriptors for key is \",\n ...descriptorsForKey\n )\n }\n \n // Function to call completion function\n const callCompletionFunction = (\n descriptor: CBSocketCallbackHolderMessageDescriptor,\n storedResponseCondition = NO\n ) => {\n \n var messageData = message.messageData\n \n if (message.useStoredResponse && storedResponseCondition) {\n \n messageData = this.storedResponseForKey(descriptor.key, descriptor.messageDataHash)\n \n const responseHash = this.storedResponseHashObjectForKey(\n descriptor.key,\n descriptor.messageDataHash\n ).hash\n \n const localStorageKey = this.keyForRequestKeyAndRequestDataHash(\n descriptor.key,\n descriptor.messageDataHash\n )\n \n if (message.responseValidityDuration && this.storedResponseHashesDictionary[localStorageKey]) {\n \n this.storedResponseHashesDictionary[localStorageKey].validityDate = Date.now() +\n message.responseValidityDuration\n \n this.saveStoredResponseHashesDictionary(this.storedResponseHashesDictionary)\n \n }\n \n this._verifiedResponseHashesDictionary[responseHash] = YES\n \n console.log(\"Using stored response.\")\n \n }\n \n // Call completionFunction and set response data hash\n descriptor.completionFunction(messageData, sendResponseFunction)\n descriptor.responseDataHash = responseDataHash\n \n }\n \n \n descriptorsForKey.copy().forEach(function (\n this: CBSocketCallbackHolder,\n descriptor: CBSocketCallbackHolderMessageDescriptor,\n index: number,\n array: CBSocketCallbackHolderMessageDescriptor[]\n ) {\n \n \n if ((descriptor.completionPolicy == CBSocketClient.completionPolicy.directOnly &&\n descriptor.message.identifier == message.inResponseToIdentifier) || descriptor.completionPolicy ==\n CBSocketClient.completionPolicy.first || descriptor.completionPolicy ==\n CBSocketClient.completionPolicy.firstOnly || descriptor.completionPolicy ==\n CBSocketClient.completionPolicy.storedOrFirst) {\n \n // Calling completion function and removing descriptor\n \n if (!message.keepWaitingForResponses) {\n \n this.storeResponse(descriptor.key, descriptor.messageDataHash, message, responseDataHash!)\n \n descriptorsForKey.removeElement(descriptor)\n \n sendResponseFunction.respondingToMainResponse = YES\n \n }\n \n callCompletionFunction(descriptor, !message.keepWaitingForResponses)\n \n }\n else if (descriptor.completionPolicy == CBSocketClient.completionPolicy.all) {\n \n // Calling completion function\n callCompletionFunction(descriptor, !message.keepWaitingForResponses)\n \n // Marking descriptor as having been responded to\n if (!message.keepWaitingForResponses) {\n \n if (message.inResponseToIdentifier == descriptor.message.identifier) {\n \n sendResponseFunction.respondingToMainResponse = YES\n descriptor.mainResponseReceived = YES\n descriptorsForKey.removeElement(descriptor)\n \n }\n \n descriptor.anyMainResponseReceived = YES\n \n }\n \n \n }\n else if (descriptor.completionPolicy == CBSocketClient.completionPolicy.allDifferent) {\n \n // Calling completionFunction if messageData is different from previous\n if (descriptor.responseDataHash != responseDataHash) {\n \n callCompletionFunction(descriptor, !message.keepWaitingForResponses)\n \n }\n \n // Marking descriptor as having been responded to\n if (!message.keepWaitingForResponses) {\n \n if (message.inResponseToIdentifier == descriptor.message.identifier) {\n \n sendResponseFunction.respondingToMainResponse = YES\n descriptor.mainResponseReceived = YES\n descriptorsForKey.removeElement(descriptor)\n \n }\n \n descriptor.anyMainResponseReceived = YES\n \n }\n \n }\n else if (descriptor.completionPolicy == CBSocketClient.completionPolicy.last &&\n descriptor.message.identifier == message.inResponseToIdentifier) {\n \n if (!message.keepWaitingForResponses) {\n \n // Marking descriptor as having been responded to\n descriptor.mainResponseReceived = YES\n descriptor.anyMainResponseReceived = YES\n \n sendResponseFunction.respondingToMainResponse = YES\n \n }\n else {\n \n descriptor.completionFunction(message.messageData, sendResponseFunction)\n \n }\n \n }\n else if (descriptor.completionPolicy == CBSocketClient.completionPolicy.firstAndLast ||\n descriptor.completionPolicy == CBSocketClient.completionPolicy.firstAndLastIfDifferent) {\n \n if (!message.keepWaitingForResponses) {\n \n // Only calling completionFunction once as a first response call\n if (!descriptor.anyMainResponseReceived) {\n \n callCompletionFunction(descriptor, !message.keepWaitingForResponses)\n \n }\n \n // Marking descriptor as having been responded to\n if (descriptor.message.identifier == message.inResponseToIdentifier) {\n \n descriptor.mainResponseReceived = YES\n sendResponseFunction.respondingToMainResponse = YES\n \n }\n \n descriptor.anyMainResponseReceived = YES\n \n }\n else if (descriptor.message.identifier == message.inResponseToIdentifier &&\n message.keepWaitingForResponses) {\n \n descriptor.completionFunction(message.messageData, sendResponseFunction)\n \n }\n \n }\n \n }.bind(this))\n \n \n // Last message completion policies\n \n const allResponsesReceived = descriptorsForKey.allMatch(function (descriptorObject, index, array) {\n return descriptorObject.mainResponseReceived\n })\n \n descriptorsForKey.copy().forEach(function (\n this: CBSocketCallbackHolder,\n descriptor: CBSocketCallbackHolderMessageDescriptor,\n index: number,\n array: CBSocketCallbackHolderMessageDescriptor[]\n ) {\n \n if ((descriptor.completionPolicy == CBSocketClient.completionPolicy.last ||\n descriptor.completionPolicy == CBSocketClient.completionPolicy.firstAndLast) &&\n allResponsesReceived && !message.keepWaitingForResponses) {\n \n // Calling completionFunction\n callCompletionFunction(descriptor, !message.keepWaitingForResponses)\n \n // Cleaning up\n descriptorsForKey.removeElement(descriptor)\n \n }\n else if (descriptor.completionPolicy == CBSocketClient.completionPolicy.firstAndLastIfDifferent &&\n allResponsesReceived && !message.keepWaitingForResponses) {\n \n // Calling completionFunction if needed\n if (descriptor.responseDataHash != responseDataHash) {\n \n callCompletionFunction(descriptor, !message.keepWaitingForResponses)\n \n }\n \n // Cleaning up\n descriptorsForKey.removeElement(descriptor)\n \n }\n \n }.bind(this))\n \n \n // Clean up the bucket if all descriptors have been removed\n if (!message.keepWaitingForResponses && descriptorsForKey.length === 0) {\n \n delete this.messageDescriptors[descriptorKey]\n \n }\n \n }\n \n \n }\n \n \n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAAuB;AACvB,uBAA0D;AAO1D,4BAA+B;AAwCxB,MAAM,+BAA+B,0BAAS;AAAA,EA4CjD,YAAY,cAA8B,wBAAiD;AAEvF,UAAM;AA5CV,8BAII,CAAC;AAEL,oBAEI,CAAC;AAEL,2BAEI,CAAC;AAEL,8BAII,CAAC;AAGL,mBAAU;AACV,kCAAmC,CAAC;AACpC,2CASI,CAAC;AACL,6CAII,CAAC;AAUD,SAAK,gBAAgB;AAErB,YAAI,qBAAG,sBAAsB,GAAG;AAE5B,WAAK,WAAW,uBAAuB;AACvC,WAAK,oCAAoC,uBAAuB;AAAA,IAEpE;AAAA,EAGJ;AAAA,EAGA,4BAA4B;AAExB,SAAK,mBAAmB,QAAQ,SAAU,YAAqD,KAAa;AAExG,UAAI,WAAW,sBAAsB;AAEjC,mBAAW,mBAAmB,qCAAe,sBAAsB,oBAAG;AAAA,MAE1E;AAAA,IAEJ,CAAC;AAAA,EAEL;AAAA,EAGA,gBAAgB,KAAa,iBAAiD;AAG1E,QAAI,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,WACS,WAAW,oBAAoB,qCAAe,iBAAiB,2BACpE,wBAAwB,CAAC,QAAQ,yBAAyB;AAG1D,cAAI,WAAW,oBAAoB,kBAAkB;AAEjD,mCAAuB,YAAY,CAAC,QAAQ,uBAAuB;AAAA,UAEvE;AAGA,4BAAkB,cAAc,UAAU;AAAA,QAE9C;AAAA,MAEJ,EAAE,KAAK,IAAI,CAAC;AAIZ,UAAI,CAAC,QAAQ,2BAA2B,kBAAkB,WAAW,GAAG;AAEpE,eAAO,KAAK,mBAAmB,aAAa;AAAA,MAEhD;AAAA,IAEJ;AAAA,EAGJ;AAGJ;",
6
6
  "names": ["objectHash"]
7
7
  }
@@ -81,6 +81,9 @@ const _CBSocketClient = class _CBSocketClient extends import_uicore_ts.UIObject
81
81
  _CBSocketClient.multipleMessageKey,
82
82
  (message) => {
83
83
  console.log("Received " + message.messageData.length + " messages.");
84
+ if (document.cbsocketclientlogmessages) {
85
+ console.log(message.messageData);
86
+ }
84
87
  this.didReceiveMessageForKey(_CBSocketClient.multipleMessageKey, message);
85
88
  }
86
89
  );
@@ -92,6 +95,7 @@ const _CBSocketClient = class _CBSocketClient extends import_uicore_ts.UIObject
92
95
  this._messagesToBeSent = this._messagesToBeSent.filter((messageObject, index, array) => !messagesToCancel.contains(messageObject));
93
96
  }
94
97
  sendUnsentMessages(receiveResponsesTogether = import_uicore_ts.NO, completion) {
98
+ var _a;
95
99
  if (!this._isConnectionEstablished || this._collectMessagesToSendLater) {
96
100
  return;
97
101
  }
@@ -143,6 +147,14 @@ const _CBSocketClient = class _CBSocketClient extends import_uicore_ts.UIObject
143
147
  shouldGroupResponses: receiveResponsesTogether
144
148
  };
145
149
  this._callbackHolder.socketWillSendMultipleMessage(messageObject, completion);
150
+ if (document.cbsocketclientlogmessages) {
151
+ console.log(
152
+ "CB socket client is sending multiple messages. [",
153
+ (_a = groupedMessages.everyElement.key.UI_elementValues) == null ? void 0 : _a.join(", "),
154
+ "] ",
155
+ messageObject
156
+ );
157
+ }
146
158
  this.socket.emit(_CBSocketClient.multipleMessageKey, messageObject);
147
159
  didSendFunctions.forEach((didSendFunction, index, array) => {
148
160
  didSendFunction();
@@ -201,6 +213,14 @@ const _CBSocketClient = class _CBSocketClient extends import_uicore_ts.UIObject
201
213
  completion
202
214
  );
203
215
  if (shouldSendMessage) {
216
+ if (document.cbsocketclientlogmessages) {
217
+ console.log(
218
+ "CB socket client is sending message. [",
219
+ key,
220
+ "] ",
221
+ messageObject
222
+ );
223
+ }
204
224
  this.socket.emit(key, messageObject);
205
225
  }
206
226
  didSendFunction();
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../scripts/CBSocketClient.ts"],
4
- "sourcesContent": ["import { io, ManagerOptions, Socket, SocketOptions } from \"socket.io-client\"\nimport { FIRST_OR_NIL, IF, IS, IS_NIL, IS_NOT, MAKE_ID, nil, NO, RETURNER, UIObject, YES } from \"../../uicore-ts\"\nimport { CBCore } from \"./CBCore\"\nimport {\n CBSocketHandshakeInitMessage,\n CBSocketHandshakeResponseMessage,\n CBSocketMessage,\n CBSocketMessageCompletionFunction,\n CBSocketMessageHandlerFunction,\n CBSocketMessageSendResponseFunction,\n CBSocketMultipleMessage,\n CBSocketMultipleMessagecompletionFunction,\n CBSocketMultipleMessageObject,\n SocketClientInterface\n} from \"./CBDataInterfaces\"\nimport { CBSocketCallbackHolder } from \"./CBSocketCallbackHolder\"\n\n\ndeclare interface CBSocketClientMessageToBeSent {\n \n key: string;\n message: any;\n \n inResponseToMessage: CBSocketMessage<any>;\n keepWaitingForResponses: boolean;\n \n isBoundToUserWithID: string;\n \n completionPolicy: string;\n \n didSendFunction?: () => void;\n \n completion: CBSocketMessageCompletionFunction;\n \n}\n\n\ndeclare interface CBSocketClientErrorMessage {\n \n _isCBSocketErrorMessage: boolean;\n \n messageData: any;\n \n}\n\n\ntype FilterConditionally<Source, Condition> = Pick<Source, { [K in keyof Source]: Source[K] extends Condition ? K : never }[keyof Source]>;\n\n\nexport function IS_SOCKET_ERROR(object: any): object is CBSocketClientErrorMessage {\n \n const result = (IS(object) && object._isCBSocketErrorMessage)\n \n return result\n \n}\n\nexport function IS_NOT_SOCKET_ERROR(object: any) {\n \n return !IS_SOCKET_ERROR(object)\n \n}\n\n\nexport class CBSocketClient extends UIObject {\n \n _socket: Socket\n _isConnectionEstablished = NO\n \n _collectMessagesToSendLater = NO\n \n _messagesToBeSent: CBSocketClientMessageToBeSent[] = []\n \n static _sharedInstance: CBSocketClient\n \n _core: CBCore\n \n _subscribedKeys: {\n [x: string]: boolean\n } = {}\n \n _callbackHolder = new CBSocketCallbackHolder(this)\n \n static responseMessageKey = \"CBSocketResponseMessage\"\n static multipleMessageKey = \"CBSocketMultipleMessage\"\n \n \n static disconnectionMessage: CBSocketClientErrorMessage = {\n \n _isCBSocketErrorMessage: YES,\n \n messageData: \"Server disconnected\"\n \n }\n \n \n constructor(core: CBCore) {\n \n super()\n \n this._core = core\n this._socket = io()\n \n this.socket.on(\"connect\", () => {\n \n console.log(\"Socket.io connected to server. clientID = \", this.socket, \" socketID = \", this.socket)\n \n this.sendUnsentMessages()\n \n })\n \n \n this._callbackHolder = new CBSocketCallbackHolder(this, this._callbackHolder)\n \n this.socket.on(\n \"CBSocketWelcomeMessage\",\n (message: CBSocketMessage<{ userProfile?: Record<string, string> }>) => {\n \n core.userProfile = message.messageData.userProfile\n \n this._isConnectionEstablished = YES\n \n this.sendUnsentMessages()\n \n }\n )\n \n this.socket.on(\"disconnect\", () => {\n \n console.log(\"Socket.io disconnected from server. clientID = \", this.socket)\n \n this._isConnectionEstablished = NO\n this._callbackHolder.isValid = NO\n this._callbackHolder.triggerDisconnectHandlers()\n \n \n })\n \n \n this.socket.on(\"CBPerformReconnect\", (message?: string) => {\n \n console.log(\"Performing socket reconnection.\")\n \n core.reloadSocketConnection()\n if (message) {\n this._core.dialogViewShowerClass.alert(message)\n }\n \n \n })\n \n \n this._socket.on(\n CBSocketClient.responseMessageKey,\n (message: CBSocketMessage<any>) => {\n \n this.didReceiveMessageForKey(CBSocketClient.responseMessageKey, message)\n \n }\n )\n \n this._socket.on(\n CBSocketClient.multipleMessageKey,\n (message: CBSocketMessage<CBSocketMultipleMessageObject[]>) => {\n \n console.log(\"Received \" + message.messageData.length + \" messages.\")\n this.didReceiveMessageForKey(CBSocketClient.multipleMessageKey, message)\n \n }\n )\n \n \n }\n \n \n get socket() {\n return this._socket\n }\n \n \n cancelUnsentMessages(messagesToCancel: CBSocketClientMessageToBeSent[]) {\n \n this._messagesToBeSent = this._messagesToBeSent.filter((\n messageObject: CBSocketClientMessageToBeSent,\n index: number,\n array: CBSocketClientMessageToBeSent[]\n ) => !messagesToCancel.contains(messageObject))\n \n }\n \n \n sendUnsentMessages(receiveResponsesTogether = NO, completion?: CBSocketMultipleMessagecompletionFunction) {\n \n if (!this._isConnectionEstablished || this._collectMessagesToSendLater) {\n \n return\n \n }\n \n const groupedMessages: CBSocketMultipleMessageObject<any>[] = []\n const didSendFunctions: (() => void)[] = []\n \n \n this._messagesToBeSent.copy().forEach((messageToBeSentObject: CBSocketClientMessageToBeSent) => {\n \n if (this._isConnectionEstablished) {\n \n var message = messageToBeSentObject.message\n if (IS_NOT(message)) {\n message = \"\"\n }\n \n const identifier = MAKE_ID()\n \n const completion = messageToBeSentObject.completion\n \n const messageObject: CBSocketMessage<any> = {\n \n messageData: message,\n identifier: identifier,\n keepWaitingForResponses: messageToBeSentObject.keepWaitingForResponses,\n inResponseToIdentifier: messageToBeSentObject.inResponseToMessage.identifier,\n completionPolicy: messageToBeSentObject.completionPolicy\n \n }\n \n const shouldSendMessage = this._callbackHolder.socketShouldSendMessage(\n messageToBeSentObject.key,\n messageObject,\n messageToBeSentObject.completionPolicy,\n completion\n )\n \n if (shouldSendMessage) {\n \n \n groupedMessages.push({\n \n key: messageToBeSentObject.key,\n message: messageObject\n \n })\n \n \n }\n \n didSendFunctions.push(messageToBeSentObject.didSendFunction!)\n \n \n }\n \n })\n \n \n this._messagesToBeSent = []\n \n if (IS_NOT(groupedMessages.length)) {\n \n return\n \n }\n \n if (groupedMessages.length == 1) {\n \n console.log(\"sending 1 unsent message.\")\n \n }\n else {\n \n console.log(\"Sending \" + groupedMessages.length + \" unsent messages.\")\n \n }\n \n \n const messageObject: CBSocketMultipleMessage = {\n \n messageData: groupedMessages,\n identifier: MAKE_ID(),\n completionPolicy: CBSocketClient.completionPolicy.all,\n \n shouldGroupResponses: receiveResponsesTogether\n \n }\n \n //if (receiveResponsesTogether) {\n \n this._callbackHolder.socketWillSendMultipleMessage(messageObject, completion)\n \n //}\n \n this.socket.emit(CBSocketClient.multipleMessageKey, messageObject)\n \n \n didSendFunctions.forEach((didSendFunction, index, array) => {\n didSendFunction()\n })\n \n }\n \n \n static completionPolicy = {\n \n \"all\": \"all\",\n \"allDifferent\": \"allDifferent\",\n \"first\": \"first\",\n \"last\": \"last\",\n \"firstAndLast\": \"firstAndLast\",\n \"firstAndLastIfDifferent\": \"firstAndLastIfDifferent\",\n \"directOnly\": \"directOnly\",\n \"firstOnly\": \"firstOnly\",\n \"storedOrFirst\": \"storedOrFirst\"\n \n } as const\n \n \n sendUserBoundMessageForKeyWithPolicy(\n key: keyof SocketClientInterface,\n message: any,\n completionPolicy: keyof typeof CBSocketClient.completionPolicy,\n completion?: CBSocketMessageCompletionFunction\n ) {\n \n \n this._sendMessageForKey(key as string, message, undefined, NO, completionPolicy, YES, nil, completion)\n \n }\n \n sendUserBoundMessageForKey(\n key: keyof SocketClientInterface,\n message: any,\n completion?: CBSocketMessageCompletionFunction\n ) {\n \n this._sendMessageForKey(key as string, message, undefined, NO, undefined, YES, nil, completion)\n \n }\n \n sendMessageForKeyWithPolicy(\n key: keyof SocketClientInterface,\n message: any,\n completionPolicy: keyof typeof CBSocketClient.completionPolicy,\n completion?: CBSocketMessageCompletionFunction\n ) {\n \n \n this._sendMessageForKey(key as string, message, undefined, NO, completionPolicy, NO, nil, completion)\n \n }\n \n sendMessageForKey(key: keyof SocketClientInterface, message: any, completion?: CBSocketMessageCompletionFunction) {\n \n this._sendMessageForKey(key as string, message, undefined, NO, undefined, NO, nil, completion)\n \n }\n \n \n resultForMessageForKey(\n key: keyof SocketClientInterface,\n message: any,\n completionPolicy?: keyof typeof CBSocketClient.completionPolicy,\n isUserBound = NO\n ) {\n \n const result = new Promise<{\n \n responseMessage: any,\n result: any,\n errorResult: any,\n \n respondWithMessage: CBSocketMessageSendResponseFunction\n \n }>((resolve, reject) => {\n \n this._sendMessageForKey(\n key as string,\n message,\n undefined,\n NO,\n completionPolicy,\n isUserBound,\n nil,\n (responseMessage, respondWithMessage) => resolve({\n \n responseMessage: responseMessage,\n result: IF(IS_NOT_SOCKET_ERROR(responseMessage))(() => responseMessage).ELSE(RETURNER(undefined)),\n errorResult: IF(IS_SOCKET_ERROR(responseMessage))(() => responseMessage).ELSE(RETURNER(undefined)),\n \n respondWithMessage: respondWithMessage\n \n })\n )\n \n })\n \n return result\n \n }\n \n \n _sendMessageForKey(\n key: string,\n message: any,\n inResponseToMessage: CBSocketMessage<any> = {} as any,\n keepMessageConnectionOpen = NO,\n completionPolicy: keyof typeof CBSocketClient.completionPolicy = CBSocketClient.completionPolicy.directOnly,\n isUserBound = NO,\n didSendFunction: () => void = nil,\n completion: CBSocketMessageCompletionFunction = nil\n ) {\n \n if (IS_NIL(message)) {\n \n message = \"\"\n \n }\n \n if (this._isConnectionEstablished && !this._collectMessagesToSendLater) {\n \n const identifier = MAKE_ID()\n \n const messageObject: CBSocketMessage<any> = {\n \n messageData: message,\n identifier: identifier,\n keepWaitingForResponses: keepMessageConnectionOpen,\n inResponseToIdentifier: inResponseToMessage.identifier,\n completionPolicy: completionPolicy\n \n }\n \n const shouldSendMessage = this._callbackHolder.socketShouldSendMessage(\n key,\n messageObject,\n completionPolicy,\n completion\n )\n \n if (shouldSendMessage) {\n \n this.socket.emit(key, messageObject)\n \n }\n \n didSendFunction()\n \n }\n else {\n \n this._messagesToBeSent.push({\n \n key: key,\n message: message,\n inResponseToMessage: inResponseToMessage,\n keepWaitingForResponses: keepMessageConnectionOpen,\n completionPolicy: completionPolicy,\n isBoundToUserWithID: IF(isUserBound)(RETURNER(FIRST_OR_NIL(CBCore.sharedInstance.userProfile?._id)))(),\n didSendFunction: didSendFunction,\n completion: completion\n \n })\n \n return this._messagesToBeSent.lastElement\n \n }\n \n }\n \n \n sendMessagesAsGroup<FunctionReturnType extends object>(functionToCall: () => FunctionReturnType) {\n \n const collectMessagesToSendLater = this._collectMessagesToSendLater\n \n this._collectMessagesToSendLater = YES\n \n var result = functionToCall()\n \n this._collectMessagesToSendLater = collectMessagesToSendLater\n \n this.sendUnsentMessages()\n \n return result\n \n }\n \n sendAndReceiveMessagesAsGroup<FunctionReturnType extends object>(\n functionToCall: () => FunctionReturnType,\n completion?: CBSocketMultipleMessagecompletionFunction\n ) {\n \n const collectMessagesToSendLater = this._collectMessagesToSendLater\n \n this._collectMessagesToSendLater = YES\n \n var result = functionToCall()\n \n this._collectMessagesToSendLater = collectMessagesToSendLater\n \n this.sendUnsentMessages(YES, completion)\n \n return result\n \n }\n \n \n didReceiveMessageForKey(key: string, message: CBSocketMessage<any>) {\n \n \n const sendResponseFunction: CBSocketMessageSendResponseFunction = function (\n this: CBSocketClient,\n responseMessage: any,\n completion: CBSocketMessageCompletionFunction\n ) {\n \n this._sendMessageForKey(\n CBSocketClient.responseMessageKey,\n responseMessage,\n message,\n NO,\n undefined,\n NO,\n nil,\n completion\n )\n \n }.bind(this) as any\n \n sendResponseFunction.sendIntermediateResponse = function (\n this: CBSocketClient,\n updateMessage: any,\n completion: CBSocketMessageCompletionFunction\n ) {\n \n this._sendMessageForKey(\n CBSocketClient.responseMessageKey,\n updateMessage,\n message,\n YES,\n undefined,\n NO,\n nil,\n completion\n )\n \n }.bind(this)\n \n const sendUserBoundResponseFunction: CBSocketMessageSendResponseFunction = function (\n this: CBSocketClient,\n responseMessage: any,\n completion: CBSocketMessageCompletionFunction\n ) {\n \n this._sendMessageForKey(\n CBSocketClient.responseMessageKey,\n responseMessage,\n message,\n NO,\n undefined,\n YES,\n nil,\n completion\n )\n \n }.bind(this) as any\n \n sendUserBoundResponseFunction.sendIntermediateResponse = function (\n this: CBSocketClient,\n updateMessage: any,\n completion: CBSocketMessageCompletionFunction\n ) {\n \n this._sendMessageForKey(\n CBSocketClient.responseMessageKey,\n updateMessage,\n message,\n YES,\n undefined,\n YES,\n nil,\n completion\n )\n \n }.bind(this)\n \n if (IS_SOCKET_ERROR(message.messageData)) {\n \n console.log(\"CBSocketClient did receive error message.\")\n \n console.log(message.messageData)\n \n \n }\n \n \n this._callbackHolder.socketDidReceiveMessageForKey(key, message, sendResponseFunction)\n \n }\n \n \n addTargetForMessagesForKeys(keys: string[], handlerFunction: CBSocketMessageHandlerFunction) {\n keys.forEach(function (this: CBSocketClient, key: string, index: number, array: string[]) {\n this.addTargetForMessagesForKey(key, handlerFunction)\n }.bind(this))\n }\n \n \n addTargetForMessagesForKey(key: string, handlerFunction: CBSocketMessageHandlerFunction) {\n \n this._callbackHolder.registerHandler(key, handlerFunction)\n \n if (IS_NOT(this._subscribedKeys[key])) {\n \n this._socket.on(key, function (this: CBSocketClient, message: CBSocketMessage<any>) {\n \n this.didReceiveMessageForKey(key, message)\n \n }.bind(this))\n \n this._subscribedKeys[key] = true\n \n }\n \n \n }\n \n addTargetForOneMessageForKey(key: string, handlerFunction: CBSocketMessageHandlerFunction) {\n \n this._callbackHolder.registerOnetimeHandler(key, handlerFunction)\n \n if (IS_NOT(this._subscribedKeys[key])) {\n \n this._socket.on(key, function (this: CBSocketClient, message: CBSocketMessage<any>) {\n \n this.didReceiveMessageForKey(key, message)\n \n }.bind(this))\n \n this._subscribedKeys[key] = true\n \n }\n \n \n }\n \n \n}\n\n\nexport const SocketClient: SocketClientInterface = new Proxy({ \"name\": \"SocketClient\" }, {\n \n get(target, key) {\n \n const result = (\n messageData: any,\n completionPolicy: string | undefined,\n isUserBound: boolean | undefined\n ) => CBCore.sharedInstance.socketClient.resultForMessageForKey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,yBAAyB;AAAA,EAEzB,aAAa;AAEjB;AA7BS,gBA4OF,mBAAmB;AAAA,EAEtB,OAAO;AAAA,EACP,gBAAgB;AAAA,EAChB,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,gBAAgB;AAAA,EAChB,2BAA2B;AAAA,EAC3B,cAAc;AAAA,EACd,aAAa;AAAA,EACb,iBAAiB;AAErB;AAxPG,IAAM,iBAAN;AAukBA,MAAM,eAAsC,IAAI,MAAM,EAAE,QAAQ,eAAe,GAAG;AAAA,EAErF,IAAI,QAAQ,KAAK;AAEb,UAAM,SAAS,CACX,aACA,kBACA,gBACC,qBAAO,eAAe,aAAa;AAAA,MACpC;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACJ;AAGA,WAAO;AAAA,EAEX;AAEJ,CAAC;",
4
+ "sourcesContent": ["import { io, ManagerOptions, Socket, SocketOptions } from \"socket.io-client\"\nimport { FIRST_OR_NIL, IF, IS, IS_NIL, IS_NOT, MAKE_ID, nil, NO, RETURNER, UIObject, YES } from \"../../uicore-ts\"\nimport { CBCore } from \"./CBCore\"\nimport {\n CBSocketHandshakeInitMessage,\n CBSocketHandshakeResponseMessage,\n CBSocketMessage,\n CBSocketMessageCompletionFunction,\n CBSocketMessageHandlerFunction,\n CBSocketMessageSendResponseFunction,\n CBSocketMultipleMessage,\n CBSocketMultipleMessagecompletionFunction,\n CBSocketMultipleMessageObject,\n SocketClientInterface\n} from \"./CBDataInterfaces\"\nimport { CBSocketCallbackHolder } from \"./CBSocketCallbackHolder\"\n\n\ndeclare interface CBSocketClientMessageToBeSent {\n \n key: string;\n message: any;\n \n inResponseToMessage: CBSocketMessage<any>;\n keepWaitingForResponses: boolean;\n \n isBoundToUserWithID: string;\n \n completionPolicy: string;\n \n didSendFunction?: () => void;\n \n completion: CBSocketMessageCompletionFunction;\n \n}\n\n\ndeclare interface CBSocketClientErrorMessage {\n \n _isCBSocketErrorMessage: boolean;\n \n messageData: any;\n \n}\n\n\ntype FilterConditionally<Source, Condition> = Pick<Source, { [K in keyof Source]: Source[K] extends Condition ? K : never }[keyof Source]>;\n\n\nexport function IS_SOCKET_ERROR(object: any): object is CBSocketClientErrorMessage {\n \n const result = (IS(object) && object._isCBSocketErrorMessage)\n \n return result\n \n}\n\nexport function IS_NOT_SOCKET_ERROR(object: any) {\n \n return !IS_SOCKET_ERROR(object)\n \n}\n\n\nexport class CBSocketClient extends UIObject {\n \n _socket: Socket\n _isConnectionEstablished = NO\n \n _collectMessagesToSendLater = NO\n \n _messagesToBeSent: CBSocketClientMessageToBeSent[] = []\n \n static _sharedInstance: CBSocketClient\n \n _core: CBCore\n \n _subscribedKeys: {\n [x: string]: boolean\n } = {}\n \n _callbackHolder = new CBSocketCallbackHolder(this)\n \n static responseMessageKey = \"CBSocketResponseMessage\"\n static multipleMessageKey = \"CBSocketMultipleMessage\"\n \n \n static disconnectionMessage: CBSocketClientErrorMessage = {\n \n _isCBSocketErrorMessage: YES,\n \n messageData: \"Server disconnected\"\n \n }\n \n \n constructor(core: CBCore) {\n \n super()\n \n this._core = core\n this._socket = io()\n \n this.socket.on(\"connect\", () => {\n \n console.log(\"Socket.io connected to server. clientID = \", this.socket, \" socketID = \", this.socket)\n \n this.sendUnsentMessages()\n \n })\n \n \n this._callbackHolder = new CBSocketCallbackHolder(this, this._callbackHolder)\n \n this.socket.on(\n \"CBSocketWelcomeMessage\",\n (message: CBSocketMessage<{ userProfile?: Record<string, string> }>) => {\n \n core.userProfile = message.messageData.userProfile\n \n this._isConnectionEstablished = YES\n \n this.sendUnsentMessages()\n \n }\n )\n \n this.socket.on(\"disconnect\", () => {\n \n console.log(\"Socket.io disconnected from server. clientID = \", this.socket)\n \n this._isConnectionEstablished = NO\n this._callbackHolder.isValid = NO\n this._callbackHolder.triggerDisconnectHandlers()\n \n \n })\n \n \n this.socket.on(\"CBPerformReconnect\", (message?: string) => {\n \n console.log(\"Performing socket reconnection.\")\n \n core.reloadSocketConnection()\n if (message) {\n this._core.dialogViewShowerClass.alert(message)\n }\n \n \n })\n \n \n this._socket.on(\n CBSocketClient.responseMessageKey,\n (message: CBSocketMessage<any>) => {\n \n this.didReceiveMessageForKey(CBSocketClient.responseMessageKey, message)\n \n }\n )\n \n this._socket.on(\n CBSocketClient.multipleMessageKey,\n (message: CBSocketMessage<CBSocketMultipleMessageObject[]>) => {\n \n console.log(\"Received \" + message.messageData.length + \" messages.\")\n // @ts-ignore\n if (document.cbsocketclientlogmessages) {\n console.log(message.messageData)\n }\n this.didReceiveMessageForKey(CBSocketClient.multipleMessageKey, message)\n \n }\n )\n \n \n }\n \n \n get socket() {\n return this._socket\n }\n \n \n cancelUnsentMessages(messagesToCancel: CBSocketClientMessageToBeSent[]) {\n \n this._messagesToBeSent = this._messagesToBeSent.filter((\n messageObject: CBSocketClientMessageToBeSent,\n index: number,\n array: CBSocketClientMessageToBeSent[]\n ) => !messagesToCancel.contains(messageObject))\n \n }\n \n \n sendUnsentMessages(receiveResponsesTogether = NO, completion?: CBSocketMultipleMessagecompletionFunction) {\n \n if (!this._isConnectionEstablished || this._collectMessagesToSendLater) {\n \n return\n \n }\n \n const groupedMessages: CBSocketMultipleMessageObject<any>[] = []\n const didSendFunctions: (() => void)[] = []\n \n \n this._messagesToBeSent.copy().forEach((messageToBeSentObject: CBSocketClientMessageToBeSent) => {\n \n if (this._isConnectionEstablished) {\n \n var message = messageToBeSentObject.message\n if (IS_NOT(message)) {\n message = \"\"\n }\n \n const identifier = MAKE_ID()\n \n const completion = messageToBeSentObject.completion\n \n const messageObject: CBSocketMessage<any> = {\n \n messageData: message,\n identifier: identifier,\n keepWaitingForResponses: messageToBeSentObject.keepWaitingForResponses,\n inResponseToIdentifier: messageToBeSentObject.inResponseToMessage.identifier,\n completionPolicy: messageToBeSentObject.completionPolicy\n \n }\n \n const shouldSendMessage = this._callbackHolder.socketShouldSendMessage(\n messageToBeSentObject.key,\n messageObject,\n messageToBeSentObject.completionPolicy,\n completion\n )\n \n if (shouldSendMessage) {\n \n \n groupedMessages.push({\n \n key: messageToBeSentObject.key,\n message: messageObject\n \n })\n \n \n }\n \n didSendFunctions.push(messageToBeSentObject.didSendFunction!)\n \n \n }\n \n })\n \n \n this._messagesToBeSent = []\n \n if (IS_NOT(groupedMessages.length)) {\n \n return\n \n }\n \n if (groupedMessages.length == 1) {\n \n console.log(\"sending 1 unsent message.\")\n \n }\n else {\n \n console.log(\"Sending \" + groupedMessages.length + \" unsent messages.\")\n \n }\n \n \n const messageObject: CBSocketMultipleMessage = {\n \n messageData: groupedMessages,\n identifier: MAKE_ID(),\n completionPolicy: CBSocketClient.completionPolicy.all,\n \n shouldGroupResponses: receiveResponsesTogether\n \n }\n \n //if (receiveResponsesTogether) {\n \n this._callbackHolder.socketWillSendMultipleMessage(messageObject, completion)\n \n //}\n \n // @ts-ignore\n if (document.cbsocketclientlogmessages) {\n console.log(\n \"CB socket client is sending multiple messages. [\",\n groupedMessages.everyElement.key.UI_elementValues?.join(\", \"), \"] \",\n messageObject\n )\n }\n \n this.socket.emit(CBSocketClient.multipleMessageKey, messageObject)\n \n \n didSendFunctions.forEach((didSendFunction, index, array) => {\n didSendFunction()\n })\n \n }\n \n \n static completionPolicy = {\n \n \"all\": \"all\",\n \"allDifferent\": \"allDifferent\",\n \"first\": \"first\",\n \"last\": \"last\",\n \"firstAndLast\": \"firstAndLast\",\n \"firstAndLastIfDifferent\": \"firstAndLastIfDifferent\",\n \"directOnly\": \"directOnly\",\n \"firstOnly\": \"firstOnly\",\n \"storedOrFirst\": \"storedOrFirst\"\n \n } as const\n \n \n sendUserBoundMessageForKeyWithPolicy(\n key: keyof SocketClientInterface,\n message: any,\n completionPolicy: keyof typeof CBSocketClient.completionPolicy,\n completion?: CBSocketMessageCompletionFunction\n ) {\n \n \n this._sendMessageForKey(key as string, message, undefined, NO, completionPolicy, YES, nil, completion)\n \n }\n \n sendUserBoundMessageForKey(\n key: keyof SocketClientInterface,\n message: any,\n completion?: CBSocketMessageCompletionFunction\n ) {\n \n this._sendMessageForKey(key as string, message, undefined, NO, undefined, YES, nil, completion)\n \n }\n \n sendMessageForKeyWithPolicy(\n key: keyof SocketClientInterface,\n message: any,\n completionPolicy: keyof typeof CBSocketClient.completionPolicy,\n completion?: CBSocketMessageCompletionFunction\n ) {\n \n \n this._sendMessageForKey(key as string, message, undefined, NO, completionPolicy, NO, nil, completion)\n \n }\n \n sendMessageForKey(key: keyof SocketClientInterface, message: any, completion?: CBSocketMessageCompletionFunction) {\n \n this._sendMessageForKey(key as string, message, undefined, NO, undefined, NO, nil, completion)\n \n }\n \n \n resultForMessageForKey(\n key: keyof SocketClientInterface,\n message: any,\n completionPolicy?: keyof typeof CBSocketClient.completionPolicy,\n isUserBound = NO\n ) {\n \n const result = new Promise<{\n \n responseMessage: any,\n result: any,\n errorResult: any,\n \n respondWithMessage: CBSocketMessageSendResponseFunction\n \n }>((resolve, reject) => {\n \n this._sendMessageForKey(\n key as string,\n message,\n undefined,\n NO,\n completionPolicy,\n isUserBound,\n nil,\n (responseMessage, respondWithMessage) => resolve({\n \n responseMessage: responseMessage,\n result: IF(IS_NOT_SOCKET_ERROR(responseMessage))(() => responseMessage).ELSE(RETURNER(undefined)),\n errorResult: IF(IS_SOCKET_ERROR(responseMessage))(() => responseMessage).ELSE(RETURNER(undefined)),\n \n respondWithMessage: respondWithMessage\n \n })\n )\n \n })\n \n return result\n \n }\n \n \n _sendMessageForKey(\n key: string,\n message: any,\n inResponseToMessage: CBSocketMessage<any> = {} as any,\n keepMessageConnectionOpen = NO,\n completionPolicy: keyof typeof CBSocketClient.completionPolicy = CBSocketClient.completionPolicy.directOnly,\n isUserBound = NO,\n didSendFunction: () => void = nil,\n completion: CBSocketMessageCompletionFunction = nil\n ) {\n \n if (IS_NIL(message)) {\n \n message = \"\"\n \n }\n \n if (this._isConnectionEstablished && !this._collectMessagesToSendLater) {\n \n const identifier = MAKE_ID()\n \n const messageObject: CBSocketMessage<any> = {\n \n messageData: message,\n identifier: identifier,\n keepWaitingForResponses: keepMessageConnectionOpen,\n inResponseToIdentifier: inResponseToMessage.identifier,\n completionPolicy: completionPolicy\n \n }\n \n const shouldSendMessage = this._callbackHolder.socketShouldSendMessage(\n key,\n messageObject,\n completionPolicy,\n completion\n )\n \n if (shouldSendMessage) {\n \n // @ts-ignore\n if (document.cbsocketclientlogmessages) {\n console.log(\n \"CB socket client is sending message. [\", key, \"] \",\n messageObject\n )\n }\n \n this.socket.emit(key, messageObject)\n \n }\n \n didSendFunction()\n \n }\n else {\n \n this._messagesToBeSent.push({\n \n key: key,\n message: message,\n inResponseToMessage: inResponseToMessage,\n keepWaitingForResponses: keepMessageConnectionOpen,\n completionPolicy: completionPolicy,\n isBoundToUserWithID: IF(isUserBound)(RETURNER(FIRST_OR_NIL(CBCore.sharedInstance.userProfile?._id)))(),\n didSendFunction: didSendFunction,\n completion: completion\n \n })\n \n return this._messagesToBeSent.lastElement\n \n }\n \n }\n \n \n sendMessagesAsGroup<FunctionReturnType extends object>(functionToCall: () => FunctionReturnType) {\n \n const collectMessagesToSendLater = this._collectMessagesToSendLater\n \n this._collectMessagesToSendLater = YES\n \n var result = functionToCall()\n \n this._collectMessagesToSendLater = collectMessagesToSendLater\n \n this.sendUnsentMessages()\n \n return result\n \n }\n \n sendAndReceiveMessagesAsGroup<FunctionReturnType extends object>(\n functionToCall: () => FunctionReturnType,\n completion?: CBSocketMultipleMessagecompletionFunction\n ) {\n \n const collectMessagesToSendLater = this._collectMessagesToSendLater\n \n this._collectMessagesToSendLater = YES\n \n var result = functionToCall()\n \n this._collectMessagesToSendLater = collectMessagesToSendLater\n \n this.sendUnsentMessages(YES, completion)\n \n return result\n \n }\n \n \n didReceiveMessageForKey(key: string, message: CBSocketMessage<any>) {\n \n \n const sendResponseFunction: CBSocketMessageSendResponseFunction = function (\n this: CBSocketClient,\n responseMessage: any,\n completion: CBSocketMessageCompletionFunction\n ) {\n \n this._sendMessageForKey(\n CBSocketClient.responseMessageKey,\n responseMessage,\n message,\n NO,\n undefined,\n NO,\n nil,\n completion\n )\n \n }.bind(this) as any\n \n sendResponseFunction.sendIntermediateResponse = function (\n this: CBSocketClient,\n updateMessage: any,\n completion: CBSocketMessageCompletionFunction\n ) {\n \n this._sendMessageForKey(\n CBSocketClient.responseMessageKey,\n updateMessage,\n message,\n YES,\n undefined,\n NO,\n nil,\n completion\n )\n \n }.bind(this)\n \n const sendUserBoundResponseFunction: CBSocketMessageSendResponseFunction = function (\n this: CBSocketClient,\n responseMessage: any,\n completion: CBSocketMessageCompletionFunction\n ) {\n \n this._sendMessageForKey(\n CBSocketClient.responseMessageKey,\n responseMessage,\n message,\n NO,\n undefined,\n YES,\n nil,\n completion\n )\n \n }.bind(this) as any\n \n sendUserBoundResponseFunction.sendIntermediateResponse = function (\n this: CBSocketClient,\n updateMessage: any,\n completion: CBSocketMessageCompletionFunction\n ) {\n \n this._sendMessageForKey(\n CBSocketClient.responseMessageKey,\n updateMessage,\n message,\n YES,\n undefined,\n YES,\n nil,\n completion\n )\n \n }.bind(this)\n \n if (IS_SOCKET_ERROR(message.messageData)) {\n \n console.log(\"CBSocketClient did receive error message.\")\n \n console.log(message.messageData)\n \n \n }\n \n \n this._callbackHolder.socketDidReceiveMessageForKey(key, message, sendResponseFunction)\n \n }\n \n \n addTargetForMessagesForKeys(keys: string[], handlerFunction: CBSocketMessageHandlerFunction) {\n keys.forEach(function (this: CBSocketClient, key: string, index: number, array: string[]) {\n this.addTargetForMessagesForKey(key, handlerFunction)\n }.bind(this))\n }\n \n \n addTargetForMessagesForKey(key: string, handlerFunction: CBSocketMessageHandlerFunction) {\n \n this._callbackHolder.registerHandler(key, handlerFunction)\n \n if (IS_NOT(this._subscribedKeys[key])) {\n \n this._socket.on(key, function (this: CBSocketClient, message: CBSocketMessage<any>) {\n \n this.didReceiveMessageForKey(key, message)\n \n }.bind(this))\n \n this._subscribedKeys[key] = true\n \n }\n \n \n }\n \n addTargetForOneMessageForKey(key: string, handlerFunction: CBSocketMessageHandlerFunction) {\n \n this._callbackHolder.registerOnetimeHandler(key, handlerFunction)\n \n if (IS_NOT(this._subscribedKeys[key])) {\n \n this._socket.on(key, function (this: CBSocketClient, message: CBSocketMessage<any>) {\n \n this.didReceiveMessageForKey(key, message)\n \n }.bind(this))\n \n this._subscribedKeys[key] = true\n \n }\n \n \n }\n \n \n}\n\n\nexport const SocketClient: SocketClientInterface = new Proxy({ \"name\": \"SocketClient\" }, {\n \n get(target, key) {\n \n const result = (\n messageData: any,\n completionPolicy: string | undefined,\n isUserBound: boolean | undefined\n ) => CBCore.sharedInstance.socketClient.resultForMessageForKey(\n key as string,\n messageData,\n completionPolicy as any,\n isUserBound\n )\n \n \n return result\n \n }\n \n}) as any\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA0D;AAC1D,uBAAgG;AAChG,oBAAuB;AAavB,oCAAuC;AAkChC,SAAS,gBAAgB,QAAmD;AAE/E,QAAM,aAAU,qBAAG,MAAM,KAAK,OAAO;AAErC,SAAO;AAEX;AAEO,SAAS,oBAAoB,QAAa;AAE7C,SAAO,CAAC,gBAAgB,MAAM;AAElC;AAGO,MAAM,kBAAN,MAAM,wBAAuB,0BAAS;AAAA,EAgCzC,YAAY,MAAc;AAEtB,UAAM;AA/BV,oCAA2B;AAE3B,uCAA8B;AAE9B,6BAAqD,CAAC;AAMtD,2BAEI,CAAC;AAEL,2BAAkB,IAAI,qDAAuB,IAAI;AAmB7C,SAAK,QAAQ;AACb,SAAK,cAAU,kBAAG;AAElB,SAAK,OAAO,GAAG,WAAW,MAAM;AAE5B,cAAQ,IAAI,8CAA8C,KAAK,QAAQ,gBAAgB,KAAK,MAAM;AAElG,WAAK,mBAAmB;AAAA,IAE5B,CAAC;AAGD,SAAK,kBAAkB,IAAI,qDAAuB,MAAM,KAAK,eAAe;AAE5E,SAAK,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package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cbcore-ts",
3
- "version": "1.0.57",
3
+ "version": "1.0.61",
4
4
  "description": "CBCore is a library to build web applications using pure Typescript.",
5
5
  "main": "compiledScripts/index.js",
6
6
  "types": "compiledScripts/index.d.ts",
package/scripts/CBCore.ts CHANGED
@@ -23,6 +23,56 @@ declare interface CBDialogViewShower {
23
23
  declare const CBCoreInitializerObject: any
24
24
 
25
25
 
26
+ /**
27
+ * CBCore — Application session model and library entry point.
28
+ *
29
+ * CBCore is a general-purpose library class. It must not contain any
30
+ * project-specific business logic. To extend it for a specific project,
31
+ * subclass CBCore and register the subclass as the singleton before any
32
+ * other code accesses `CBCore.sharedInstance`.
33
+ *
34
+ * ## Extension pattern
35
+ *
36
+ * 1. Subclass CBCore in your project:
37
+ *
38
+ * ```typescript
39
+ * class MyAppCore extends CBCore {
40
+ *
41
+ * // Additional session-level state goes here.
42
+ * mySessionData: MySessionData | undefined = undefined
43
+ *
44
+ * // Override didSetUserProfile to fetch session data before the
45
+ * // userDidLogIn broadcast fires. Call super only after your data
46
+ * // is ready so that every listener receives a fully populated core.
47
+ * override async didSetUserProfile() {
48
+ * if (IS(this.userProfile)) {
49
+ * this.mySessionData = await fetchMySessionData()
50
+ * }
51
+ * else {
52
+ * this.mySessionData = undefined
53
+ * }
54
+ * super.didSetUserProfile()
55
+ * }
56
+ *
57
+ * // Expose a typed singleton so callers never need CBCore.sharedInstance.
58
+ * static override get sharedInstance(): MyAppCore {
59
+ * return CBCore.sharedInstance as MyAppCore
60
+ * }
61
+ *
62
+ * }
63
+ * ```
64
+ *
65
+ * 2. Register the subclass at app startup, before UICore is initialised:
66
+ *
67
+ * ```typescript
68
+ * CBCore.setSharedInstance(new MyAppCore())
69
+ * CBCore.initIfNeededWithViewCore(new UICore(...))
70
+ * ```
71
+ *
72
+ * 3. From that point on, every call to `CBCore.sharedInstance` — including
73
+ * calls made internally by the library — returns the MyAppCore instance.
74
+ * Project code should call `MyAppCore.sharedInstance` for the typed version.
75
+ */
26
76
  export class CBCore extends UIObject {
27
77
 
28
78
  private static _sharedInstance: CBCore
@@ -57,9 +107,6 @@ export class CBCore extends UIObject {
57
107
  return
58
108
  }
59
109
 
60
- //console.log("" + event.key + " changed to " + event.newValue + " from " + event.oldValue);
61
-
62
-
63
110
  if (event.key == "CBLanguageKey") {
64
111
  this.didSetLanguageKey()
65
112
  }
@@ -67,8 +114,6 @@ export class CBCore extends UIObject {
67
114
  }.bind(this))
68
115
 
69
116
 
70
- //this.checkIfUserIsAuthenticated();
71
-
72
117
  this.didSetLanguageKey()
73
118
 
74
119
 
@@ -82,6 +127,15 @@ export class CBCore extends UIObject {
82
127
  }
83
128
 
84
129
 
130
+ /**
131
+ * Returns the shared singleton instance.
132
+ *
133
+ * If `setSharedInstance` was called before this getter was first accessed,
134
+ * that instance is returned. Otherwise a default `CBCore` is created.
135
+ * Library-internal code always goes through this getter, so registering a
136
+ * subclass via `setSharedInstance` is sufficient to replace the singleton
137
+ * for the entire session.
138
+ */
85
139
  static get sharedInstance() {
86
140
  if (!CBCore._sharedInstance) {
87
141
  CBCore._sharedInstance = new CBCore()
@@ -90,6 +144,37 @@ export class CBCore extends UIObject {
90
144
  }
91
145
 
92
146
 
147
+ /**
148
+ * Registers a subclass instance as the application singleton.
149
+ *
150
+ * Call this once at app startup, before `CBCore.sharedInstance` or
151
+ * `CBCore.initIfNeededWithViewCore` are first accessed. Calling it after
152
+ * the singleton has already been created has no effect and will throw in
153
+ * development to catch accidental misuse.
154
+ *
155
+ * ```typescript
156
+ * // App entry point — must be the very first thing that runs.
157
+ * CBCore.setSharedInstance(new MyAppCore())
158
+ * CBCore.initIfNeededWithViewCore(new UICore("root", RootViewController))
159
+ * ```
160
+ */
161
+ static setSharedInstance(instance: CBCore) {
162
+
163
+ if (CBCore._sharedInstance) {
164
+ /// #if DEV
165
+ throw new Error(
166
+ "CBCore.setSharedInstance must be called before sharedInstance is first accessed. " +
167
+ "Move the call to the very top of your app entry point."
168
+ )
169
+ /// #endif
170
+ return
171
+ }
172
+
173
+ CBCore._sharedInstance = instance
174
+
175
+ }
176
+
177
+
93
178
  static broadcastEventName = {
94
179
 
95
180
  "userDidLogIn": "UserDidLogIn",
@@ -179,6 +264,29 @@ export class CBCore extends UIObject {
179
264
  this.didSetUserProfile()
180
265
  }
181
266
 
267
+ /**
268
+ * Called whenever `userProfile` is assigned.
269
+ *
270
+ * The default implementation derives `isUserLoggedIn` from the profile
271
+ * and triggers the login/logout broadcast via `didSetIsUserLoggedIn`.
272
+ *
273
+ * Subclasses may override this to fetch additional session data before
274
+ * the broadcast fires. The override must be `async` and must call
275
+ * `super.didSetUserProfile()` after it has finished populating any
276
+ * extra state, so that all broadcast listeners receive a complete core:
277
+ *
278
+ * ```typescript
279
+ * override async didSetUserProfile() {
280
+ * if (IS(this.userProfile)) {
281
+ * this.companyStatus = (await SocketClient.CurrentUserStatusInCompany()).result
282
+ * }
283
+ * else {
284
+ * this.companyStatus = undefined
285
+ * }
286
+ * super.didSetUserProfile() // broadcast fires here
287
+ * }
288
+ * ```
289
+ */
182
290
  didSetUserProfile() {
183
291
  this.isUserLoggedIn = IS(this.userProfile)
184
292
  }
@@ -249,22 +357,3 @@ export class CBCore extends UIObject {
249
357
 
250
358
  }
251
359
 
252
-
253
-
254
-
255
-
256
-
257
-
258
-
259
-
260
-
261
-
262
-
263
-
264
-
265
-
266
-
267
-
268
-
269
-
270
-
@@ -9,9 +9,6 @@ import {
9
9
  import { CBSocketClient } from "./CBSocketClient"
10
10
 
11
11
 
12
-
13
-
14
-
15
12
  interface CBSocketCallbackHolderMessageDescriptor {
16
13
 
17
14
  key: string;
@@ -49,8 +46,6 @@ interface CBSocketCallbackHolderStoredResponseObject {
49
46
  }
50
47
 
51
48
 
52
-
53
-
54
49
  export class CBSocketCallbackHolder extends UIObject {
55
50
 
56
51
  messageDescriptors: {
@@ -95,9 +90,6 @@ export class CBSocketCallbackHolder extends UIObject {
95
90
  _socketClient: CBSocketClient
96
91
 
97
92
 
98
-
99
-
100
-
101
93
  constructor(socketClient: CBSocketClient, previousCallbackHolder?: CBSocketCallbackHolder) {
102
94
 
103
95
  super()
@@ -113,15 +105,9 @@ export class CBSocketCallbackHolder extends UIObject {
113
105
  }
114
106
 
115
107
 
116
-
117
-
118
-
119
108
  }
120
109
 
121
110
 
122
-
123
-
124
-
125
111
  triggerDisconnectHandlers() {
126
112
 
127
113
  this.messageDescriptors.forEach(function (descriptor: CBSocketCallbackHolderMessageDescriptor, key: string) {
@@ -137,9 +123,6 @@ export class CBSocketCallbackHolder extends UIObject {
137
123
  }
138
124
 
139
125
 
140
-
141
-
142
-
143
126
  registerHandler(key: string, handlerFunction: CBSocketMessageHandlerFunction) {
144
127
 
145
128
 
@@ -152,7 +135,6 @@ export class CBSocketCallbackHolder extends UIObject {
152
135
  this.handlers[key].push(handlerFunction)
153
136
 
154
137
 
155
-
156
138
  }
157
139
 
158
140
  registerOnetimeHandler(key: string, handlerFunction: CBSocketMessageHandlerFunction) {
@@ -167,13 +149,9 @@ export class CBSocketCallbackHolder extends UIObject {
167
149
  this.onetimeHandlers[key].push(handlerFunction)
168
150
 
169
151
 
170
-
171
152
  }
172
153
 
173
154
 
174
-
175
-
176
-
177
155
  get storedResponseHashesDictionary() {
178
156
 
179
157
  if (IS_NOT(this._storedResponseHashesDictionary)) {
@@ -195,7 +173,6 @@ export class CBSocketCallbackHolder extends UIObject {
195
173
  const result = FIRST(hashObject, {} as any)
196
174
 
197
175
 
198
-
199
176
  return result
200
177
 
201
178
  }
@@ -266,10 +243,9 @@ export class CBSocketCallbackHolder extends UIObject {
266
243
  }
267
244
 
268
245
 
269
-
270
-
271
-
272
- private saveStoredResponseHashesDictionary(storedResponseHashesDictionary: { [x: string]: { hash: string; validityDate: number; }; }) {
246
+ private saveStoredResponseHashesDictionary(storedResponseHashesDictionary: {
247
+ [x: string]: { hash: string; validityDate: number; };
248
+ }) {
273
249
 
274
250
  this.saveInLocalStorage("CBSocketResponseHashesDictionary", storedResponseHashesDictionary)
275
251
 
@@ -290,9 +266,6 @@ export class CBSocketCallbackHolder extends UIObject {
290
266
  }
291
267
 
292
268
 
293
-
294
-
295
-
296
269
  socketShouldSendMessage(
297
270
  key: string,
298
271
  message: CBSocketMessage<any>,
@@ -301,7 +274,6 @@ export class CBSocketCallbackHolder extends UIObject {
301
274
  ) {
302
275
 
303
276
 
304
-
305
277
  var result = YES
306
278
 
307
279
  var triggerStoredResponseImmediately = NO
@@ -318,7 +290,6 @@ export class CBSocketCallbackHolder extends UIObject {
318
290
  message.storedResponseHash = hashObject.hash
319
291
 
320
292
 
321
-
322
293
  if (completionPolicy == CBSocketClient.completionPolicy.first) {
323
294
 
324
295
  const descriptorsForKey = (this.messageDescriptors[descriptorKey] || [])
@@ -445,9 +416,6 @@ export class CBSocketCallbackHolder extends UIObject {
445
416
  }
446
417
 
447
418
 
448
-
449
-
450
-
451
419
  static defaultMultipleMessagecompletionFunction(responseMessages: any[], callcompletionFunctions: () => void) {
452
420
  callcompletionFunctions()
453
421
  }
@@ -459,7 +427,6 @@ export class CBSocketCallbackHolder extends UIObject {
459
427
  ) {
460
428
 
461
429
 
462
-
463
430
  const key = CBSocketClient.multipleMessageKey
464
431
 
465
432
 
@@ -473,9 +440,6 @@ export class CBSocketCallbackHolder extends UIObject {
473
440
  messageToSend.storedResponseHash = this.storedResponseHashObjectForKey(key, messageDataHash).hash
474
441
 
475
442
 
476
-
477
-
478
-
479
443
  this.messageDescriptors[descriptorKey].push({
480
444
 
481
445
  key: key,
@@ -513,7 +477,8 @@ export class CBSocketCallbackHolder extends UIObject {
513
477
  }),
514
478
  function (this: CBSocketCallbackHolder) {
515
479
 
516
- //console.log("Received multiple message response with length of " + responseMessage.length + ".");
480
+ //console.log("Received multiple message response with length of " + responseMessage.length +
481
+ // ".");
517
482
 
518
483
  // Call all completion functions
519
484
  responseMessage.forEach(function (
@@ -540,9 +505,6 @@ export class CBSocketCallbackHolder extends UIObject {
540
505
  }
541
506
 
542
507
 
543
-
544
-
545
-
546
508
  socketDidReceiveMessageForKey(
547
509
  key: string,
548
510
  message: CBSocketMessage<any>,
@@ -589,7 +551,6 @@ export class CBSocketCallbackHolder extends UIObject {
589
551
  }
590
552
 
591
553
 
592
-
593
554
  // Temporary response handlers are evaluated here
594
555
  if (message.inResponseToIdentifier &&
595
556
  (CBSocketClient.responseMessageKey == key || CBSocketClient.multipleMessageKey == key)) {
@@ -606,13 +567,29 @@ export class CBSocketCallbackHolder extends UIObject {
606
567
 
607
568
  delete this.keysForIdentifiers[message.inResponseToIdentifier]
608
569
 
609
- delete this.messageDescriptors[descriptorKey]
570
+ // Do NOT delete the entire descriptorKey bucket here — multiple descriptors
571
+ // with identical messageData (e.g. two concurrent requests with undefined payload)
572
+ // share the same bucket. The per-descriptor removeElement() calls below handle
573
+ // individual cleanup. We only delete the bucket once it is fully empty.
610
574
 
611
575
  }
612
576
 
613
577
 
578
+ // @ts-ignore
579
+ if (document.cbsocketclientlogmessages) {
580
+ console.log(
581
+ "Callback holder is handling message. [", descriptorsForKey.firstElement?.key, "] ",
582
+ message,
583
+ " Descriptors for key is ",
584
+ ...descriptorsForKey
585
+ )
586
+ }
587
+
614
588
  // Function to call completion function
615
- const callCompletionFunction = (descriptor: CBSocketCallbackHolderMessageDescriptor, storedResponseCondition = NO) => {
589
+ const callCompletionFunction = (
590
+ descriptor: CBSocketCallbackHolderMessageDescriptor,
591
+ storedResponseCondition = NO
592
+ ) => {
616
593
 
617
594
  var messageData = message.messageData
618
595
 
@@ -702,7 +679,6 @@ export class CBSocketCallbackHolder extends UIObject {
702
679
  }
703
680
 
704
681
 
705
-
706
682
  }
707
683
  else if (descriptor.completionPolicy == CBSocketClient.completionPolicy.allDifferent) {
708
684
 
@@ -783,9 +759,6 @@ export class CBSocketCallbackHolder extends UIObject {
783
759
  }.bind(this))
784
760
 
785
761
 
786
-
787
-
788
-
789
762
  // Last message completion policies
790
763
 
791
764
  const allResponsesReceived = descriptorsForKey.allMatch(function (descriptorObject, index, array) {
@@ -828,44 +801,17 @@ export class CBSocketCallbackHolder extends UIObject {
828
801
  }.bind(this))
829
802
 
830
803
 
804
+ // Clean up the bucket if all descriptors have been removed
805
+ if (!message.keepWaitingForResponses && descriptorsForKey.length === 0) {
806
+
807
+ delete this.messageDescriptors[descriptorKey]
808
+
809
+ }
810
+
831
811
  }
832
812
 
833
813
 
834
-
835
-
836
-
837
814
  }
838
815
 
839
816
 
840
-
841
-
842
-
843
817
  }
844
-
845
-
846
-
847
-
848
-
849
-
850
-
851
-
852
-
853
-
854
-
855
-
856
-
857
-
858
-
859
-
860
-
861
-
862
-
863
-
864
-
865
-
866
-
867
-
868
-
869
-
870
-
871
-
@@ -164,6 +164,10 @@ export class CBSocketClient extends UIObject {
164
164
  (message: CBSocketMessage<CBSocketMultipleMessageObject[]>) => {
165
165
 
166
166
  console.log("Received " + message.messageData.length + " messages.")
167
+ // @ts-ignore
168
+ if (document.cbsocketclientlogmessages) {
169
+ console.log(message.messageData)
170
+ }
167
171
  this.didReceiveMessageForKey(CBSocketClient.multipleMessageKey, message)
168
172
 
169
173
  }
@@ -288,6 +292,15 @@ export class CBSocketClient extends UIObject {
288
292
 
289
293
  //}
290
294
 
295
+ // @ts-ignore
296
+ if (document.cbsocketclientlogmessages) {
297
+ console.log(
298
+ "CB socket client is sending multiple messages. [",
299
+ groupedMessages.everyElement.key.UI_elementValues?.join(", "), "] ",
300
+ messageObject
301
+ )
302
+ }
303
+
291
304
  this.socket.emit(CBSocketClient.multipleMessageKey, messageObject)
292
305
 
293
306
 
@@ -437,6 +450,14 @@ export class CBSocketClient extends UIObject {
437
450
 
438
451
  if (shouldSendMessage) {
439
452
 
453
+ // @ts-ignore
454
+ if (document.cbsocketclientlogmessages) {
455
+ console.log(
456
+ "CB socket client is sending message. [", key, "] ",
457
+ messageObject
458
+ )
459
+ }
460
+
440
461
  this.socket.emit(key, messageObject)
441
462
 
442
463
  }