cbcore-ts 1.1.1 → 1.1.6

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.
@@ -104,6 +104,13 @@ export declare class CBCore extends UIObject {
104
104
  get serverClient(): CBServerClient;
105
105
  set isUserLoggedIn(isUserLoggedIn: boolean);
106
106
  didSetIsUserLoggedIn(previousValue: boolean): void;
107
+ /**
108
+ * Called when the user transitions from logged-in to logged-out.
109
+ * The default implementation clears the route and broadcasts `userDidLogOut`.
110
+ * Subclasses may override this to suppress the route change when they intend
111
+ * to navigate somewhere specific immediately after logout.
112
+ */
113
+ didLogOut(): void;
107
114
  updateLinkTargets(): void;
108
115
  get isUserLoggedIn(): boolean;
109
116
  private _userProfile;
@@ -114,18 +114,27 @@ const _CBCore = class _CBCore extends import_uicore_ts2.UIObject {
114
114
  });
115
115
  this.updateLinkTargets();
116
116
  } else if (previousValue != isUserLoggedIn) {
117
- this.performFunctionWithDelay(0.01, function() {
118
- import_uicore_ts2.UIRoute.currentRoute.routeByRemovingComponentsOtherThanOnesNamed([
119
- "settings"
120
- ]).apply();
121
- this.broadcastMessageInRootViewTree({
122
- name: _CBCore.broadcastEventName.userDidLogOut,
123
- parameters: import_uicore_ts2.nil
124
- });
125
- this.updateLinkTargets();
126
- }.bind(this));
117
+ this.didLogOut();
127
118
  }
128
119
  }
120
+ /**
121
+ * Called when the user transitions from logged-in to logged-out.
122
+ * The default implementation clears the route and broadcasts `userDidLogOut`.
123
+ * Subclasses may override this to suppress the route change when they intend
124
+ * to navigate somewhere specific immediately after logout.
125
+ */
126
+ didLogOut() {
127
+ this.performFunctionWithDelay(0.01, function() {
128
+ import_uicore_ts2.UIRoute.currentRoute.routeByRemovingComponentsOtherThanOnesNamed([
129
+ "settings"
130
+ ]).apply();
131
+ this.broadcastMessageInRootViewTree({
132
+ name: _CBCore.broadcastEventName.userDidLogOut,
133
+ parameters: import_uicore_ts2.nil
134
+ });
135
+ this.updateLinkTargets();
136
+ }.bind(this));
137
+ }
129
138
  updateLinkTargets() {
130
139
  this.viewCores.everyElement.rootViewController.view.forEachViewInSubtree(function(view) {
131
140
  if (view instanceof import_uicore_ts2.UILink) {
@@ -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\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)\n functionToCall()\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;AAqExB,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;AAEA,UAAI,MAAM,OAAO,iBAAiB;AAC9B,aAAK,kBAAkB;AAAA,MAC3B;AAAA,IAEJ,EAAE,KAAK,IAAI,CAAC;AAGZ,SAAK,kBAAkB;AAAA,EAG3B;AAAA,EAGA,OAAO,yBACH,UACF;AACE,YAAO,eAAe,UAAU,KAAK,QAAQ;AAAA,EACjD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA,WAAW,iBAAiB;AACxB,QAAI,CAAC,QAAO,iBAAiB;AACzB,cAAO,kBAAkB,IAAI,QAAO;AAAA,IACxC;AACA,WAAO,QAAO;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA;AA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AU,OAAO,OAAO,OAAO;AAEhD,YAAM,gBAAgB,YAAY;AAAA,IAEtC,CAAC;AAED,SAAK,oCAAoC,QAAQ,SAAU,gBAAgB,OAAO,OAAO;AAErF,qBAAe;AAAA,IAEnB,CAAC;AAAA,EAGL;AAAA,EAGA,gCAAgC,gBAA4B;AACxD,SAAK,oCAAoC,KAAK,cAAc;AAC5D,mBAAe;AAAA,EACnB;AAGJ;AA1Ra,QAsGF,qBAAqB;AAAA,EAExB,gBAAgB;AAAA,EAChB,iBAAiB;AAErB;AA3GG,IAAM,SAAN;",
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\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.didLogOut()\n \n }\n \n }\n \n /**\n * Called when the user transitions from logged-in to logged-out.\n * The default implementation clears the route and broadcasts `userDidLogOut`.\n * Subclasses may override this to suppress the route change when they intend\n * to navigate somewhere specific immediately after logout.\n */\n didLogOut() {\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 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)\n functionToCall()\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;AAqExB,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;AAEA,UAAI,MAAM,OAAO,iBAAiB;AAC9B,aAAK,kBAAkB;AAAA,MAC3B;AAAA,IAEJ,EAAE,KAAK,IAAI,CAAC;AAGZ,SAAK,k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C/B;AAAA,IACJ,EAAE,sCAAsC;AAAA,EAC5C;AAAA,EAGA,yBAAyB;AAGrB,SAAK,aAAa,OAAO,WAAW;AAEpC,UAAM,mBAAmB,KAAK,aAAa,kBAAkB,OAAO,SAAU,aAAa,OAAO,OAAO;AA/UjH;AAiVY,aAAQ,CAAC,YAAY,uBAAuB,YAAY,yBACpD,aAAO,eAAe,gBAAtB,mBAAmC;AAAA,IAE3C,CAAC;AAED,SAAK,gBAAgB,IAAI,qCAAe,IAAI;AAC5C,SAAK,cAAc,oBAAoB;AAEvC,UAAM,eAAe,KAAK;AAE1B,SAAK,QAAQ,QAAQ,SAAU,OAAO,OAAO,OAAO;AAEhD,YAAM,gBAAgB,YAAY;AAAA,IAEtC,CAAC;AAED,SAAK,oCAAoC,QAAQ,SAAU,gBAAgB,OAAO,OAAO;AAErF,qBAAe;AAAA,IAEnB,CAAC;AAAA,EAGL;AAAA,EAGA,gCAAgC,gBAA4B;AACxD,SAAK,oCAAoC,KAAK,cAAc;AAC5D,mBAAe;AAAA,EACnB;AAGJ;AAtSa,QAsGF,qBAAqB;AAAA,EAExB,gBAAgB;AAAA,EAChB,iBAAiB;AAErB;AA3GG,IAAM,SAAN;",
6
6
  "names": ["import_uicore_ts"]
7
7
  }
