cbcore-ts 1.0.21 → 1.0.26
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.
- package/compiledScripts/CBCore.d.ts +0 -10
- package/compiledScripts/CBCore.js +7 -18
- package/compiledScripts/CBCore.js.map +2 -2
- package/compiledScripts/CBDataInterfaces.d.ts +14 -14
- package/compiledScripts/CBLanguageService.d.ts +1 -0
- package/compiledScripts/CBLanguageService.js +24 -25
- package/compiledScripts/CBLanguageService.js.map +2 -2
- package/compiledScripts/CBSocketClient.js +7 -5
- package/compiledScripts/CBSocketClient.js.map +2 -2
- package/package.json +5 -4
- package/scripts/CBCore.ts +19 -129
- package/scripts/CBLanguageService.ts +28 -32
- package/scripts/CBSocketClient.ts +12 -10
|
@@ -38,16 +38,6 @@ export declare class CBCore extends UIObject {
|
|
|
38
38
|
set languageKey(languageKey: string);
|
|
39
39
|
get languageKey(): string;
|
|
40
40
|
didSetLanguageKey(): void;
|
|
41
|
-
get externalServiceIdentifier(): {
|
|
42
|
-
accessKey: string;
|
|
43
|
-
serviceID: string;
|
|
44
|
-
organizationID: string;
|
|
45
|
-
};
|
|
46
|
-
set externalServiceIdentifier(externalServiceIdentifier: {
|
|
47
|
-
accessKey: string;
|
|
48
|
-
serviceID: string;
|
|
49
|
-
organizationID: string;
|
|
50
|
-
});
|
|
51
41
|
reloadSocketConnection(): void;
|
|
52
42
|
callFunctionForEachSocketClient(functionToCall: () => void): void;
|
|
53
43
|
}
|
|
@@ -83,8 +83,7 @@ const _CBCore = class extends import_uicore_ts.UIObject {
|
|
|
83
83
|
} else if (previousValue != isUserLoggedIn) {
|
|
84
84
|
this.performFunctionWithDelay(0.01, function() {
|
|
85
85
|
import_uicore_ts.UIRoute.currentRoute.routeByRemovingComponentsOtherThanOnesNamed([
|
|
86
|
-
"settings"
|
|
87
|
-
"inquiry"
|
|
86
|
+
"settings"
|
|
88
87
|
]).apply();
|
|
89
88
|
this.broadcastMessageInRootViewTree({
|
|
90
89
|
name: _CBCore.broadcastEventName.userDidLogOut,
|
|
@@ -102,16 +101,14 @@ const _CBCore = class extends import_uicore_ts.UIObject {
|
|
|
102
101
|
});
|
|
103
102
|
}
|
|
104
103
|
get isUserLoggedIn() {
|
|
105
|
-
|
|
106
|
-
return result;
|
|
104
|
+
return localStorage.getItem("CBIsUserLoggedIn") == "true";
|
|
107
105
|
}
|
|
108
106
|
get userProfile() {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
} catch (error) {
|
|
107
|
+
const text = localStorage.getItem("CBUserProfile");
|
|
108
|
+
if (text) {
|
|
109
|
+
return JSON.parse(text);
|
|
113
110
|
}
|
|
114
|
-
return
|
|
111
|
+
return void 0;
|
|
115
112
|
}
|
|
116
113
|
set userProfile(userProfile) {
|
|
117
114
|
if ((0, import_uicore_ts.IS_NOT)(userProfile)) {
|
|
@@ -131,11 +128,10 @@ const _CBCore = class extends import_uicore_ts.UIObject {
|
|
|
131
128
|
this.didSetLanguageKey();
|
|
132
129
|
}
|
|
133
130
|
get languageKey() {
|
|
134
|
-
|
|
131
|
+
return (0, import_uicore_ts.FIRST)(localStorage.getItem("CBLanguageKey"), import_CBLanguageService.CBLanguageService.defaultLanguageKey).replace(
|
|
135
132
|
'"',
|
|
136
133
|
""
|
|
137
134
|
).replace('"', "");
|
|
138
|
-
return result;
|
|
139
135
|
}
|
|
140
136
|
didSetLanguageKey() {
|
|
141
137
|
import_uicore_ts.UIRoute.currentRoute.routeWithComponent(
|
|
@@ -144,13 +140,6 @@ const _CBCore = class extends import_uicore_ts.UIObject {
|
|
|
144
140
|
import_uicore_ts.YES
|
|
145
141
|
).applyByReplacingCurrentRouteInHistory();
|
|
146
142
|
}
|
|
147
|
-
get externalServiceIdentifier() {
|
|
148
|
-
const result = JSON.parse(localStorage.getItem("CBExternalServiceIdentifier"));
|
|
149
|
-
return result;
|
|
150
|
-
}
|
|
151
|
-
set externalServiceIdentifier(externalServiceIdentifier) {
|
|
152
|
-
localStorage.setItem("CBExternalServiceIdentifier", JSON.stringify(externalServiceIdentifier));
|
|
153
|
-
}
|
|
154
143
|
reloadSocketConnection() {
|
|
155
144
|
this.socketClient.socket.disconnect();
|
|
156
145
|
const messagesToBeSent = this.socketClient._messagesToBeSent.filter(function(messageItem, index, array) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../scripts/CBCore.ts"],
|
|
4
|
-
"sourcesContent": ["import {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,
|
|
4
|
+
"sourcesContent": ["import { 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: boolean = nil\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(viewCore: UICore) {\n \n CBCore.sharedInstance.viewCores.push(viewCore)\n \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 localStorage.setItem(\"CBIsUserLoggedIn\", \"\" + 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 private 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 (localStorage.getItem(\"CBIsUserLoggedIn\") == \"true\")\n }\n \n \n get userProfile() {\n const text = localStorage.getItem(\"CBUserProfile\")\n if (text) {\n return JSON.parse(text) as CBUserProfile\n }\n return undefined\n }\n \n set userProfile(userProfile: CBUserProfile) {\n if (IS_NOT(userProfile)) {\n localStorage.removeItem(\"CBUserProfile\")\n }\n localStorage.setItem(\"CBUserProfile\", JSON.stringify(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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|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type CBReferenceID = string;
|
|
2
2
|
export interface CBLanguageItem {
|
|
3
3
|
value: string;
|
|
4
4
|
languageKey: string;
|
|
@@ -86,8 +86,8 @@ export interface CBSubscription {
|
|
|
86
86
|
createdAt: Date;
|
|
87
87
|
updatedAt: Date;
|
|
88
88
|
}
|
|
89
|
-
export
|
|
90
|
-
export
|
|
89
|
+
export type CBUserProfilePublic = any;
|
|
90
|
+
export type CBUserProfile = any;
|
|
91
91
|
export interface SocketClientInterface {
|
|
92
92
|
[x: string]: SocketClientFunction<any, any>;
|
|
93
93
|
}
|
|
@@ -97,8 +97,8 @@ export interface SocketClientResult<ResultType> {
|
|
|
97
97
|
errorResult: any;
|
|
98
98
|
respondWithMessage: CBSocketMessageSendResponseFunction;
|
|
99
99
|
}
|
|
100
|
-
export
|
|
101
|
-
export
|
|
100
|
+
export type SocketClientFunction<MessageType, ResultType> = (messageData: MessageType, completionPolicy?: string, isUserBound?: boolean) => Promise<SocketClientResult<ResultType>>;
|
|
101
|
+
export type SocketClientNoMessageFunction<ResultType> = (messageData?: null, completionPolicy?: string, isUserBound?: boolean) => Promise<SocketClientResult<ResultType>>;
|
|
102
102
|
export interface CBSocketMultipleMessageObject<MessageDataType = any> {
|
|
103
103
|
key: string;
|
|
104
104
|
message: CBSocketMessage<MessageDataType>;
|
|
@@ -118,10 +118,10 @@ export interface CBSocketMessage<MessageDataType = any> {
|
|
|
118
118
|
export interface CBSocketMultipleMessage extends CBSocketMessage<CBSocketMultipleMessageObject[]> {
|
|
119
119
|
shouldGroupResponses: boolean;
|
|
120
120
|
}
|
|
121
|
-
export
|
|
122
|
-
export
|
|
123
|
-
export
|
|
124
|
-
export
|
|
121
|
+
export type CBSocketMessageSendResponseFunctionBase<ResponseMessageType> = (responseMessage: ResponseMessageType, completion?: CBSocketMessageCompletionFunction) => Promise<string>;
|
|
122
|
+
export type CBSocketMessageCompletionFunction = (responseMessage: any, respondWithMessage: CBSocketMessageSendResponseFunction) => void;
|
|
123
|
+
export type CBSocketMessageHandlerFunction<ResponseMessageType = any> = (message: any, respondWithMessage: CBSocketMessageSendResponseFunction<ResponseMessageType>) => void;
|
|
124
|
+
export type CBSocketMultipleMessagecompletionFunction = (responseMessages: any[], callcompletionFunctions: () => void) => void;
|
|
125
125
|
export interface CBSocketMessageSendResponseFunction<ResponseMessageType = any> extends CBSocketMessageSendResponseFunctionBase<ResponseMessageType> {
|
|
126
126
|
respondingToMainResponse: boolean;
|
|
127
127
|
excludeMessageFromAutomaticConnectionEvents: () => void;
|
|
@@ -147,16 +147,16 @@ export interface CBSocketHandshakeResponseMessage {
|
|
|
147
147
|
accepted: boolean;
|
|
148
148
|
userProfile?: CBUserProfile;
|
|
149
149
|
}
|
|
150
|
-
export
|
|
151
|
-
export
|
|
152
|
-
export
|
|
150
|
+
export type TypeWithoutKey<Type, Key> = Pick<Type, Exclude<keyof Type, Key>>;
|
|
151
|
+
export type TypeWithoutID<Type> = TypeWithoutKey<Type, "_id">;
|
|
152
|
+
export type Diff<T extends keyof any, U extends keyof any> = ({
|
|
153
153
|
[P in T]: P;
|
|
154
154
|
} & {
|
|
155
155
|
[P in U]: never;
|
|
156
156
|
} & {
|
|
157
157
|
[x: string]: never;
|
|
158
158
|
})[T];
|
|
159
|
-
export
|
|
160
|
-
export
|
|
159
|
+
export type Overwrite<T, U> = Pick<T, Diff<keyof T, keyof U>> & U;
|
|
160
|
+
export type RecursivePartial<T> = {
|
|
161
161
|
[P in keyof T]?: T[P] extends (infer U)[] ? RecursivePartial<U>[] : T[P] extends object ? RecursivePartial<T[P]> : T[P];
|
|
162
162
|
};
|
|
@@ -14,6 +14,7 @@ export interface LanguageValues {
|
|
|
14
14
|
est: ParticularLanguageValues;
|
|
15
15
|
}
|
|
16
16
|
export declare class CBLanguageService implements UILanguageService {
|
|
17
|
+
static currentClassObject: typeof CBLanguageService;
|
|
17
18
|
static _currentLanguageKey: string;
|
|
18
19
|
static languageValues: LanguageValues;
|
|
19
20
|
static languages: any;
|
|
@@ -25,12 +25,12 @@ var import_uicore_ts = require("uicore-ts");
|
|
|
25
25
|
var import_CBCore = require("./CBCore");
|
|
26
26
|
const _CBLanguageService = class {
|
|
27
27
|
static useStoredLanguageValues(values = {}) {
|
|
28
|
-
const result = JSON.parse(JSON.stringify(
|
|
28
|
+
const result = JSON.parse(JSON.stringify(this.languageValues)).objectByCopyingValuesRecursivelyFromObject(
|
|
29
29
|
values
|
|
30
30
|
);
|
|
31
|
-
if (JSON.stringify(result) != JSON.stringify(
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
if (JSON.stringify(result) != JSON.stringify(this.languages)) {
|
|
32
|
+
this.languages = result;
|
|
33
|
+
this.broadcastLanguageChangeEvent();
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
static broadcastLanguageChangeEvent(view) {
|
|
@@ -44,34 +44,35 @@ const _CBLanguageService = class {
|
|
|
44
44
|
return CBCoreInitializerObject.defaultLanguageKey || "en";
|
|
45
45
|
}
|
|
46
46
|
static get currentLanguageKey() {
|
|
47
|
-
if (!
|
|
48
|
-
|
|
47
|
+
if (!this._currentLanguageKey) {
|
|
48
|
+
this.updateCurrentLanguageKey();
|
|
49
49
|
}
|
|
50
|
-
return
|
|
50
|
+
return this._currentLanguageKey;
|
|
51
51
|
}
|
|
52
52
|
updateCurrentLanguageKey() {
|
|
53
|
-
_CBLanguageService.updateCurrentLanguageKey();
|
|
53
|
+
_CBLanguageService.currentClassObject.updateCurrentLanguageKey();
|
|
54
54
|
}
|
|
55
55
|
static updateCurrentLanguageKey(route = import_uicore_ts.UIRoute.currentRoute) {
|
|
56
|
-
|
|
56
|
+
var _a, _b;
|
|
57
|
+
let result = (_b = (_a = route.componentWithName("settings")) == null ? void 0 : _a.parameters) == null ? void 0 : _b.language;
|
|
57
58
|
if ((0, import_uicore_ts.IS_NOT)(result)) {
|
|
58
|
-
result =
|
|
59
|
+
result = this.defaultLanguageKey;
|
|
59
60
|
}
|
|
60
|
-
const isChanged = result !=
|
|
61
|
-
|
|
61
|
+
const isChanged = result != this._currentLanguageKey;
|
|
62
|
+
this._currentLanguageKey = result;
|
|
62
63
|
if (isChanged) {
|
|
63
64
|
import_CBCore.CBCore.sharedInstance.languageKey = result;
|
|
64
|
-
|
|
65
|
+
this.broadcastLanguageChangeEvent();
|
|
65
66
|
}
|
|
66
67
|
}
|
|
67
68
|
get currentLanguageKey() {
|
|
68
|
-
const result = _CBLanguageService.currentLanguageKey;
|
|
69
|
+
const result = _CBLanguageService.currentClassObject.currentLanguageKey;
|
|
69
70
|
return result;
|
|
70
71
|
}
|
|
71
72
|
static stringForKey(key, languageKey, defaultString, parameters) {
|
|
72
73
|
var result;
|
|
73
|
-
if ((0, import_uicore_ts.IS)(key) &&
|
|
74
|
-
result =
|
|
74
|
+
if ((0, import_uicore_ts.IS)(key) && this.languages[languageKey] && (0, import_uicore_ts.IS_DEFINED)(this.languages[languageKey][key])) {
|
|
75
|
+
result = this.languages[languageKey][key];
|
|
75
76
|
} else {
|
|
76
77
|
result = defaultString;
|
|
77
78
|
}
|
|
@@ -92,7 +93,7 @@ const _CBLanguageService = class {
|
|
|
92
93
|
return result;
|
|
93
94
|
}
|
|
94
95
|
stringForKey(key, languageKey, defaultString, parameters) {
|
|
95
|
-
return _CBLanguageService.stringForKey(key, languageKey, defaultString, parameters);
|
|
96
|
+
return _CBLanguageService.currentClassObject.stringForKey(key, languageKey, defaultString, parameters);
|
|
96
97
|
}
|
|
97
98
|
static localizedTextObjectForKey(key, defaultString = key, parameters) {
|
|
98
99
|
const result = {};
|
|
@@ -102,7 +103,7 @@ const _CBLanguageService = class {
|
|
|
102
103
|
return result;
|
|
103
104
|
}
|
|
104
105
|
localizedTextObjectForKey(key, defaultString, parameters) {
|
|
105
|
-
const result = _CBLanguageService.localizedTextObjectForKey(key, defaultString, parameters);
|
|
106
|
+
const result = _CBLanguageService.currentClassObject.localizedTextObjectForKey(key, defaultString, parameters);
|
|
106
107
|
return result;
|
|
107
108
|
}
|
|
108
109
|
static localizedTextObjectForText(text) {
|
|
@@ -115,20 +116,17 @@ const _CBLanguageService = class {
|
|
|
115
116
|
return result;
|
|
116
117
|
}
|
|
117
118
|
localizedTextObjectForText(text) {
|
|
118
|
-
const result = _CBLanguageService.localizedTextObjectForText(text);
|
|
119
|
+
const result = _CBLanguageService.currentClassObject.localizedTextObjectForText(text);
|
|
119
120
|
return result;
|
|
120
121
|
}
|
|
121
122
|
static stringForCurrentLanguage(localizedTextObject) {
|
|
122
|
-
if (!_CBLanguageService || !localizedTextObject) {
|
|
123
|
-
const asd = 1;
|
|
124
|
-
}
|
|
125
123
|
if (localizedTextObject === "" + localizedTextObject) {
|
|
126
124
|
return localizedTextObject;
|
|
127
125
|
}
|
|
128
126
|
localizedTextObject = (0, import_uicore_ts.FIRST_OR_NIL)(localizedTextObject);
|
|
129
|
-
let result = localizedTextObject[
|
|
127
|
+
let result = localizedTextObject[this.currentLanguageKey];
|
|
130
128
|
if ((0, import_uicore_ts.IS_NOT)(result)) {
|
|
131
|
-
result = localizedTextObject[
|
|
129
|
+
result = localizedTextObject[this.defaultLanguageKey];
|
|
132
130
|
}
|
|
133
131
|
if ((0, import_uicore_ts.IS_NOT)(result)) {
|
|
134
132
|
result = localizedTextObject["en"];
|
|
@@ -139,10 +137,11 @@ const _CBLanguageService = class {
|
|
|
139
137
|
return result;
|
|
140
138
|
}
|
|
141
139
|
stringForCurrentLanguage(localizedTextObject) {
|
|
142
|
-
return _CBLanguageService.stringForCurrentLanguage(localizedTextObject);
|
|
140
|
+
return _CBLanguageService.currentClassObject.stringForCurrentLanguage(localizedTextObject);
|
|
143
141
|
}
|
|
144
142
|
};
|
|
145
143
|
let CBLanguageService = _CBLanguageService;
|
|
144
|
+
CBLanguageService.currentClassObject = _CBLanguageService;
|
|
146
145
|
CBLanguageService.languageValues = {
|
|
147
146
|
en: {
|
|
148
147
|
languageName: "English",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../scripts/CBLanguageService.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n FIRST_OR_NIL,\n IS,\n IS_DEFINED,\n IS_NOT,\n nil,\n UICore,\n UILanguageService,\n UILocalizedTextObject,\n UIRoute,\n UIView\n} from \"uicore-ts\"\nimport { CBCore } from \"./CBCore\"\nimport { CBLocalizedTextObject } from \"./CBDataInterfaces\"\n\n\nexport interface ParticularLanguageValues {\n \n [x: string]: string\n \n topBarTitle: string;\n selectLanguageTitle: string;\n languageNameShort: string;\n leftBarTitle: string;\n languageName: string\n \n}\n\n\nexport interface LanguageValues {\n \n [x: string]: ParticularLanguageValues\n \n en: ParticularLanguageValues\n est: ParticularLanguageValues\n \n}\n\n\nexport class CBLanguageService implements UILanguageService {\n \n static _currentLanguageKey: string\n \n static languageValues: LanguageValues = {\n \n en: {\n \n languageName: \"English\",\n languageNameShort: \"ENG\",\n \n topBarTitle: \"UICore application\",\n \n selectLanguageTitle: \"Select language\",\n leftBarTitle: \"Title\"\n \n \n },\n est: {\n \n languageName: \"Eesti keel\",\n languageNameShort: \"EST\",\n \n topBarTitle: \"UICore rakendus\",\n \n selectLanguageTitle: \"Vali keel\",\n leftBarTitle: \"Pealkiri\"\n \n \n }\n \n \n \n \n }\n \n static languages = JSON.parse(JSON.stringify(
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAWO;AACP,oBAAuB;AA2BhB,MAAM,qBAAN,MAAqD;AAAA,
|
|
4
|
+
"sourcesContent": ["import {\n FIRST_OR_NIL,\n IS,\n IS_DEFINED,\n IS_NOT,\n nil,\n UICore,\n UILanguageService,\n UILocalizedTextObject,\n UIRoute,\n UIView\n} from \"uicore-ts\"\nimport { CBCore } from \"./CBCore\"\nimport { CBLocalizedTextObject } from \"./CBDataInterfaces\"\n\n\nexport interface ParticularLanguageValues {\n \n [x: string]: string\n \n topBarTitle: string;\n selectLanguageTitle: string;\n languageNameShort: string;\n leftBarTitle: string;\n languageName: string\n \n}\n\n\nexport interface LanguageValues {\n \n [x: string]: ParticularLanguageValues\n \n en: ParticularLanguageValues\n est: ParticularLanguageValues\n \n}\n\n\nexport class CBLanguageService implements UILanguageService {\n \n static currentClassObject = CBLanguageService;\n \n static _currentLanguageKey: string\n \n static languageValues: LanguageValues = {\n \n en: {\n \n languageName: \"English\",\n languageNameShort: \"ENG\",\n \n topBarTitle: \"UICore application\",\n \n selectLanguageTitle: \"Select language\",\n leftBarTitle: \"Title\"\n \n \n },\n est: {\n \n languageName: \"Eesti keel\",\n languageNameShort: \"EST\",\n \n topBarTitle: \"UICore rakendus\",\n \n selectLanguageTitle: \"Vali keel\",\n leftBarTitle: \"Pealkiri\"\n \n \n }\n \n \n \n \n }\n \n static languages = JSON.parse(JSON.stringify(this.languageValues))\n \n static useStoredLanguageValues(values = {}) {\n \n const result = JSON.parse(JSON.stringify(this.languageValues))\n .objectByCopyingValuesRecursivelyFromObject(\n values) as any\n \n if (JSON.stringify(result) != JSON.stringify(this.languages)) {\n \n this.languages = result\n \n this.broadcastLanguageChangeEvent()\n \n }\n \n }\n \n \n static broadcastLanguageChangeEvent(view?: UIView) {\n \n view = view as any || CBCore.sharedInstance.viewCores.everyElement.rootViewController.view.rootView as any\n \n view?.broadcastEventInSubtree({\n name: UIView.broadcastEventName.LanguageChanged,\n parameters: {}\n })\n \n }\n \n static get defaultLanguageKey() {\n \n // @ts-ignore\n return (CBCoreInitializerObject.defaultLanguageKey || \"en\")\n \n }\n \n static get currentLanguageKey() {\n \n if (!this._currentLanguageKey) {\n \n this.updateCurrentLanguageKey()\n \n }\n \n return this._currentLanguageKey\n \n }\n \n updateCurrentLanguageKey() {\n \n CBLanguageService.currentClassObject.updateCurrentLanguageKey()\n \n }\n \n static updateCurrentLanguageKey(route = UIRoute.currentRoute) {\n \n let result = route.componentWithName(\"settings\")?.parameters?.language\n \n if (IS_NOT(result)) {\n \n result = this.defaultLanguageKey\n \n }\n \n const isChanged = (result != this._currentLanguageKey)\n \n this._currentLanguageKey = result\n \n if (isChanged) {\n \n CBCore.sharedInstance.languageKey = result\n \n this.broadcastLanguageChangeEvent()\n \n }\n \n }\n \n get currentLanguageKey() {\n \n const result = CBLanguageService.currentClassObject.currentLanguageKey\n \n return result\n \n }\n \n \n \n static stringForKey(\n key: string,\n languageKey: string,\n defaultString: string,\n parameters?: { [x: string]: string | UILocalizedTextObject; }\n ) {\n \n var result: string\n \n if (IS(key) && this.languages[languageKey] &&\n IS_DEFINED(this.languages[languageKey][key])) {\n \n result = this.languages[languageKey][key]\n \n }\n else {\n \n result = defaultString\n \n }\n \n if (IS(parameters)) {\n \n const parameterKeys = Object.keys(parameters)\n \n parameterKeys.forEach(function (key, index, array) {\n \n const keyString = \"%\" + key + \"%\"\n \n const parameter = parameters[key]\n \n var parameterString\n \n if (parameter instanceof Object) {\n \n parameterString = UICore.languageService.stringForCurrentLanguage(parameter as UILocalizedTextObject)\n \n }\n else {\n \n parameterString = parameter\n \n }\n \n \n result = result.replace(new RegExp(keyString, \"g\"), parameterString)\n \n })\n \n }\n \n return result\n \n }\n \n stringForKey(\n key: string,\n languageKey: string,\n defaultString: string,\n parameters?: { [x: string]: string | UILocalizedTextObject; }\n ) {\n \n \n return CBLanguageService.currentClassObject.stringForKey(key, languageKey, defaultString, parameters)\n \n \n }\n \n \n static localizedTextObjectForKey(\n key: string,\n defaultString = key,\n parameters?: { [x: string]: string | UILocalizedTextObject; }\n ) {\n \n const result = {}\n \n CBLanguageService.languages.forEach(function (languageObject: any, languageKey: string) {\n \n // @ts-ignore\n result[languageKey] = CBLanguageService.stringForKey(key, languageKey, defaultString, parameters)\n \n })\n \n return result\n \n }\n \n localizedTextObjectForKey(\n key: string,\n defaultString?: string,\n parameters?: { [x: string]: string | UILocalizedTextObject; }\n ) {\n \n const result = CBLanguageService.currentClassObject.localizedTextObjectForKey(key, defaultString, parameters)\n \n return result\n \n }\n \n \n static localizedTextObjectForText(text: string) {\n \n if (IS_NOT(text)) {\n \n return nil\n \n }\n \n const result = {\n \n [CBLanguageService.defaultLanguageKey]: text\n \n }\n \n return result\n \n }\n \n localizedTextObjectForText(text: string) {\n \n const result = CBLanguageService.currentClassObject.localizedTextObjectForText(text)\n \n return result\n \n }\n \n \n static stringForCurrentLanguage(localizedTextObject: CBLocalizedTextObject | string) {\n \n if (localizedTextObject === \"\" + localizedTextObject) {\n \n return localizedTextObject\n \n }\n \n localizedTextObject = FIRST_OR_NIL(localizedTextObject)\n \n // @ts-ignore\n let result: string = localizedTextObject[this.currentLanguageKey]\n \n if (IS_NOT(result)) {\n \n // @ts-ignore\n result = localizedTextObject[this.defaultLanguageKey]\n \n }\n \n if (IS_NOT(result)) {\n \n // @ts-ignore\n result = localizedTextObject[\"en\"]\n \n }\n \n if (IS_NOT(result)) {\n \n result = \"\"\n \n }\n \n return result\n \n }\n \n stringForCurrentLanguage(localizedTextObject: CBLocalizedTextObject) {\n \n return CBLanguageService.currentClassObject.stringForCurrentLanguage(localizedTextObject)\n \n }\n \n \n \n \n}\n\n\nUICore.languageService = CBLanguageService\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,uBAWO;AACP,oBAAuB;AA2BhB,MAAM,qBAAN,MAAqD;AAAA,EAwCxD,OAAO,wBAAwB,SAAS,CAAC,GAAG;AAExC,UAAM,SAAS,KAAK,MAAM,KAAK,UAAU,KAAK,cAAc,CAAC,EACxD;AAAA,MACG;AAAA,IAAM;AAEd,QAAI,KAAK,UAAU,MAAM,KAAK,KAAK,UAAU,KAAK,SAAS,GAAG;AAE1D,WAAK,YAAY;AAEjB,WAAK,6BAA6B;AAAA,IAEtC;AAAA,EAEJ;AAAA,EAGA,OAAO,6B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tC;AAEA,YAAI,yBAAO,MAAM,GAAG;AAGhB,eAAS,oBAAoB;AAAA,IAEjC;AAEA,YAAI,yBAAO,MAAM,GAAG;AAEhB,eAAS;AAAA,IAEb;AAEA,WAAO;AAAA,EAEX;AAAA,EAEA,yBAAyB,qBAA4C;AAEjE,WAAO,mBAAkB,mBAAmB,yBAAyB,mBAAmB;AAAA,EAE5F;AAKJ;AA7SO,IAAM,oBAAN;AAAM,kBAEF,qBAAqB;AAFnB,kBAMF,iBAAiC;AAAA,EAEpC,IAAI;AAAA,IAEA,cAAc;AAAA,IACd,mBAAmB;AAAA,IAEnB,aAAa;AAAA,IAEb,qBAAqB;AAAA,IACrB,cAAc;AAAA,EAGlB;AAAA,EACA,KAAK;AAAA,IAED,cAAc;AAAA,IACd,mBAAmB;AAAA,IAEnB,aAAa;AAAA,IAEb,qBAAqB;AAAA,IACrB,cAAc;AAAA,EAGlB;AAKJ;AApCS,kBAsCF,YAAY,KAAK,MAAM,KAAK,UAAU,mBAAK,cAAc,CAAC;AA0QrE,wBAAO,kBAAkB;",
|
|
6
6
|
"names": ["key"]
|
|
7
7
|
}
|
|
@@ -46,15 +46,16 @@ const _CBSocketClient = class extends import_uicore_ts.UIObject {
|
|
|
46
46
|
this._callbackHolder = new import_CBSocketCallbackHolder.CBSocketCallbackHolder(this);
|
|
47
47
|
this._core = core;
|
|
48
48
|
this.socket.on("connect", () => {
|
|
49
|
-
|
|
49
|
+
var _a, _b;
|
|
50
|
+
console.log("Socket.io connected to server. clientID = ", this.socket, " socketID = ", this.socket);
|
|
50
51
|
var instanceIdentifier = localStorage.getItem("InstanceIdentifier");
|
|
51
52
|
if ((0, import_uicore_ts.IS_NOT)(instanceIdentifier)) {
|
|
52
53
|
instanceIdentifier = (0, import_uicore_ts.MAKE_ID)();
|
|
53
54
|
localStorage.setItem("InstanceIdentifier", instanceIdentifier);
|
|
54
55
|
}
|
|
55
56
|
const handshakeMessage = {
|
|
56
|
-
accessToken: void 0,
|
|
57
|
-
userID: this._core.userProfile._id,
|
|
57
|
+
accessToken: (_a = localStorage.getItem("CBUserAccessToken")) != null ? _a : void 0,
|
|
58
|
+
userID: (_b = this._core.userProfile) == null ? void 0 : _b._id,
|
|
58
59
|
inquiryAccessKey: void 0,
|
|
59
60
|
instanceIdentifier
|
|
60
61
|
};
|
|
@@ -66,6 +67,7 @@ const _CBSocketClient = class extends import_uicore_ts.UIObject {
|
|
|
66
67
|
this.socket.on(
|
|
67
68
|
"CBSocketHandshakeResponseMessage",
|
|
68
69
|
(message) => {
|
|
70
|
+
var _a;
|
|
69
71
|
this._isConnectionEstablished = message.messageData.accepted;
|
|
70
72
|
if (!message.messageData.accepted) {
|
|
71
73
|
console.log("SocketIO connection failed.");
|
|
@@ -77,13 +79,13 @@ const _CBSocketClient = class extends import_uicore_ts.UIObject {
|
|
|
77
79
|
} else {
|
|
78
80
|
console.log("SocketIO connection handshake completed.");
|
|
79
81
|
this._callbackHolder = new import_CBSocketCallbackHolder.CBSocketCallbackHolder(this, this._callbackHolder);
|
|
80
|
-
core.userProfile = message.messageData.userProfile;
|
|
82
|
+
core.userProfile = (_a = message.messageData.userProfile) != null ? _a : {};
|
|
81
83
|
this.sendUnsentMessages();
|
|
82
84
|
}
|
|
83
85
|
}
|
|
84
86
|
);
|
|
85
87
|
this.socket.on("disconnect", () => {
|
|
86
|
-
console.log("Socket.io disconnected from server. clientID = "
|
|
88
|
+
console.log("Socket.io disconnected from server. clientID = ", this.socket);
|
|
87
89
|
this._isConnectionEstablished = import_uicore_ts.NO;
|
|
88
90
|
this._callbackHolder.isValid = import_uicore_ts.NO;
|
|
89
91
|
this._callbackHolder.triggerDisconnectHandlers();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../scripts/CBSocketClient.ts"],
|
|
4
|
-
"sourcesContent": ["import { io, Socket } 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 = io()\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 \n \n this.socket.on(\"connect\", () => {\n \n console.log(\"Socket.io connected to server. clientID = \" + this.socket + \", socketID = \" + this.socket)\n \n var instanceIdentifier = localStorage.getItem(\"InstanceIdentifier\")\n \n if (IS_NOT(instanceIdentifier)) {\n \n instanceIdentifier = MAKE_ID()\n localStorage.setItem(\"InstanceIdentifier\", instanceIdentifier)\n \n }\n \n const handshakeMessage: CBSocketHandshakeInitMessage = {\n \n accessToken: undefined,\n userID: this._core.userProfile._id,\n \n inquiryAccessKey: undefined,\n \n instanceIdentifier: instanceIdentifier\n \n }\n \n this.socket.emit(\"CBSocketHandshakeInitMessage\", {\n \n identifier: MAKE_ID(),\n messageData: handshakeMessage\n \n })\n \n \n })\n \n \n this.socket.on(\n \"CBSocketHandshakeResponseMessage\",\n (message: CBSocketMessage<CBSocketHandshakeResponseMessage>) => {\n \n \n this._isConnectionEstablished = message.messageData.accepted\n \n if (!message.messageData.accepted) {\n \n console.log(\"SocketIO connection failed.\")\n \n this._core.dialogViewShowerClass.alert(\n \"Failed to establish connection to server.\",\n () => {\n }\n )\n \n }\n else {\n \n console.log(\"SocketIO connection handshake completed.\")\n \n this._callbackHolder = new CBSocketCallbackHolder(this, this._callbackHolder)\n \n core.userProfile = message.messageData.userProfile\n \n this.sendUnsentMessages()\n \n }\n \n \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 \n this._callbackHolder.isValid = NO\n \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 \n if (message) {\n \n this._core.dialogViewShowerClass.alert(message)\n \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(\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,oBAA2B;AAC3B,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,cAA6B,0BAAS;AAAA,EAgCzC,YAAY,MAAc;AAEtB,UAAM;AAhCV,uBAAkB,kBAAG;AACrB,oCAA2B;AAE3B,uCAA8B;AAE9B,6BAAqD,CAAC;AAMtD,2BAEI,CAAC;AAEL,2BAAkB,IAAI,qDAAuB,IAAI;AAmB7C,SAAK,QAAQ;AAGb,SAAK,OAAO,GAAG,WAAW,MAAM;
|
|
4
|
+
"sourcesContent": ["import { io, Socket } 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 = io()\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 \n \n this.socket.on(\"connect\", () => {\n \n console.log(\"Socket.io connected to server. clientID = \", this.socket, \" socketID = \", this.socket)\n \n var instanceIdentifier = localStorage.getItem(\"InstanceIdentifier\")\n \n if (IS_NOT(instanceIdentifier)) {\n \n instanceIdentifier = MAKE_ID()\n localStorage.setItem(\"InstanceIdentifier\", instanceIdentifier!)\n \n }\n \n const handshakeMessage: CBSocketHandshakeInitMessage = {\n \n accessToken: localStorage.getItem(\"CBUserAccessToken\") ?? undefined,\n userID: this._core.userProfile?._id,\n \n inquiryAccessKey: undefined,\n \n instanceIdentifier: instanceIdentifier!\n \n }\n \n this.socket.emit(\"CBSocketHandshakeInitMessage\", {\n \n identifier: MAKE_ID(),\n messageData: handshakeMessage\n \n })\n \n \n })\n \n \n this.socket.on(\n \"CBSocketHandshakeResponseMessage\",\n (message: CBSocketMessage<CBSocketHandshakeResponseMessage>) => {\n \n \n this._isConnectionEstablished = message.messageData.accepted\n \n if (!message.messageData.accepted) {\n \n console.log(\"SocketIO connection failed.\")\n \n this._core.dialogViewShowerClass.alert(\n \"Failed to establish connection to server.\",\n () => {\n }\n )\n \n }\n else {\n \n console.log(\"SocketIO connection handshake completed.\")\n \n this._callbackHolder = new CBSocketCallbackHolder(this, this._callbackHolder)\n \n \n core.userProfile = message.messageData.userProfile ?? {}\n \n \n this.sendUnsentMessages()\n \n }\n \n \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 \n this._callbackHolder.isValid = NO\n \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 \n if (message) {\n \n this._core.dialogViewShowerClass.alert(message)\n \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(\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,oBAA2B;AAC3B,uBAAgG;AAChG,oBAAuB;AAavB,oCAAuC;AAkChC,SAAS,gBAAgB,QAAmD;AAE/E,QAAM,aAAU,qBAAG,MAAM,KAAK,OAAO;AAErC,SAAO;AAEX;AAEO,SAAS,oBAAoB,QAAa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wB,KAAK,OAAO;AAAA,MAE7C,EAAE,KAAK,IAAI,CAAC;AAEZ,WAAK,gBAAgB,OAAO;AAAA,IAEhC;AAAA,EAGJ;AAGJ;AAznBO,IAAM,iBAAN;AAAM,eAmBF,qBAAqB;AAnBnB,eAoBF,qBAAqB;AApBnB,eAuBF,uBAAmD;AAAA,EAEtD,yBAAyB;AAAA,EAEzB,aAAa;AAEjB;AA7BS,eAiSF,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;AA+UG,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;",
|
|
6
6
|
"names": ["completion", "messageObject"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cbcore-ts",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.26",
|
|
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",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "etsc && tsc --emitDeclarationOnly",
|
|
9
|
+
"tscv": "tsc -v",
|
|
9
10
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
10
11
|
"prepare": "npm run build"
|
|
11
12
|
},
|
|
@@ -33,8 +34,8 @@
|
|
|
33
34
|
"dependencies": {
|
|
34
35
|
"@types/object-hash": "^2.1.1",
|
|
35
36
|
"object-hash": "^2.1.1",
|
|
36
|
-
"socket.io-client": "^4.5
|
|
37
|
-
"uicore-ts": "1.0.
|
|
37
|
+
"socket.io-client": "^4.7.5",
|
|
38
|
+
"uicore-ts": "1.0.535"
|
|
38
39
|
},
|
|
39
40
|
"devDependencies": {
|
|
40
41
|
"@rollup/plugin-commonjs": "^23.0.0",
|
|
@@ -46,6 +47,6 @@
|
|
|
46
47
|
"rollup-plugin-sourcemaps": "^0.6.3",
|
|
47
48
|
"rollup-plugin-typescript2": "^0.32.1",
|
|
48
49
|
"rollup-plugin-web-worker-loader": "^1.6.1",
|
|
49
|
-
"typescript": "^
|
|
50
|
+
"typescript": "^5.8.3"
|
|
50
51
|
}
|
|
51
52
|
}
|
package/scripts/CBCore.ts
CHANGED
|
@@ -1,18 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
FIRST,
|
|
3
|
-
FIRST_OR_NIL,
|
|
4
|
-
IS,
|
|
5
|
-
IS_NOT,
|
|
6
|
-
nil,
|
|
7
|
-
UICore,
|
|
8
|
-
UILink,
|
|
9
|
-
UIObject,
|
|
10
|
-
UIRoute,
|
|
11
|
-
UIViewBroadcastEvent,
|
|
12
|
-
YES
|
|
13
|
-
} from "../../uicore-ts"
|
|
14
|
-
import { CBLanguageService } from "./CBLanguageService"
|
|
1
|
+
import { FIRST, IS, IS_NOT, nil, UICore, UILink, UIObject, UIRoute, UIViewBroadcastEvent, YES } from "../../uicore-ts"
|
|
15
2
|
import { CBLocalizedTextObject, CBUserProfile } from "./CBDataInterfaces"
|
|
3
|
+
import { CBLanguageService } from "./CBLanguageService"
|
|
16
4
|
import { CBServerClient } from "./CBServerClient"
|
|
17
5
|
import { CBSocketClient } from "./CBSocketClient"
|
|
18
6
|
|
|
@@ -20,13 +8,16 @@ import { CBSocketClient } from "./CBSocketClient"
|
|
|
20
8
|
declare interface CBDialogViewShower {
|
|
21
9
|
|
|
22
10
|
alert(text: string, dismissCallback?: Function): void
|
|
11
|
+
|
|
23
12
|
localizedAlert(textObject: CBLocalizedTextObject, dismissCallback?: Function): void
|
|
24
13
|
|
|
25
14
|
showActionIndicatorDialog(message: string, dismissCallback?: Function): void
|
|
15
|
+
|
|
26
16
|
hideActionIndicatorDialog(): void
|
|
27
17
|
|
|
28
18
|
}
|
|
29
19
|
|
|
20
|
+
|
|
30
21
|
declare const CBCoreInitializerObject: any
|
|
31
22
|
|
|
32
23
|
|
|
@@ -61,40 +52,34 @@ export class CBCore extends UIObject {
|
|
|
61
52
|
window.addEventListener("storage", function (this: CBCore, event: StorageEvent) {
|
|
62
53
|
|
|
63
54
|
if (event.newValue == event.oldValue) {
|
|
64
|
-
|
|
65
55
|
return
|
|
66
|
-
|
|
67
56
|
}
|
|
68
57
|
|
|
69
58
|
//console.log("" + event.key + " changed to " + event.newValue + " from " + event.oldValue);
|
|
70
59
|
|
|
71
60
|
|
|
72
|
-
|
|
73
61
|
if (event.key == "CBLanguageKey") {
|
|
74
|
-
|
|
75
62
|
this.didSetLanguageKey()
|
|
76
|
-
|
|
77
63
|
}
|
|
78
64
|
|
|
79
65
|
}.bind(this))
|
|
80
|
-
|
|
81
|
-
|
|
66
|
+
|
|
67
|
+
|
|
82
68
|
//this.checkIfUserIsAuthenticated();
|
|
83
|
-
|
|
69
|
+
|
|
84
70
|
this.didSetLanguageKey()
|
|
85
|
-
|
|
86
|
-
|
|
71
|
+
|
|
72
|
+
|
|
87
73
|
}
|
|
88
74
|
|
|
89
75
|
|
|
90
76
|
static initIfNeededWithViewCore(viewCore: UICore) {
|
|
91
77
|
|
|
92
|
-
CBCore.sharedInstance.viewCores.push(viewCore)
|
|
78
|
+
CBCore.sharedInstance.viewCores.push(viewCore)
|
|
93
79
|
|
|
94
80
|
}
|
|
95
81
|
|
|
96
82
|
|
|
97
|
-
|
|
98
83
|
static get sharedInstance() {
|
|
99
84
|
if (!CBCore._sharedInstance) {
|
|
100
85
|
CBCore._sharedInstance = new CBCore()
|
|
@@ -103,9 +88,6 @@ export class CBCore extends UIObject {
|
|
|
103
88
|
}
|
|
104
89
|
|
|
105
90
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
91
|
static broadcastEventName = {
|
|
110
92
|
|
|
111
93
|
"userDidLogIn": "UserDidLogIn",
|
|
@@ -114,15 +96,12 @@ export class CBCore extends UIObject {
|
|
|
114
96
|
} as const
|
|
115
97
|
|
|
116
98
|
broadcastMessageInRootViewTree(message: UIViewBroadcastEvent) {
|
|
117
|
-
|
|
99
|
+
|
|
118
100
|
this.viewCores.everyElement.rootViewController.view.broadcastEventInSubtree(message)
|
|
119
101
|
|
|
120
102
|
}
|
|
121
103
|
|
|
122
104
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
105
|
get socketClient() {
|
|
127
106
|
return this._socketClient
|
|
128
107
|
}
|
|
@@ -132,21 +111,10 @@ export class CBCore extends UIObject {
|
|
|
132
111
|
}
|
|
133
112
|
|
|
134
113
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
114
|
set isUserLoggedIn(isUserLoggedIn: boolean) {
|
|
139
|
-
|
|
140
115
|
const previousValue = this.isUserLoggedIn
|
|
141
|
-
|
|
142
|
-
|
|
143
116
|
localStorage.setItem("CBIsUserLoggedIn", "" + isUserLoggedIn)
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
//this._isUserLoggedIn = isUserLoggedIn;
|
|
147
|
-
|
|
148
117
|
this.didSetIsUserLoggedIn(previousValue)
|
|
149
|
-
|
|
150
118
|
}
|
|
151
119
|
|
|
152
120
|
didSetIsUserLoggedIn(previousValue: boolean) {
|
|
@@ -156,167 +124,90 @@ export class CBCore extends UIObject {
|
|
|
156
124
|
if (isUserLoggedIn && previousValue != isUserLoggedIn) {
|
|
157
125
|
|
|
158
126
|
// Send message to views
|
|
159
|
-
|
|
160
127
|
this.broadcastMessageInRootViewTree({
|
|
161
|
-
|
|
162
128
|
name: CBCore.broadcastEventName.userDidLogIn,
|
|
163
129
|
parameters: nil
|
|
164
|
-
|
|
165
130
|
})
|
|
166
131
|
|
|
167
132
|
this.updateLinkTargets()
|
|
168
133
|
|
|
169
|
-
|
|
170
134
|
}
|
|
171
135
|
else if (previousValue != isUserLoggedIn) {
|
|
172
136
|
|
|
173
|
-
|
|
174
137
|
this.performFunctionWithDelay(0.01, function (this: CBCore) {
|
|
175
138
|
|
|
176
139
|
UIRoute.currentRoute.routeByRemovingComponentsOtherThanOnesNamed([
|
|
177
|
-
|
|
178
|
-
"settings",
|
|
179
|
-
"inquiry"
|
|
180
|
-
|
|
140
|
+
"settings"
|
|
181
141
|
]).apply()
|
|
182
142
|
|
|
183
143
|
this.broadcastMessageInRootViewTree({
|
|
184
|
-
|
|
185
144
|
name: CBCore.broadcastEventName.userDidLogOut,
|
|
186
145
|
parameters: nil
|
|
187
|
-
|
|
188
146
|
})
|
|
189
147
|
|
|
190
148
|
this.updateLinkTargets()
|
|
191
149
|
|
|
192
|
-
|
|
193
150
|
}.bind(this))
|
|
194
151
|
|
|
195
152
|
}
|
|
196
153
|
|
|
197
|
-
|
|
198
154
|
}
|
|
199
155
|
|
|
200
156
|
private updateLinkTargets() {
|
|
201
|
-
|
|
202
157
|
this.viewCores.everyElement.rootViewController.view.forEachViewInSubtree(function (view) {
|
|
203
158
|
if (view instanceof UILink) {
|
|
204
159
|
view.updateTarget()
|
|
205
160
|
}
|
|
206
161
|
})
|
|
207
|
-
|
|
208
162
|
}
|
|
209
163
|
|
|
210
164
|
get isUserLoggedIn() {
|
|
211
|
-
|
|
212
|
-
const result = (localStorage.getItem("CBIsUserLoggedIn") == "true")
|
|
213
|
-
|
|
214
|
-
return result
|
|
215
|
-
|
|
165
|
+
return (localStorage.getItem("CBIsUserLoggedIn") == "true")
|
|
216
166
|
}
|
|
217
167
|
|
|
218
168
|
|
|
219
|
-
|
|
220
169
|
get userProfile() {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
try {
|
|
226
|
-
// @ts-ignore
|
|
227
|
-
result = JSON.parse(localStorage.getItem("CBUserProfile"))
|
|
228
|
-
} catch (error) {
|
|
229
|
-
|
|
170
|
+
const text = localStorage.getItem("CBUserProfile")
|
|
171
|
+
if (text) {
|
|
172
|
+
return JSON.parse(text) as CBUserProfile
|
|
230
173
|
}
|
|
231
|
-
|
|
232
|
-
// if (IS_NOT(result)) {
|
|
233
|
-
|
|
234
|
-
// // Get userID from inquiryAccessKey if possible
|
|
235
|
-
// var inquiryKey = this.inquiryAccessKey;
|
|
236
|
-
|
|
237
|
-
// if (IS(inquiryKey)) {
|
|
238
|
-
|
|
239
|
-
// result = FIRST_OR_NIL(this.inquiriesModel.inquiriesByCurrentUser.firstElement).inquirer
|
|
240
|
-
|
|
241
|
-
// }
|
|
242
|
-
|
|
243
|
-
// }
|
|
244
|
-
|
|
245
|
-
return FIRST_OR_NIL(result)
|
|
246
|
-
|
|
174
|
+
return undefined
|
|
247
175
|
}
|
|
248
176
|
|
|
249
177
|
set userProfile(userProfile: CBUserProfile) {
|
|
250
|
-
|
|
251
178
|
if (IS_NOT(userProfile)) {
|
|
252
|
-
|
|
253
179
|
localStorage.removeItem("CBUserProfile")
|
|
254
|
-
|
|
255
180
|
}
|
|
256
|
-
|
|
257
181
|
localStorage.setItem("CBUserProfile", JSON.stringify(userProfile))
|
|
258
|
-
|
|
259
182
|
this.didSetUserProfile()
|
|
260
|
-
|
|
261
183
|
}
|
|
262
184
|
|
|
263
185
|
didSetUserProfile() {
|
|
264
|
-
|
|
265
186
|
this.isUserLoggedIn = IS(this.userProfile)
|
|
266
|
-
|
|
267
187
|
}
|
|
268
188
|
|
|
269
189
|
|
|
270
190
|
set languageKey(languageKey: string) {
|
|
271
|
-
|
|
272
191
|
if (IS_NOT(languageKey)) {
|
|
273
|
-
|
|
274
192
|
localStorage.removeItem("CBLanguageKey")
|
|
275
|
-
|
|
276
193
|
}
|
|
277
|
-
|
|
278
194
|
localStorage.setItem("CBLanguageKey", JSON.stringify(languageKey))
|
|
279
|
-
|
|
280
195
|
this.didSetLanguageKey()
|
|
281
|
-
|
|
282
196
|
}
|
|
283
197
|
|
|
284
198
|
get languageKey() {
|
|
285
|
-
|
|
286
|
-
const result = FIRST(localStorage.getItem("CBLanguageKey"), CBLanguageService.defaultLanguageKey).replace(
|
|
199
|
+
return FIRST(localStorage.getItem("CBLanguageKey"), CBLanguageService.defaultLanguageKey).replace(
|
|
287
200
|
"\"",
|
|
288
201
|
""
|
|
289
202
|
).replace("\"", "")
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
return result
|
|
293
|
-
|
|
294
203
|
}
|
|
295
204
|
|
|
296
205
|
didSetLanguageKey() {
|
|
297
|
-
|
|
298
206
|
UIRoute.currentRoute.routeWithComponent(
|
|
299
207
|
"settings",
|
|
300
208
|
{ "language": this.languageKey },
|
|
301
209
|
YES
|
|
302
210
|
).applyByReplacingCurrentRouteInHistory()
|
|
303
|
-
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
get externalServiceIdentifier(): { accessKey: string; serviceID: string; organizationID: string } {
|
|
308
|
-
|
|
309
|
-
// @ts-ignore
|
|
310
|
-
const result = JSON.parse(localStorage.getItem("CBExternalServiceIdentifier"))
|
|
311
|
-
|
|
312
|
-
return result
|
|
313
|
-
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
set externalServiceIdentifier(externalServiceIdentifier: { accessKey: string; serviceID: string; organizationID: string }) {
|
|
317
|
-
|
|
318
|
-
localStorage.setItem("CBExternalServiceIdentifier", JSON.stringify(externalServiceIdentifier))
|
|
319
|
-
|
|
320
211
|
}
|
|
321
212
|
|
|
322
213
|
|
|
@@ -350,7 +241,6 @@ export class CBCore extends UIObject {
|
|
|
350
241
|
})
|
|
351
242
|
|
|
352
243
|
|
|
353
|
-
|
|
354
244
|
}
|
|
355
245
|
|
|
356
246
|
|
|
@@ -39,6 +39,8 @@ export interface LanguageValues {
|
|
|
39
39
|
|
|
40
40
|
export class CBLanguageService implements UILanguageService {
|
|
41
41
|
|
|
42
|
+
static currentClassObject = CBLanguageService;
|
|
43
|
+
|
|
42
44
|
static _currentLanguageKey: string
|
|
43
45
|
|
|
44
46
|
static languageValues: LanguageValues = {
|
|
@@ -73,19 +75,19 @@ export class CBLanguageService implements UILanguageService {
|
|
|
73
75
|
|
|
74
76
|
}
|
|
75
77
|
|
|
76
|
-
static languages = JSON.parse(JSON.stringify(
|
|
78
|
+
static languages = JSON.parse(JSON.stringify(this.languageValues))
|
|
77
79
|
|
|
78
80
|
static useStoredLanguageValues(values = {}) {
|
|
79
81
|
|
|
80
|
-
const result = JSON.parse(JSON.stringify(
|
|
82
|
+
const result = JSON.parse(JSON.stringify(this.languageValues))
|
|
81
83
|
.objectByCopyingValuesRecursivelyFromObject(
|
|
82
84
|
values) as any
|
|
83
85
|
|
|
84
|
-
if (JSON.stringify(result) != JSON.stringify(
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
86
|
+
if (JSON.stringify(result) != JSON.stringify(this.languages)) {
|
|
87
|
+
|
|
88
|
+
this.languages = result
|
|
89
|
+
|
|
90
|
+
this.broadcastLanguageChangeEvent()
|
|
89
91
|
|
|
90
92
|
}
|
|
91
93
|
|
|
@@ -112,41 +114,41 @@ export class CBLanguageService implements UILanguageService {
|
|
|
112
114
|
|
|
113
115
|
static get currentLanguageKey() {
|
|
114
116
|
|
|
115
|
-
if (!
|
|
117
|
+
if (!this._currentLanguageKey) {
|
|
116
118
|
|
|
117
|
-
|
|
119
|
+
this.updateCurrentLanguageKey()
|
|
118
120
|
|
|
119
121
|
}
|
|
120
122
|
|
|
121
|
-
return
|
|
123
|
+
return this._currentLanguageKey
|
|
122
124
|
|
|
123
125
|
}
|
|
124
126
|
|
|
125
127
|
updateCurrentLanguageKey() {
|
|
126
128
|
|
|
127
|
-
CBLanguageService.updateCurrentLanguageKey()
|
|
129
|
+
CBLanguageService.currentClassObject.updateCurrentLanguageKey()
|
|
128
130
|
|
|
129
131
|
}
|
|
130
132
|
|
|
131
133
|
static updateCurrentLanguageKey(route = UIRoute.currentRoute) {
|
|
132
134
|
|
|
133
|
-
let result = route.componentWithName("settings")
|
|
135
|
+
let result = route.componentWithName("settings")?.parameters?.language
|
|
134
136
|
|
|
135
137
|
if (IS_NOT(result)) {
|
|
136
138
|
|
|
137
|
-
result =
|
|
139
|
+
result = this.defaultLanguageKey
|
|
138
140
|
|
|
139
141
|
}
|
|
140
142
|
|
|
141
|
-
const isChanged = (result !=
|
|
143
|
+
const isChanged = (result != this._currentLanguageKey)
|
|
142
144
|
|
|
143
|
-
|
|
145
|
+
this._currentLanguageKey = result
|
|
144
146
|
|
|
145
147
|
if (isChanged) {
|
|
146
148
|
|
|
147
149
|
CBCore.sharedInstance.languageKey = result
|
|
148
150
|
|
|
149
|
-
|
|
151
|
+
this.broadcastLanguageChangeEvent()
|
|
150
152
|
|
|
151
153
|
}
|
|
152
154
|
|
|
@@ -154,7 +156,7 @@ export class CBLanguageService implements UILanguageService {
|
|
|
154
156
|
|
|
155
157
|
get currentLanguageKey() {
|
|
156
158
|
|
|
157
|
-
const result = CBLanguageService.currentLanguageKey
|
|
159
|
+
const result = CBLanguageService.currentClassObject.currentLanguageKey
|
|
158
160
|
|
|
159
161
|
return result
|
|
160
162
|
|
|
@@ -171,10 +173,10 @@ export class CBLanguageService implements UILanguageService {
|
|
|
171
173
|
|
|
172
174
|
var result: string
|
|
173
175
|
|
|
174
|
-
if (IS(key) &&
|
|
175
|
-
IS_DEFINED(
|
|
176
|
+
if (IS(key) && this.languages[languageKey] &&
|
|
177
|
+
IS_DEFINED(this.languages[languageKey][key])) {
|
|
176
178
|
|
|
177
|
-
result =
|
|
179
|
+
result = this.languages[languageKey][key]
|
|
178
180
|
|
|
179
181
|
}
|
|
180
182
|
else {
|
|
@@ -225,7 +227,7 @@ export class CBLanguageService implements UILanguageService {
|
|
|
225
227
|
) {
|
|
226
228
|
|
|
227
229
|
|
|
228
|
-
return CBLanguageService.stringForKey(key, languageKey, defaultString, parameters)
|
|
230
|
+
return CBLanguageService.currentClassObject.stringForKey(key, languageKey, defaultString, parameters)
|
|
229
231
|
|
|
230
232
|
|
|
231
233
|
}
|
|
@@ -256,7 +258,7 @@ export class CBLanguageService implements UILanguageService {
|
|
|
256
258
|
parameters?: { [x: string]: string | UILocalizedTextObject; }
|
|
257
259
|
) {
|
|
258
260
|
|
|
259
|
-
const result = CBLanguageService.localizedTextObjectForKey(key, defaultString, parameters)
|
|
261
|
+
const result = CBLanguageService.currentClassObject.localizedTextObjectForKey(key, defaultString, parameters)
|
|
260
262
|
|
|
261
263
|
return result
|
|
262
264
|
|
|
@@ -283,7 +285,7 @@ export class CBLanguageService implements UILanguageService {
|
|
|
283
285
|
|
|
284
286
|
localizedTextObjectForText(text: string) {
|
|
285
287
|
|
|
286
|
-
const result = CBLanguageService.localizedTextObjectForText(text)
|
|
288
|
+
const result = CBLanguageService.currentClassObject.localizedTextObjectForText(text)
|
|
287
289
|
|
|
288
290
|
return result
|
|
289
291
|
|
|
@@ -292,12 +294,6 @@ export class CBLanguageService implements UILanguageService {
|
|
|
292
294
|
|
|
293
295
|
static stringForCurrentLanguage(localizedTextObject: CBLocalizedTextObject | string) {
|
|
294
296
|
|
|
295
|
-
if (!CBLanguageService || !localizedTextObject) {
|
|
296
|
-
|
|
297
|
-
const asd = 1
|
|
298
|
-
|
|
299
|
-
}
|
|
300
|
-
|
|
301
297
|
if (localizedTextObject === "" + localizedTextObject) {
|
|
302
298
|
|
|
303
299
|
return localizedTextObject
|
|
@@ -307,12 +303,12 @@ export class CBLanguageService implements UILanguageService {
|
|
|
307
303
|
localizedTextObject = FIRST_OR_NIL(localizedTextObject)
|
|
308
304
|
|
|
309
305
|
// @ts-ignore
|
|
310
|
-
let result: string = localizedTextObject[
|
|
306
|
+
let result: string = localizedTextObject[this.currentLanguageKey]
|
|
311
307
|
|
|
312
308
|
if (IS_NOT(result)) {
|
|
313
309
|
|
|
314
310
|
// @ts-ignore
|
|
315
|
-
result = localizedTextObject[
|
|
311
|
+
result = localizedTextObject[this.defaultLanguageKey]
|
|
316
312
|
|
|
317
313
|
}
|
|
318
314
|
|
|
@@ -335,7 +331,7 @@ export class CBLanguageService implements UILanguageService {
|
|
|
335
331
|
|
|
336
332
|
stringForCurrentLanguage(localizedTextObject: CBLocalizedTextObject) {
|
|
337
333
|
|
|
338
|
-
return CBLanguageService.stringForCurrentLanguage(localizedTextObject)
|
|
334
|
+
return CBLanguageService.currentClassObject.stringForCurrentLanguage(localizedTextObject)
|
|
339
335
|
|
|
340
336
|
}
|
|
341
337
|
|
|
@@ -103,25 +103,25 @@ export class CBSocketClient extends UIObject {
|
|
|
103
103
|
|
|
104
104
|
this.socket.on("connect", () => {
|
|
105
105
|
|
|
106
|
-
console.log("Socket.io connected to server. clientID = "
|
|
106
|
+
console.log("Socket.io connected to server. clientID = ", this.socket, " socketID = ", this.socket)
|
|
107
107
|
|
|
108
108
|
var instanceIdentifier = localStorage.getItem("InstanceIdentifier")
|
|
109
109
|
|
|
110
110
|
if (IS_NOT(instanceIdentifier)) {
|
|
111
111
|
|
|
112
112
|
instanceIdentifier = MAKE_ID()
|
|
113
|
-
localStorage.setItem("InstanceIdentifier", instanceIdentifier)
|
|
113
|
+
localStorage.setItem("InstanceIdentifier", instanceIdentifier!)
|
|
114
114
|
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
const handshakeMessage: CBSocketHandshakeInitMessage = {
|
|
118
118
|
|
|
119
|
-
accessToken: undefined,
|
|
120
|
-
userID: this._core.userProfile
|
|
119
|
+
accessToken: localStorage.getItem("CBUserAccessToken") ?? undefined,
|
|
120
|
+
userID: this._core.userProfile?._id,
|
|
121
121
|
|
|
122
122
|
inquiryAccessKey: undefined,
|
|
123
123
|
|
|
124
|
-
instanceIdentifier: instanceIdentifier
|
|
124
|
+
instanceIdentifier: instanceIdentifier!
|
|
125
125
|
|
|
126
126
|
}
|
|
127
127
|
|
|
@@ -160,7 +160,9 @@ export class CBSocketClient extends UIObject {
|
|
|
160
160
|
|
|
161
161
|
this._callbackHolder = new CBSocketCallbackHolder(this, this._callbackHolder)
|
|
162
162
|
|
|
163
|
-
|
|
163
|
+
|
|
164
|
+
core.userProfile = message.messageData.userProfile ?? {}
|
|
165
|
+
|
|
164
166
|
|
|
165
167
|
this.sendUnsentMessages()
|
|
166
168
|
|
|
@@ -173,7 +175,7 @@ export class CBSocketClient extends UIObject {
|
|
|
173
175
|
|
|
174
176
|
this.socket.on("disconnect", () => {
|
|
175
177
|
|
|
176
|
-
console.log("Socket.io disconnected from server. clientID = "
|
|
178
|
+
console.log("Socket.io disconnected from server. clientID = ", this.socket)
|
|
177
179
|
|
|
178
180
|
this._isConnectionEstablished = NO
|
|
179
181
|
|
|
@@ -192,7 +194,7 @@ export class CBSocketClient extends UIObject {
|
|
|
192
194
|
core.reloadSocketConnection()
|
|
193
195
|
|
|
194
196
|
if (message) {
|
|
195
|
-
|
|
197
|
+
|
|
196
198
|
this._core.dialogViewShowerClass.alert(message)
|
|
197
199
|
|
|
198
200
|
}
|
|
@@ -360,7 +362,7 @@ export class CBSocketClient extends UIObject {
|
|
|
360
362
|
"directOnly": "directOnly",
|
|
361
363
|
"firstOnly": "firstOnly",
|
|
362
364
|
"storedOrFirst": "storedOrFirst"
|
|
363
|
-
|
|
365
|
+
|
|
364
366
|
} as const
|
|
365
367
|
|
|
366
368
|
|
|
@@ -431,7 +433,7 @@ export class CBSocketClient extends UIObject {
|
|
|
431
433
|
isUserBound,
|
|
432
434
|
nil,
|
|
433
435
|
(responseMessage, respondWithMessage) => resolve({
|
|
434
|
-
|
|
436
|
+
|
|
435
437
|
responseMessage: responseMessage,
|
|
436
438
|
result: IF(IS_NOT_SOCKET_ERROR(responseMessage))(() => responseMessage).ELSE(RETURNER(undefined)),
|
|
437
439
|
errorResult: IF(IS_SOCKET_ERROR(responseMessage))(() => responseMessage).ELSE(RETURNER(undefined)),
|