@@ -52,13 +52,16 @@ class CBSocketCallbackHolder extends import_uicore_ts.UIObject {
52
52
  }
53
53
  }
54
54
  triggerDisconnectHandlers() {
55
- this.messageDescriptors.forEach(function(descriptor, key) {
56
- var _a;
57
- if (!descriptor.mainResponseReceived) {
58
- this._cancelTimeoutForDescriptor(descriptor);
59
- (_a = descriptor == null ? void 0 : descriptor.completionFunction) == null ? void 0 : _a.call(descriptor, import_CBSocketClient.CBSocketClient.disconnectionMessage, import_uicore_ts.nil);
60
- }
61
- }.bind(this));
55
+ this.messageDescriptors.forEach(
56
+ function(descriptor, key) {
57
+ if (!descriptor.mainResponseReceived) {
58
+ this._cancelTimeoutForDescriptor(descriptor);
59
+ if (typeof (descriptor == null ? void 0 : descriptor.completionFunction) == "function") {
60
+ descriptor.completionFunction(import_CBSocketClient.CBSocketClient.disconnectionMessage, import_uicore_ts.nil);
61
+ }
62
+ }
63
+ }.bind(this)
64
+ );
62
65
  }
63
66
  registerHandler(key, handlerFunction) {
64
67
  if (!this.handlers[key]) {
@@ -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 CBSocketKeepalivePayload,\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 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 _timeoutId?: ReturnType<typeof setTimeout>;\n\n /**\n * Called when a keepalive frame arrives for this descriptor's request.\n * Registered via CBSocketRequestPromise.didReceiveKeepalive().\n */\n keepaliveHandler?: (payload: CBSocketKeepalivePayload) => void;\n\n /**\n * When true the defaultKeepaliveHandler on CBSocketClient is NOT called\n * for this descriptor \u2014 only keepaliveHandler fires.\n */\n keepaliveHandlerOverridesDefault: boolean;\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 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 (this: CBSocketCallbackHolder, descriptor: CBSocketCallbackHolderMessageDescriptor, key: string) {\n \n if (!descriptor.mainResponseReceived) {\n \n this._cancelTimeoutForDescriptor(descriptor)\n descriptor?.completionFunction?.(CBSocketClient.disconnectionMessage, nil)\n \n }\n \n }.bind(this))\n \n }\n \n \n registerHandler(key: string, handlerFunction: CBSocketMessageHandlerFunction) {\n \n if (!this.handlers[key]) {\n \n this.handlers[key] = []\n \n }\n \n this.handlers[key].push(handlerFunction)\n \n }\n \n registerOnetimeHandler(key: string, handlerFunction: CBSocketMessageHandlerFunction) {\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 _scheduleTimeoutForDescriptor(descriptor: CBSocketCallbackHolderMessageDescriptor) {\n \n const timeoutMs = this._socketClient.requestTimeoutMs\n \n if (!timeoutMs) {\n \n return\n \n }\n \n descriptor._timeoutId = setTimeout(() => {\n \n if (descriptor.mainResponseReceived) {\n \n return\n \n }\n \n console.warn(\n `CBSocketCallbackHolder: request \"${descriptor.key}\" timed out after ${timeoutMs} ms`\n )\n \n descriptor.mainResponseReceived = YES\n \n descriptor.completionFunction(CBSocketClient.timeoutMessage, nil)\n \n const descriptorKey = this.keysForIdentifiers[descriptor.message.identifier]\n \n if (descriptorKey) {\n \n const descriptorsForKey = this.messageDescriptors[descriptorKey]\n \n if (descriptorsForKey) {\n \n descriptorsForKey.removeElement(descriptor)\n \n if (descriptorsForKey.length === 0) {\n \n delete this.messageDescriptors[descriptorKey]\n \n }\n \n }\n \n delete this.keysForIdentifiers[descriptor.message.identifier]\n \n }\n \n }, timeoutMs)\n \n }\n \n \n _cancelTimeoutForDescriptor(descriptor: CBSocketCallbackHolderMessageDescriptor) {\n \n if (descriptor._timeoutId !== undefined) {\n \n clearTimeout(descriptor._timeoutId)\n descriptor._timeoutId = undefined\n \n }\n \n }\n\n\n /**\n * Resets the timeout for a descriptor by cancelling the current timer and\n * scheduling a fresh one. Called whenever a keepalive frame arrives so the\n * request gets a full new window to complete.\n */\n _resetTimeoutForDescriptor(descriptor: CBSocketCallbackHolderMessageDescriptor) {\n\n this._cancelTimeoutForDescriptor(descriptor)\n this._scheduleTimeoutForDescriptor(descriptor)\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 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 if (!responseMessage.canBeStoredAsResponse ||\n (IS_NOT(responseMessage.messageData) && IS_NOT(responseMessage.messageDataHash))) {\n \n return\n \n }\n \n const localStorageKey = this.keyForRequestKeyAndRequestDataHash(requestKey, requestDataHash)\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 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 const stringToSave = JSON.stringify(object)\n \n if (stringToSave != localStorage[key]) {\n \n localStorage[key] = stringToSave\n \n }\n \n }\n \n \n socketShouldSendMessage(\n key: string,\n message: CBSocketMessage<any>,\n completionPolicy: string,\n completionFunction: CBSocketMessageCompletionFunction\n ) {\n \n var result = YES\n \n var triggerStoredResponseImmediately = NO\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 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 messageDataHash: messageDataHash,\n \n mainResponseReceived: NO,\n anyMainResponseReceived: NO,\n \n completionPolicy: completionPolicy,\n completionFunction: completionFunction,\n\n keepaliveHandler: undefined,\n keepaliveHandlerOverridesDefault: NO\n \n })\n \n const pushedDescriptor = this.messageDescriptors[descriptorKey].lastElement\n this._scheduleTimeoutForDescriptor(pushedDescriptor)\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 const key = CBSocketClient.multipleMessageKey\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 messageToSend.storedResponseHash = this.storedResponseHashObjectForKey(key, messageDataHash).hash\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 messageDataHash: messageDataHash,\n \n mainResponseReceived: NO,\n anyMainResponseReceived: NO,\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 keepaliveHandler: undefined,\n keepaliveHandlerOverridesDefault: NO\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 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\n // --- Keepalive fast path ---\n // A keepalive frame must not flow through the normal completion machinery.\n // Handle it here and return early so nothing else fires.\n if (message.isKeepalive) {\n\n const payload: CBSocketKeepalivePayload = message.messageData || {}\n\n descriptorsForKey.forEach((descriptor) => {\n\n if (descriptor.message.identifier !== message.inResponseToIdentifier) {\n return\n }\n\n // Reset the client-side timeout so the request gets a full new window\n this._resetTimeoutForDescriptor(descriptor)\n\n // Fire the default handler unless the per-call handler overrides it\n if (!descriptor.keepaliveHandlerOverridesDefault) {\n this._socketClient.defaultKeepaliveHandler?.(payload)\n }\n\n // Fire the per-call handler if one was registered\n descriptor.keepaliveHandler?.(payload)\n\n })\n\n return\n\n }\n // --- End keepalive fast path ---\n\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 this._cancelTimeoutForDescriptor(descriptor)\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;AAQ1D,4BAA+B;AAqDxB,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;AASD,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,SAAwC,YAAqD,KAAa;AA7HlJ;AA+HY,UAAI,CAAC,WAAW,sBAAsB;AAElC,aAAK,4BAA4B,UAAU;AAC3C,uDAAY,uBAAZ,oCAAiC,qCAAe,sBAAsB;AAAA,MAE1E;AAAA,IAEJ,EAAE,KAAK,IAAI,CAAC;AAAA,EAEhB;AAAA,EAGA,gBAAgB,KAAa,iBAAiD;AAE1E,QAAI,CAAC,KAAK,SAAS,GAAG,GAAG;AAErB,WAAK,SAAS,GAAG,IAAI,CAAC;AAAA,IAE1B;AAEA,SAAK,SAAS,GAAG,EAAE,KAAK,eAAe;AAAA,EAE3C;AAAA,EAEA,uBAAuB,KAAa,iBAAiD;AAEjF,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BAAyB;AAG1D,iCAAuB,YAAY,CAAC,QAAQ,uBAAuB;AAGnE,4BAAkB,cAAc,UAAU;AAAA,QAE9C,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;",
4
+ "sourcesContent": ["import objectHash from \"object-hash\"\nimport { FIRST, IS, IS_NOT, nil, NO, UIObject, YES } from \"../../uicore-ts\"\nimport {\n CBSocketKeepalivePayload,\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 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 _timeoutId?: ReturnType<typeof setTimeout>;\n \n /**\n * Called when a keepalive frame arrives for this descriptor's request.\n * Registered via CBSocketRequestPromise.didReceiveKeepalive().\n */\n keepaliveHandler?: (payload: CBSocketKeepalivePayload) => void;\n \n /**\n * When true the defaultKeepaliveHandler on CBSocketClient is NOT called\n * for this descriptor \u2014 only keepaliveHandler fires.\n */\n keepaliveHandlerOverridesDefault: boolean;\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 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(\n function (this: CBSocketCallbackHolder, descriptor: CBSocketCallbackHolderMessageDescriptor, key: string) {\n \n if (!descriptor.mainResponseReceived) {\n \n this._cancelTimeoutForDescriptor(descriptor)\n \n if (typeof descriptor?.completionFunction == \"function\") {\n descriptor.completionFunction(CBSocketClient.disconnectionMessage, nil)\n }\n \n }\n \n }.bind(this))\n \n }\n \n \n registerHandler(key: string, handlerFunction: CBSocketMessageHandlerFunction) {\n \n if (!this.handlers[key]) {\n \n this.handlers[key] = []\n \n }\n \n this.handlers[key].push(handlerFunction)\n \n }\n \n registerOnetimeHandler(key: string, handlerFunction: CBSocketMessageHandlerFunction) {\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 _scheduleTimeoutForDescriptor(descriptor: CBSocketCallbackHolderMessageDescriptor) {\n \n const timeoutMs = this._socketClient.requestTimeoutMs\n \n if (!timeoutMs) {\n \n return\n \n }\n \n descriptor._timeoutId = setTimeout(() => {\n \n if (descriptor.mainResponseReceived) {\n \n return\n \n }\n \n console.warn(\n `CBSocketCallbackHolder: request \"${descriptor.key}\" timed out after ${timeoutMs} ms`\n )\n \n descriptor.mainResponseReceived = YES\n \n descriptor.completionFunction(CBSocketClient.timeoutMessage, nil)\n \n const descriptorKey = this.keysForIdentifiers[descriptor.message.identifier]\n \n if (descriptorKey) {\n \n const descriptorsForKey = this.messageDescriptors[descriptorKey]\n \n if (descriptorsForKey) {\n \n descriptorsForKey.removeElement(descriptor)\n \n if (descriptorsForKey.length === 0) {\n \n delete this.messageDescriptors[descriptorKey]\n \n }\n \n }\n \n delete this.keysForIdentifiers[descriptor.message.identifier]\n \n }\n \n }, timeoutMs)\n \n }\n \n \n _cancelTimeoutForDescriptor(descriptor: CBSocketCallbackHolderMessageDescriptor) {\n \n if (descriptor._timeoutId !== undefined) {\n \n clearTimeout(descriptor._timeoutId)\n descriptor._timeoutId = undefined\n \n }\n \n }\n \n \n /**\n * Resets the timeout for a descriptor by cancelling the current timer and\n * scheduling a fresh one. Called whenever a keepalive frame arrives so the\n * request gets a full new window to complete.\n */\n _resetTimeoutForDescriptor(descriptor: CBSocketCallbackHolderMessageDescriptor) {\n \n this._cancelTimeoutForDescriptor(descriptor)\n this._scheduleTimeoutForDescriptor(descriptor)\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 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 if (!responseMessage.canBeStoredAsResponse ||\n (IS_NOT(responseMessage.messageData) && IS_NOT(responseMessage.messageDataHash))) {\n \n return\n \n }\n \n const localStorageKey = this.keyForRequestKeyAndRequestDataHash(requestKey, requestDataHash)\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 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 const stringToSave = JSON.stringify(object)\n \n if (stringToSave != localStorage[key]) {\n \n localStorage[key] = stringToSave\n \n }\n \n }\n \n \n socketShouldSendMessage(\n key: string,\n message: CBSocketMessage<any>,\n completionPolicy: string,\n completionFunction: CBSocketMessageCompletionFunction\n ) {\n \n var result = YES\n \n var triggerStoredResponseImmediately = NO\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 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 messageDataHash: messageDataHash,\n \n mainResponseReceived: NO,\n anyMainResponseReceived: NO,\n \n completionPolicy: completionPolicy,\n completionFunction: completionFunction,\n \n keepaliveHandler: undefined,\n keepaliveHandlerOverridesDefault: NO\n \n })\n \n const pushedDescriptor = this.messageDescriptors[descriptorKey].lastElement\n this._scheduleTimeoutForDescriptor(pushedDescriptor)\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 const key = CBSocketClient.multipleMessageKey\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 messageToSend.storedResponseHash = this.storedResponseHashObjectForKey(key, messageDataHash).hash\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 messageDataHash: messageDataHash,\n \n mainResponseReceived: NO,\n anyMainResponseReceived: NO,\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 keepaliveHandler: undefined,\n keepaliveHandlerOverridesDefault: NO\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 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 \n // --- Keepalive fast path ---\n // A keepalive frame must not flow through the normal completion machinery.\n // Handle it here and return early so nothing else fires.\n if (message.isKeepalive) {\n \n const payload: CBSocketKeepalivePayload = message.messageData || {}\n \n descriptorsForKey.forEach((descriptor) => {\n \n if (descriptor.message.identifier !== message.inResponseToIdentifier) {\n return\n }\n \n // Reset the client-side timeout so the request gets a full new window\n this._resetTimeoutForDescriptor(descriptor)\n \n // Fire the default handler unless the per-call handler overrides it\n if (!descriptor.keepaliveHandlerOverridesDefault) {\n this._socketClient.defaultKeepaliveHandler?.(payload)\n }\n \n // Fire the per-call handler if one was registered\n descriptor.keepaliveHandler?.(payload)\n \n })\n \n return\n \n }\n // --- End keepalive fast path ---\n \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 this._cancelTimeoutForDescriptor(descriptor)\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;AAQ1D,4BAA+B;AAqDxB,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;AASD,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;AAAA,MACpB,SAAwC,YAAqD,KAAa;AAEtG,YAAI,CAAC,WAAW,sBAAsB;AAElC,eAAK,4BAA4B,UAAU;AAE3C,cAAI,QAAO,yCAAY,uBAAsB,YAAY;AACrD,uBAAW,mBAAmB,qCAAe,sBAAsB,oBAAG;AAAA,UAC1E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J,EAAE,KAAK,IAAI,CAAC;AAKZ,YAAM,uBAAuB,kBAAkB,SAAS,SAAU,kBAAkB,OAAO,OAAO;AAC9F,eAAO,iBAAiB;AAAA,MAC5B,CAAC;AAED,wBAAkB,KAAK,EAAE,QAAQ,SAE7B,YACA,OACA,OACF;AAEE,aAAK,WAAW,oBAAoB,qCAAe,iBAAiB,QAC5D,WAAW,oBAAoB,qCAAe,iBAAiB,iBACnE,wBAAwB,CAAC,QAAQ,yBAAyB;AAG1D,iCAAuB,YAAY,CAAC,QAAQ,uBAAuB;AAGnE,4BAAkB,cAAc,UAAU;AAAA,QAE9C,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", "_a"]
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cbcore-ts",
3
- "version": "1.1.1",
3
+ "version": "1.1.6",
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
@@ -221,25 +221,37 @@ export class CBCore extends UIObject {
221
221
  }
222
222
  else if (previousValue != isUserLoggedIn) {
223
223
 
224
- this.performFunctionWithDelay(0.01, function (this: CBCore) {
225
-
226
- UIRoute.currentRoute.routeByRemovingComponentsOtherThanOnesNamed([
227
- "settings"
228
- ]).apply()
229
-
230
- this.broadcastMessageInRootViewTree({
231
- name: CBCore.broadcastEventName.userDidLogOut,
232
- parameters: nil
233
- })
234
-
235
- this.updateLinkTargets()
236
-
237
- }.bind(this))
224
+ this.didLogOut()
238
225
 
239
226
  }
240
227
 
241
228
  }
242
229
 
230
+ /**
231
+ * Called when the user transitions from logged-in to logged-out.
232
+ * The default implementation clears the route and broadcasts `userDidLogOut`.
233
+ * Subclasses may override this to suppress the route change when they intend
234
+ * to navigate somewhere specific immediately after logout.
235
+ */
236
+ didLogOut() {
237
+
238
+ this.performFunctionWithDelay(0.01, function (this: CBCore) {
239
+
240
+ UIRoute.currentRoute.routeByRemovingComponentsOtherThanOnesNamed([
241
+ "settings"
242
+ ]).apply()
243
+
244
+ this.broadcastMessageInRootViewTree({
245
+ name: CBCore.broadcastEventName.userDidLogOut,
246
+ parameters: nil
247
+ })
248
+
249
+ this.updateLinkTargets()
250
+
251
+ }.bind(this))
252
+
253
+ }
254
+
243
255
  updateLinkTargets() {
244
256
  this.viewCores.everyElement.rootViewController.view.forEachViewInSubtree(function (view) {
245
257
  if (view instanceof UILink) {
@@ -356,4 +368,3 @@ export class CBCore extends UIObject {
356
368
 
357
369
 
358
370
  }
359
-
@@ -35,13 +35,13 @@ interface CBSocketCallbackHolderMessageDescriptor {
35
35
  completionFunction: CBSocketMessageCompletionFunction;
36
36
 
37
37
  _timeoutId?: ReturnType<typeof setTimeout>;
38
-
38
+
39
39
  /**
40
40
  * Called when a keepalive frame arrives for this descriptor's request.
41
41
  * Registered via CBSocketRequestPromise.didReceiveKeepalive().
42
42
  */
43
43
  keepaliveHandler?: (payload: CBSocketKeepalivePayload) => void;
44
-
44
+
45
45
  /**
46
46
  * When true the defaultKeepaliveHandler on CBSocketClient is NOT called
47
47
  * for this descriptor — only keepaliveHandler fires.
@@ -123,16 +123,20 @@ export class CBSocketCallbackHolder extends UIObject {
123
123
 
124
124
  triggerDisconnectHandlers() {
125
125
 
126
- this.messageDescriptors.forEach(function (this: CBSocketCallbackHolder, descriptor: CBSocketCallbackHolderMessageDescriptor, key: string) {
127
-
128
- if (!descriptor.mainResponseReceived) {
126
+ this.messageDescriptors.forEach(
127
+ function (this: CBSocketCallbackHolder, descriptor: CBSocketCallbackHolderMessageDescriptor, key: string) {
129
128
 
130
- this._cancelTimeoutForDescriptor(descriptor)
131
- descriptor?.completionFunction?.(CBSocketClient.disconnectionMessage, nil)
129
+ if (!descriptor.mainResponseReceived) {
130
+
131
+ this._cancelTimeoutForDescriptor(descriptor)
132
+
133
+ if (typeof descriptor?.completionFunction == "function") {
134
+ descriptor.completionFunction(CBSocketClient.disconnectionMessage, nil)
135
+ }
136
+
137
+ }
132
138
 
133
- }
134
-
135
- }.bind(this))
139
+ }.bind(this))
136
140
 
137
141
  }
138
142
 
@@ -225,20 +229,20 @@ export class CBSocketCallbackHolder extends UIObject {
225
229
  }
226
230
 
227
231
  }
228
-
229
-
232
+
233
+
230
234
  /**
231
235
  * Resets the timeout for a descriptor by cancelling the current timer and
232
236
  * scheduling a fresh one. Called whenever a keepalive frame arrives so the
233
237
  * request gets a full new window to complete.
234
238
  */
235
239
  _resetTimeoutForDescriptor(descriptor: CBSocketCallbackHolderMessageDescriptor) {
236
-
240
+
237
241
  this._cancelTimeoutForDescriptor(descriptor)
238
242
  this._scheduleTimeoutForDescriptor(descriptor)
239
-
243
+
240
244
  }
241
-
245
+
242
246
 
243
247
  get storedResponseHashesDictionary() {
244
248
 
@@ -457,7 +461,7 @@ export class CBSocketCallbackHolder extends UIObject {
457
461
 
458
462
  completionPolicy: completionPolicy,
459
463
  completionFunction: completionFunction,
460
-
464
+
461
465
  keepaliveHandler: undefined,
462
466
  keepaliveHandlerOverridesDefault: NO
463
467
 
@@ -572,7 +576,7 @@ export class CBSocketCallbackHolder extends UIObject {
572
576
  )
573
577
 
574
578
  }.bind(this),
575
-
579
+
576
580
  keepaliveHandler: undefined,
577
581
  keepaliveHandlerOverridesDefault: NO
578
582
 
@@ -636,40 +640,40 @@ export class CBSocketCallbackHolder extends UIObject {
636
640
  // Find descriptors for the key of the message that is being responded to
637
641
  const descriptorKey = this.keysForIdentifiers[message.inResponseToIdentifier]
638
642
  const descriptorsForKey = (this.messageDescriptors[descriptorKey] || [])
639
-
640
-
643
+
644
+
641
645
  // --- Keepalive fast path ---
642
646
  // A keepalive frame must not flow through the normal completion machinery.
643
647
  // Handle it here and return early so nothing else fires.
644
648
  if (message.isKeepalive) {
645
-
649
+
646
650
  const payload: CBSocketKeepalivePayload = message.messageData || {}
647
-
651
+
648
652
  descriptorsForKey.forEach((descriptor) => {
649
-
653
+
650
654
  if (descriptor.message.identifier !== message.inResponseToIdentifier) {
651
655
  return
652
656
  }
653
-
657
+
654
658
  // Reset the client-side timeout so the request gets a full new window
655
659
  this._resetTimeoutForDescriptor(descriptor)
656
-
660
+
657
661
  // Fire the default handler unless the per-call handler overrides it
658
662
  if (!descriptor.keepaliveHandlerOverridesDefault) {
659
663
  this._socketClient.defaultKeepaliveHandler?.(payload)
660
664
  }
661
-
665
+
662
666
  // Fire the per-call handler if one was registered
663
667
  descriptor.keepaliveHandler?.(payload)
664
-
668
+
665
669
  })
666
-
670
+
667
671
  return
668
-
672
+
669
673
  }
670
674
  // --- End keepalive fast path ---
671
-
672
-
675
+
676
+
673
677
  // Find response data hash to check for differences
674
678
  const responseDataHash = message.messageDataHash
675
679