cbcore-ts 1.0.61 → 1.1.0
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/CBDataInterfaces.d.ts +29 -0
- package/compiledScripts/CBDataInterfaces.js.map +2 -2
- package/compiledScripts/CBSocketCallbackHolder.d.ts +20 -1
- package/compiledScripts/CBSocketCallbackHolder.js +69 -4
- package/compiledScripts/CBSocketCallbackHolder.js.map +3 -3
- package/compiledScripts/CBSocketClient.d.ts +46 -3
- package/compiledScripts/CBSocketClient.js +49 -4
- package/compiledScripts/CBSocketClient.js.map +2 -2
- package/package.json +1 -1
- package/scripts/CBDataInterfaces.ts +35 -25
- package/scripts/CBSocketCallbackHolder.ts +143 -30
- package/scripts/CBSocketClient.ts +131 -54
|
@@ -103,6 +103,19 @@ export interface CBSocketMultipleMessageObject<MessageDataType = any> {
|
|
|
103
103
|
key: string;
|
|
104
104
|
message: CBSocketMessage<MessageDataType>;
|
|
105
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* Payload delivered to keepalive handlers on the client.
|
|
108
|
+
* All fields are optional — a bare keepalive with no payload is valid and
|
|
109
|
+
* simply resets the client's timeout window.
|
|
110
|
+
*/
|
|
111
|
+
export interface CBSocketKeepalivePayload {
|
|
112
|
+
/** Human-readable status message, e.g. "Processing items". */
|
|
113
|
+
message?: string;
|
|
114
|
+
/** Completion estimate, 0-100. */
|
|
115
|
+
percentComplete?: number;
|
|
116
|
+
/** Any additional fields the handler author may need. */
|
|
117
|
+
[key: string]: any;
|
|
118
|
+
}
|
|
106
119
|
export interface CBSocketMessage<MessageDataType = any> {
|
|
107
120
|
identifier: string;
|
|
108
121
|
inResponseToIdentifier?: string;
|
|
@@ -114,6 +127,12 @@ export interface CBSocketMessage<MessageDataType = any> {
|
|
|
114
127
|
canBeStoredAsResponse?: boolean;
|
|
115
128
|
useStoredResponse?: boolean;
|
|
116
129
|
responseValidityDuration?: number;
|
|
130
|
+
/**
|
|
131
|
+
* When true this frame is a keepalive pulse, not a real response.
|
|
132
|
+
* The client resets its timeout and fires keepalive handlers; the normal
|
|
133
|
+
* completion machinery is bypassed entirely.
|
|
134
|
+
*/
|
|
135
|
+
isKeepalive?: boolean;
|
|
117
136
|
}
|
|
118
137
|
export interface CBSocketMultipleMessage extends CBSocketMessage<CBSocketMultipleMessageObject[]> {
|
|
119
138
|
shouldGroupResponses: boolean;
|
|
@@ -130,6 +149,16 @@ export interface CBSocketMessageSendResponseFunction<ResponseMessageType = any>
|
|
|
130
149
|
useStoredResponseWithErrorResponse(): void;
|
|
131
150
|
sendErrorResponse(message?: any, completion?: CBSocketMessageCompletionFunction): void;
|
|
132
151
|
sendIntermediateResponse(updateMessage: any, completion?: CBSocketMessageCompletionFunction): void;
|
|
152
|
+
/**
|
|
153
|
+
* Sends a keepalive frame to the client immediately and resets the
|
|
154
|
+
* server-side auto-keepalive interval timer.
|
|
155
|
+
* No-ops silently if the final response has already been sent.
|
|
156
|
+
*
|
|
157
|
+
* Call this at natural yield points (after each await) during long-running
|
|
158
|
+
* handlers to keep the client timeout window alive and optionally deliver
|
|
159
|
+
* progress information.
|
|
160
|
+
*/
|
|
161
|
+
sendKeepalive(payload?: CBSocketKeepalivePayload): void;
|
|
133
162
|
confirmStoredResponseHash(responseHash: string, completion?: CBSocketMessageCompletionFunction): boolean;
|
|
134
163
|
isValid: boolean;
|
|
135
164
|
cancelHandling(): void;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../scripts/CBDataInterfaces.ts"],
|
|
4
|
-
"sourcesContent": ["\n\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["\n\nexport type CBReferenceID = string;\n\n\nexport interface CBLanguageItem {\n \n value: string;\n languageKey: string;\n itemKey: string;\n \n}\n\n\nexport interface LanguagesData {\n [key: string]: {\n [key: string]: string;\n };\n}\n\n\nexport interface CBFinancialAmount {\n \n amount: number;\n currency: string;\n \n}\n\n\nexport interface CBLocalizedTextObject {\n \n [key: string]: string\n \n}\n\n\nexport interface CBDropdownData<T> {\n \n _id: CBReferenceID;\n name?: CBLocalizedTextObject;\n dropdownCode: string;\n data: CBDropdownDataItem<T>[];\n \n}\n\n\nexport interface CBDropdownDataItem<T> {\n \n _id: CBReferenceID;\n title: CBLocalizedTextObject;\n rowsData?: CBDropdownDataItem<T>[]\n isADropdownDataSection: boolean;\n isADropdownDataRow: boolean;\n \n attachedObject: T\n \n itemCode: string;\n dropdownCode: string;\n \n}\n\n\nexport interface CBFileAccessor {\n \n fileData: CBFileData;\n createdAt: number;\n \n}\n\n\nexport interface CBFileData {\n \n _id: string;\n \n name: string;\n dataURL: string;\n type: string;\n isLimitedAccess?: boolean;\n accessibleToUsers?: CBUserProfilePublic[];\n \n}\n\nexport enum CBAuthenticationSource {\n \n google = 10,\n facebook = 11,\n emailAccessLink = 200,\n password = 220,\n inquiryAccessLink = 500\n \n}\n\n// AsdAsd\n\nexport interface CBCoreInitializer {\n \n languageValues: LanguagesData;\n defaultLanguageKey: string;\n \n}\n\nexport interface CBLoginKey {\n \n key: string;\n \n accessToken: string;\n \n storeAccessTokenInClient: boolean;\n \n authenticationSource: CBAuthenticationSource;\n \n userID: CBReferenceID;\n \n isValid: boolean;\n \n loginDate?: Date;\n logoutDate?: Date;\n \n createdAt: Date;\n updatedAt: Date;\n \n}\n\nexport interface CBUserPassword {\n \n passwordHash: string;\n \n userID: CBReferenceID;\n \n isValid: boolean;\n \n createdAt: Date;\n updatedAt: Date;\n \n}\n\nexport interface CBAdministratorRightsDescriptor {\n \n userProfile: CBUserProfile;\n \n}\n\nexport interface CBSubscription {\n \n _id: CBReferenceID;\n startDate: Date;\n endDate?: Date;\n \n isIndefinite: boolean;\n \n subscriptionKind: number;\n createdAt: Date;\n updatedAt: Date;\n \n}\n\n//Asdasd\n\nexport type CBUserProfilePublic = any;\nexport type CBUserProfile = any;\n\n\nexport interface SocketClientInterface {\n \n [x: string]: SocketClientFunction<any, any>;\n \n}\n\n\nexport interface SocketClientResult<ResultType> {\n \n responseMessage: any;\n result: ResultType;\n errorResult: any;\n respondWithMessage: CBSocketMessageSendResponseFunction;\n \n}\n\n\nexport type SocketClientFunction<MessageType, ResultType> = (\n messageData: MessageType,\n completionPolicy?: string,\n isUserBound?: boolean\n) => Promise<SocketClientResult<ResultType>>;\n\nexport type SocketClientNoMessageFunction<ResultType> = (\n messageData?: null,\n completionPolicy?: string,\n isUserBound?: boolean\n) => Promise<SocketClientResult<ResultType>>;\n\n\nexport interface CBSocketMultipleMessageObject<MessageDataType = any> {\n \n key: string;\n message: CBSocketMessage<MessageDataType>;\n \n}\n\n\n/**\n * Payload delivered to keepalive handlers on the client.\n * All fields are optional \u2014 a bare keepalive with no payload is valid and\n * simply resets the client's timeout window.\n */\nexport interface CBSocketKeepalivePayload {\n /** Human-readable status message, e.g. \"Processing items\". */\n message?: string\n /** Completion estimate, 0-100. */\n percentComplete?: number\n /** Any additional fields the handler author may need. */\n [key: string]: any\n}\n\n\n// CBSocket communication messages\nexport interface CBSocketMessage<MessageDataType = any> {\n \n identifier: string;\n inResponseToIdentifier?: string;\n keepWaitingForResponses?: boolean;\n completionPolicy: string;\n \n messageData: MessageDataType;\n \n // This is sent from client to server with requests\n storedResponseHash?: string;\n \n // This is always present on messages sent from the server side\n messageDataHash?: string;\n \n // This tells the client to store this message for future use\n canBeStoredAsResponse?: boolean;\n \n // This tells the client to use the previously stored response\n useStoredResponse?: boolean;\n \n // This tells the client that the response is valid for at least this long in ms\n responseValidityDuration?: number;\n \n /**\n * When true this frame is a keepalive pulse, not a real response.\n * The client resets its timeout and fires keepalive handlers; the normal\n * completion machinery is bypassed entirely.\n */\n isKeepalive?: boolean;\n \n}\n\n\nexport interface CBSocketMultipleMessage extends CBSocketMessage<CBSocketMultipleMessageObject[]> {\n \n shouldGroupResponses: boolean;\n \n}\n\n\nexport type CBSocketMessageSendResponseFunctionBase<ResponseMessageType> = (\n responseMessage: ResponseMessageType,\n completion?: CBSocketMessageCompletionFunction\n) => Promise<string>;\n\nexport type CBSocketMessageCompletionFunction = (\n responseMessage: any,\n respondWithMessage: CBSocketMessageSendResponseFunction\n) => void;\n\nexport type CBSocketMessageHandlerFunction<ResponseMessageType = any> = (\n message: any,\n respondWithMessage: CBSocketMessageSendResponseFunction<ResponseMessageType>\n) => void;\n\nexport type CBSocketMultipleMessagecompletionFunction = (\n responseMessages: any[],\n callcompletionFunctions: () => void\n) => void;\n\n\nexport interface CBSocketMessageSendResponseFunction<ResponseMessageType = any> extends CBSocketMessageSendResponseFunctionBase<ResponseMessageType> {\n respondingToMainResponse: boolean;\n \n excludeMessageFromAutomaticConnectionEvents: () => void;\n \n deferResponse: () => void;\n \n setResponseValidityDuration(duration: number): void;\n \n useStoredResponseWithErrorResponse(): void;\n \n sendErrorResponse(message?: any, completion?: CBSocketMessageCompletionFunction): void;\n \n sendIntermediateResponse(updateMessage: any, completion?: CBSocketMessageCompletionFunction): void;\n \n /**\n * Sends a keepalive frame to the client immediately and resets the\n * server-side auto-keepalive interval timer.\n * No-ops silently if the final response has already been sent.\n *\n * Call this at natural yield points (after each await) during long-running\n * handlers to keep the client timeout window alive and optionally deliver\n * progress information.\n */\n sendKeepalive(payload?: CBSocketKeepalivePayload): void;\n \n // This tells the client to use the stored response if responseHash matches and also enables storing of responses\n // in the client in the first place. Returns true if the hash matched.\n confirmStoredResponseHash(responseHash: string, completion?: CBSocketMessageCompletionFunction): boolean;\n \n // This becomes false when the message is known to be ignored\n isValid: boolean;\n cancelHandling(): void;\n message: CBSocketMessage;\n key: string;\n \n}\n\n\n// Socket handshake messages\nexport interface CBSocketHandshakeInitMessage {\n \n accessToken?: string;\n userID: CBReferenceID;\n \n loginKey?: string;\n inquiryAccessKey?: string;\n \n instanceIdentifier: string;\n \n}\n\n\nexport interface CBSocketHandshakeResponseMessage {\n \n accepted: boolean;\n \n userProfile?: CBUserProfile;\n \n}\n\n\nexport type TypeWithoutKey<Type, Key> = Pick<Type, Exclude<keyof Type, Key>>;\n\nexport type TypeWithoutID<Type> = TypeWithoutKey<Type, \"_id\">;\n\nexport type Diff<T extends keyof any, U extends keyof any> =\n ({ [P in T]: P } & { [P in U]: never } & { [x: string]: never })[T];\n\nexport type Overwrite<T, U> = Pick<T, Diff<keyof T, keyof U>> & U;\n\nexport type RecursivePartial<T> = {\n [P in keyof T]?:\n T[P] extends (infer U)[] ? RecursivePartial<U>[] :\n T[P] extends object ? RecursivePartial<T[P]> :\n T[P];\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAkFO,IAAK,yBAAL,kBAAKA,4BAAL;AAEH,EAAAA,gDAAA,YAAS,MAAT;AACA,EAAAA,gDAAA,cAAW,MAAX;AACA,EAAAA,gDAAA,qBAAkB,OAAlB;AACA,EAAAA,gDAAA,cAAW,OAAX;AACA,EAAAA,gDAAA,uBAAoB,OAApB;AANQ,SAAAA;AAAA,GAAA;",
|
|
6
6
|
"names": ["CBAuthenticationSource"]
|
|
7
7
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UIObject } from "../../uicore-ts";
|
|
2
|
-
import { CBSocketMessage, CBSocketMessageCompletionFunction, CBSocketMessageHandlerFunction, CBSocketMessageSendResponseFunction, CBSocketMultipleMessage, CBSocketMultipleMessagecompletionFunction } from "./CBDataInterfaces";
|
|
2
|
+
import { CBSocketKeepalivePayload, CBSocketMessage, CBSocketMessageCompletionFunction, CBSocketMessageHandlerFunction, CBSocketMessageSendResponseFunction, CBSocketMultipleMessage, CBSocketMultipleMessagecompletionFunction } from "./CBDataInterfaces";
|
|
3
3
|
import { CBSocketClient } from "./CBSocketClient";
|
|
4
4
|
interface CBSocketCallbackHolderMessageDescriptor {
|
|
5
5
|
key: string;
|
|
@@ -15,6 +15,17 @@ interface CBSocketCallbackHolderMessageDescriptor {
|
|
|
15
15
|
anyMainResponseReceived: boolean;
|
|
16
16
|
completionPolicy: string;
|
|
17
17
|
completionFunction: CBSocketMessageCompletionFunction;
|
|
18
|
+
_timeoutId?: ReturnType<typeof setTimeout>;
|
|
19
|
+
/**
|
|
20
|
+
* Called when a keepalive frame arrives for this descriptor's request.
|
|
21
|
+
* Registered via CBSocketRequestPromise.didReceiveKeepalive().
|
|
22
|
+
*/
|
|
23
|
+
keepaliveHandler?: (payload: CBSocketKeepalivePayload) => void;
|
|
24
|
+
/**
|
|
25
|
+
* When true the defaultKeepaliveHandler on CBSocketClient is NOT called
|
|
26
|
+
* for this descriptor — only keepaliveHandler fires.
|
|
27
|
+
*/
|
|
28
|
+
keepaliveHandlerOverridesDefault: boolean;
|
|
18
29
|
}
|
|
19
30
|
export declare class CBSocketCallbackHolder extends UIObject {
|
|
20
31
|
messageDescriptors: {
|
|
@@ -45,6 +56,14 @@ export declare class CBSocketCallbackHolder extends UIObject {
|
|
|
45
56
|
triggerDisconnectHandlers(): void;
|
|
46
57
|
registerHandler(key: string, handlerFunction: CBSocketMessageHandlerFunction): void;
|
|
47
58
|
registerOnetimeHandler(key: string, handlerFunction: CBSocketMessageHandlerFunction): void;
|
|
59
|
+
_scheduleTimeoutForDescriptor(descriptor: CBSocketCallbackHolderMessageDescriptor): void;
|
|
60
|
+
_cancelTimeoutForDescriptor(descriptor: CBSocketCallbackHolderMessageDescriptor): void;
|
|
61
|
+
/**
|
|
62
|
+
* Resets the timeout for a descriptor by cancelling the current timer and
|
|
63
|
+
* scheduling a fresh one. Called whenever a keepalive frame arrives so the
|
|
64
|
+
* request gets a full new window to complete.
|
|
65
|
+
*/
|
|
66
|
+
_resetTimeoutForDescriptor(descriptor: CBSocketCallbackHolderMessageDescriptor): void;
|
|
48
67
|
get storedResponseHashesDictionary(): {
|
|
49
68
|
[x: string]: {
|
|
50
69
|
hash: string;
|
|
@@ -53,10 +53,11 @@ class CBSocketCallbackHolder extends import_uicore_ts.UIObject {
|
|
|
53
53
|
}
|
|
54
54
|
triggerDisconnectHandlers() {
|
|
55
55
|
this.messageDescriptors.forEach(function(descriptor, key) {
|
|
56
|
-
if (descriptor.mainResponseReceived) {
|
|
56
|
+
if (!descriptor.mainResponseReceived) {
|
|
57
|
+
this._cancelTimeoutForDescriptor(descriptor);
|
|
57
58
|
descriptor.completionFunction(import_CBSocketClient.CBSocketClient.disconnectionMessage, import_uicore_ts.nil);
|
|
58
59
|
}
|
|
59
|
-
});
|
|
60
|
+
}.bind(this));
|
|
60
61
|
}
|
|
61
62
|
registerHandler(key, handlerFunction) {
|
|
62
63
|
if (!this.handlers[key]) {
|
|
@@ -70,6 +71,48 @@ class CBSocketCallbackHolder extends import_uicore_ts.UIObject {
|
|
|
70
71
|
}
|
|
71
72
|
this.onetimeHandlers[key].push(handlerFunction);
|
|
72
73
|
}
|
|
74
|
+
_scheduleTimeoutForDescriptor(descriptor) {
|
|
75
|
+
const timeoutMs = this._socketClient.requestTimeoutMs;
|
|
76
|
+
if (!timeoutMs) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
descriptor._timeoutId = setTimeout(() => {
|
|
80
|
+
if (descriptor.mainResponseReceived) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
console.warn(
|
|
84
|
+
`CBSocketCallbackHolder: request "${descriptor.key}" timed out after ${timeoutMs} ms`
|
|
85
|
+
);
|
|
86
|
+
descriptor.mainResponseReceived = import_uicore_ts.YES;
|
|
87
|
+
descriptor.completionFunction(import_CBSocketClient.CBSocketClient.timeoutMessage, import_uicore_ts.nil);
|
|
88
|
+
const descriptorKey = this.keysForIdentifiers[descriptor.message.identifier];
|
|
89
|
+
if (descriptorKey) {
|
|
90
|
+
const descriptorsForKey = this.messageDescriptors[descriptorKey];
|
|
91
|
+
if (descriptorsForKey) {
|
|
92
|
+
descriptorsForKey.removeElement(descriptor);
|
|
93
|
+
if (descriptorsForKey.length === 0) {
|
|
94
|
+
delete this.messageDescriptors[descriptorKey];
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
delete this.keysForIdentifiers[descriptor.message.identifier];
|
|
98
|
+
}
|
|
99
|
+
}, timeoutMs);
|
|
100
|
+
}
|
|
101
|
+
_cancelTimeoutForDescriptor(descriptor) {
|
|
102
|
+
if (descriptor._timeoutId !== void 0) {
|
|
103
|
+
clearTimeout(descriptor._timeoutId);
|
|
104
|
+
descriptor._timeoutId = void 0;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Resets the timeout for a descriptor by cancelling the current timer and
|
|
109
|
+
* scheduling a fresh one. Called whenever a keepalive frame arrives so the
|
|
110
|
+
* request gets a full new window to complete.
|
|
111
|
+
*/
|
|
112
|
+
_resetTimeoutForDescriptor(descriptor) {
|
|
113
|
+
this._cancelTimeoutForDescriptor(descriptor);
|
|
114
|
+
this._scheduleTimeoutForDescriptor(descriptor);
|
|
115
|
+
}
|
|
73
116
|
get storedResponseHashesDictionary() {
|
|
74
117
|
if ((0, import_uicore_ts.IS_NOT)(this._storedResponseHashesDictionary)) {
|
|
75
118
|
this._storedResponseHashesDictionary = JSON.parse(localStorage["CBSocketResponseHashesDictionary"] || "{}");
|
|
@@ -175,8 +218,12 @@ class CBSocketCallbackHolder extends import_uicore_ts.UIObject {
|
|
|
175
218
|
mainResponseReceived: import_uicore_ts.NO,
|
|
176
219
|
anyMainResponseReceived: import_uicore_ts.NO,
|
|
177
220
|
completionPolicy,
|
|
178
|
-
completionFunction
|
|
221
|
+
completionFunction,
|
|
222
|
+
keepaliveHandler: void 0,
|
|
223
|
+
keepaliveHandlerOverridesDefault: import_uicore_ts.NO
|
|
179
224
|
});
|
|
225
|
+
const pushedDescriptor = this.messageDescriptors[descriptorKey].lastElement;
|
|
226
|
+
this._scheduleTimeoutForDescriptor(pushedDescriptor);
|
|
180
227
|
this.keysForIdentifiers[message.identifier] = descriptorKey;
|
|
181
228
|
}
|
|
182
229
|
if (triggerStoredResponseImmediately) {
|
|
@@ -227,7 +274,9 @@ class CBSocketCallbackHolder extends import_uicore_ts.UIObject {
|
|
|
227
274
|
}.bind(this));
|
|
228
275
|
}.bind(this)
|
|
229
276
|
);
|
|
230
|
-
}.bind(this)
|
|
277
|
+
}.bind(this),
|
|
278
|
+
keepaliveHandler: void 0,
|
|
279
|
+
keepaliveHandlerOverridesDefault: import_uicore_ts.NO
|
|
231
280
|
});
|
|
232
281
|
this.keysForIdentifiers[messageToSend.identifier] = descriptorKey;
|
|
233
282
|
}
|
|
@@ -250,6 +299,21 @@ class CBSocketCallbackHolder extends import_uicore_ts.UIObject {
|
|
|
250
299
|
if (message.inResponseToIdentifier && (import_CBSocketClient.CBSocketClient.responseMessageKey == key || import_CBSocketClient.CBSocketClient.multipleMessageKey == key)) {
|
|
251
300
|
const descriptorKey = this.keysForIdentifiers[message.inResponseToIdentifier];
|
|
252
301
|
const descriptorsForKey = this.messageDescriptors[descriptorKey] || [];
|
|
302
|
+
if (message.isKeepalive) {
|
|
303
|
+
const payload = message.messageData || {};
|
|
304
|
+
descriptorsForKey.forEach((descriptor) => {
|
|
305
|
+
var _a2, _b, _c;
|
|
306
|
+
if (descriptor.message.identifier !== message.inResponseToIdentifier) {
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
this._resetTimeoutForDescriptor(descriptor);
|
|
310
|
+
if (!descriptor.keepaliveHandlerOverridesDefault) {
|
|
311
|
+
(_b = (_a2 = this._socketClient).defaultKeepaliveHandler) == null ? void 0 : _b.call(_a2, payload);
|
|
312
|
+
}
|
|
313
|
+
(_c = descriptor.keepaliveHandler) == null ? void 0 : _c.call(descriptor, payload);
|
|
314
|
+
});
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
253
317
|
const responseDataHash = message.messageDataHash;
|
|
254
318
|
if (!message.keepWaitingForResponses) {
|
|
255
319
|
delete this.keysForIdentifiers[message.inResponseToIdentifier];
|
|
@@ -265,6 +329,7 @@ class CBSocketCallbackHolder extends import_uicore_ts.UIObject {
|
|
|
265
329
|
);
|
|
266
330
|
}
|
|
267
331
|
const callCompletionFunction = (descriptor, storedResponseCondition = import_uicore_ts.NO) => {
|
|
332
|
+
this._cancelTimeoutForDescriptor(descriptor);
|
|
268
333
|
var messageData = message.messageData;
|
|
269
334
|
if (message.useStoredResponse && storedResponseCondition) {
|
|
270
335
|
messageData = this.storedResponseForKey(descriptor.key, descriptor.messageDataHash);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../scripts/CBSocketCallbackHolder.ts"],
|
|
4
|
-
"sourcesContent": ["import objectHash from \"object-hash\"\nimport { FIRST, IS, IS_NOT, nil, NO, UIObject, YES } from \"../../uicore-ts\"\nimport {\n CBSocketMessage,\n CBSocketMessageCompletionFunction,\n CBSocketMessageHandlerFunction, CBSocketMessageSendResponseFunction, CBSocketMultipleMessage,\n CBSocketMultipleMessagecompletionFunction, CBSocketMultipleMessageObject\n} from \"./CBDataInterfaces\"\nimport { CBSocketClient } from \"./CBSocketClient\"\n\n\ninterface CBSocketCallbackHolderMessageDescriptor {\n \n key: string;\n message: {\n identifier: string;\n inResponseToIdentifier?: string;\n keepWaitingForResponses?: boolean;\n }\n \n \n sentAtTime: number;\n \n //completionTriggered: boolean;\n \n messageDataHash: string;\n \n responseDataHash?: string;\n \n mainResponseReceived: boolean;\n \n anyMainResponseReceived: boolean;\n \n completionPolicy: string;\n completionFunction: CBSocketMessageCompletionFunction;\n \n}\n\n\ninterface CBSocketCallbackHolderStoredResponseObject {\n \n messageKey: string;\n messageData: any;\n messageDataHash: string;\n \n}\n\n\nexport class CBSocketCallbackHolder extends UIObject {\n \n messageDescriptors: {\n \n [x: string]: CBSocketCallbackHolderMessageDescriptor[]\n \n } = {}\n \n handlers: {\n [x: string]: CBSocketMessageHandlerFunction[]\n } = {}\n \n onetimeHandlers: {\n [x: string]: CBSocketMessageHandlerFunction[]\n } = {}\n \n keysForIdentifiers: {\n \n [x: string]: string\n \n } = {}\n \n \n isValid = YES\n _storeableResponseKeys: string[] = []\n _storedResponseHashesDictionary: {\n \n [x: string]: {\n \n hash: string,\n validityDate: number\n \n }\n \n } = {}\n _verifiedResponseHashesDictionary: {\n \n [x: string]: boolean\n \n } = {}\n \n _socketClient: CBSocketClient\n \n \n constructor(socketClient: CBSocketClient, previousCallbackHolder?: CBSocketCallbackHolder) {\n \n super()\n \n \n this._socketClient = socketClient\n \n if (IS(previousCallbackHolder)) {\n \n this.handlers = previousCallbackHolder.handlers\n this._verifiedResponseHashesDictionary = previousCallbackHolder._verifiedResponseHashesDictionary\n \n }\n \n \n }\n \n \n triggerDisconnectHandlers() {\n \n this.messageDescriptors.forEach(function (descriptor: CBSocketCallbackHolderMessageDescriptor, key: string) {\n \n if (descriptor.mainResponseReceived) {\n \n descriptor.completionFunction(CBSocketClient.disconnectionMessage, nil)\n \n }\n \n })\n \n }\n \n \n registerHandler(key: string, handlerFunction: CBSocketMessageHandlerFunction) {\n \n \n if (!this.handlers[key]) {\n \n this.handlers[key] = []\n \n }\n \n this.handlers[key].push(handlerFunction)\n \n \n }\n \n registerOnetimeHandler(key: string, handlerFunction: CBSocketMessageHandlerFunction) {\n \n \n if (!this.onetimeHandlers[key]) {\n \n this.onetimeHandlers[key] = []\n \n }\n \n this.onetimeHandlers[key].push(handlerFunction)\n \n \n }\n \n \n get storedResponseHashesDictionary() {\n \n if (IS_NOT(this._storedResponseHashesDictionary)) {\n \n this._storedResponseHashesDictionary = JSON.parse(localStorage[\"CBSocketResponseHashesDictionary\"] || \"{}\")\n \n }\n \n return this._storedResponseHashesDictionary\n \n }\n \n storedResponseHashObjectForKey(requestKey: string, requestDataHash: string) {\n \n const localStorageKey = this.keyForRequestKeyAndRequestDataHash(requestKey, requestDataHash)\n \n const hashObject = this.storedResponseHashesDictionary[localStorageKey]\n \n const result = FIRST(hashObject, {} as any)\n \n \n return result\n \n }\n \n storedResponseForKey(requestKey: string, requestDataHash: string) {\n \n const localStorageKey = this.keyForRequestKeyAndRequestDataHash(requestKey, requestDataHash)\n \n const storedObject = JSON.parse(localStorage[localStorageKey] || \"{}\")\n \n return storedObject.responseMessageData\n \n }\n \n keyForRequestKeyAndRequestDataHash(requestKey: string, requestDataHash: string) {\n \n const result = \"_CBSCH_LS_key_\" + requestKey + \"_\" + requestDataHash\n \n return result\n \n }\n \n storeResponse(\n requestKey: string,\n requestDataHash: string,\n responseMessage: CBSocketMessage<any>,\n responseDataHash: string\n ) {\n \n \n if (!responseMessage.canBeStoredAsResponse ||\n (IS_NOT(responseMessage.messageData) && IS_NOT(responseMessage.messageDataHash))) {\n \n return\n \n }\n \n \n const localStorageKey = this.keyForRequestKeyAndRequestDataHash(requestKey, requestDataHash)\n \n \n var validityDate: number\n \n if (responseMessage.responseValidityDuration) {\n \n validityDate = Date.now() + responseMessage.responseValidityDuration\n \n }\n \n const storedResponseHashesDictionary = this.storedResponseHashesDictionary\n storedResponseHashesDictionary[localStorageKey] = {\n \n hash: responseDataHash,\n validityDate: validityDate!\n \n }\n \n this.saveInLocalStorage(localStorageKey, {\n \n responseMessageData: responseMessage.messageData,\n responseHash: responseDataHash\n \n })\n \n \n this.saveStoredResponseHashesDictionary(storedResponseHashesDictionary)\n \n }\n \n \n private saveStoredResponseHashesDictionary(storedResponseHashesDictionary: {\n [x: string]: { hash: string; validityDate: number; };\n }) {\n \n this.saveInLocalStorage(\"CBSocketResponseHashesDictionary\", storedResponseHashesDictionary)\n \n }\n \n saveInLocalStorage(key: string, object: any) {\n \n \n const stringToSave = JSON.stringify(object)\n \n if (stringToSave != localStorage[key]) {\n \n localStorage[key] = stringToSave\n \n }\n \n \n }\n \n \n socketShouldSendMessage(\n key: string,\n message: CBSocketMessage<any>,\n completionPolicy: string,\n completionFunction: CBSocketMessageCompletionFunction\n ) {\n \n \n var result = YES\n \n var triggerStoredResponseImmediately = NO\n \n \n const messageDataHash = objectHash(message.messageData || nil)\n \n const descriptorKey = \"socketMessageDescriptor_\" + key + messageDataHash\n \n this.messageDescriptors[descriptorKey] = (this.messageDescriptors[descriptorKey] || [])\n \n \n const hashObject = this.storedResponseHashObjectForKey(key, messageDataHash)\n message.storedResponseHash = hashObject.hash\n \n \n if (completionPolicy == CBSocketClient.completionPolicy.first) {\n \n const descriptorsForKey = (this.messageDescriptors[descriptorKey] || [])\n \n const matchingDescriptor = descriptorsForKey.find(function (descriptor, index, array) {\n return (descriptor.messageDataHash == messageDataHash)\n })\n \n if (matchingDescriptor) {\n \n result = NO\n \n }\n \n }\n \n if (completionPolicy == CBSocketClient.completionPolicy.storedOrFirst) {\n \n const descriptorsForKey = (this.messageDescriptors[descriptorKey] || [])\n \n const matchingDescriptor = descriptorsForKey.find(function (descriptor, index, array) {\n return (descriptor.messageDataHash == messageDataHash)\n })\n \n const storedResponse = IS(message.storedResponseHash)\n \n if (matchingDescriptor ||\n (storedResponse && this._verifiedResponseHashesDictionary[message.storedResponseHash!])) {\n \n result = NO\n \n triggerStoredResponseImmediately = YES\n \n }\n \n }\n \n if (completionPolicy == CBSocketClient.completionPolicy.firstOnly) {\n \n const descriptorsForKey = (this.messageDescriptors[descriptorKey] || [])\n \n const matchingDescriptor = descriptorsForKey.find(function (descriptor, index, array) {\n return (descriptor.messageDataHash == messageDataHash)\n })\n \n if (matchingDescriptor) {\n \n return NO\n \n }\n \n }\n \n \n if (hashObject && hashObject.hash && hashObject.validityDate && message.storedResponseHash &&\n this._verifiedResponseHashesDictionary[message.storedResponseHash] && hashObject.validityDate >\n Date.now()) {\n \n result = NO\n \n triggerStoredResponseImmediately = YES\n \n }\n \n \n if (IS(completionFunction)) {\n \n this.messageDescriptors[descriptorKey].push({\n \n key: key,\n message: {\n \n identifier: message.identifier,\n inResponseToIdentifier: message.inResponseToIdentifier,\n keepWaitingForResponses: message.keepWaitingForResponses\n \n },\n \n sentAtTime: Date.now(),\n \n //completionTriggered: NO,\n \n \n messageDataHash: messageDataHash,\n \n mainResponseReceived: NO,\n anyMainResponseReceived: NO,\n \n \n completionPolicy: completionPolicy,\n completionFunction: completionFunction\n \n })\n \n this.keysForIdentifiers[message.identifier] = descriptorKey\n \n }\n \n \n if (triggerStoredResponseImmediately) {\n \n this.socketDidReceiveMessageForKey(\n CBSocketClient.responseMessageKey,\n {\n \n identifier: nil,\n messageData: nil,\n completionPolicy: CBSocketClient.completionPolicy.directOnly,\n \n inResponseToIdentifier: message.identifier,\n \n useStoredResponse: YES\n \n },\n nil\n )\n \n }\n \n \n return result\n \n \n }\n \n \n static defaultMultipleMessagecompletionFunction(responseMessages: any[], callcompletionFunctions: () => void) {\n callcompletionFunctions()\n }\n \n \n socketWillSendMultipleMessage(\n messageToSend: CBSocketMultipleMessage,\n completionFunction: CBSocketMultipleMessagecompletionFunction = CBSocketCallbackHolder.defaultMultipleMessagecompletionFunction\n ) {\n \n \n const key = CBSocketClient.multipleMessageKey\n \n \n const messageDataHash = objectHash(messageToSend.messageData || nil)\n \n const descriptorKey = \"socketMessageDescriptor_\" + key + messageDataHash\n \n this.messageDescriptors[descriptorKey] = (this.messageDescriptors[descriptorKey] || [])\n \n \n messageToSend.storedResponseHash = this.storedResponseHashObjectForKey(key, messageDataHash).hash\n \n \n this.messageDescriptors[descriptorKey].push({\n \n key: key,\n message: {\n \n identifier: messageToSend.identifier,\n inResponseToIdentifier: messageToSend.inResponseToIdentifier,\n keepWaitingForResponses: messageToSend.keepWaitingForResponses\n \n },\n \n sentAtTime: Date.now(),\n \n //completionTriggered: NO,\n \n \n messageDataHash: messageDataHash,\n \n mainResponseReceived: NO,\n anyMainResponseReceived: NO,\n \n \n completionPolicy: CBSocketClient.completionPolicy.directOnly,\n completionFunction: function (\n this: CBSocketCallbackHolder,\n responseMessage: CBSocketMultipleMessageObject[],\n respondWithMessage: any\n ) {\n \n completionFunction(\n responseMessage.map(function (messageObject, index, array) {\n \n return messageObject.message.messageData\n \n }),\n function (this: CBSocketCallbackHolder) {\n \n //console.log(\"Received multiple message response with length of \" + responseMessage.length +\n // \".\");\n \n // Call all completion functions\n responseMessage.forEach(function (\n this: CBSocketCallbackHolder,\n messageObject: CBSocketMultipleMessageObject,\n index: number,\n array: CBSocketMultipleMessageObject[]\n ) {\n \n this._socketClient.didReceiveMessageForKey(messageObject.key, messageObject.message)\n \n }.bind(this))\n \n }.bind(this)\n )\n \n }.bind(this)\n \n })\n \n this.keysForIdentifiers[messageToSend.identifier] = descriptorKey\n \n \n }\n \n \n socketDidReceiveMessageForKey(\n key: string,\n message: CBSocketMessage<any>,\n sendResponseFunction: CBSocketMessageSendResponseFunction\n ) {\n \n \n if (!this.isValid) {\n \n return\n \n }\n \n \n // Call static handlers\n if (this.handlers[key]) {\n \n this.handlers[key].forEach(function (\n this: CBSocketCallbackHolder,\n handler: CBSocketMessageHandlerFunction,\n index: any,\n array: any\n ) {\n \n handler(message.messageData, sendResponseFunction)\n \n }.bind(this))\n \n }\n \n if (this.onetimeHandlers[key]) {\n \n this.onetimeHandlers[key].forEach(function (\n this: CBSocketCallbackHolder,\n handler: CBSocketMessageHandlerFunction\n ) {\n \n handler(message.messageData, sendResponseFunction)\n \n }.bind(this))\n \n delete this.onetimeHandlers[key]\n \n }\n \n \n // Temporary response handlers are evaluated here\n if (message.inResponseToIdentifier &&\n (CBSocketClient.responseMessageKey == key || CBSocketClient.multipleMessageKey == key)) {\n \n // Find descriptors for the key of the message that is being responded to\n const descriptorKey = this.keysForIdentifiers[message.inResponseToIdentifier]\n const descriptorsForKey = (this.messageDescriptors[descriptorKey] || [])\n \n // Find response data hash to check for differences\n const responseDataHash = message.messageDataHash\n \n // Remove identifier from dictionary\n if (!message.keepWaitingForResponses) {\n \n delete this.keysForIdentifiers[message.inResponseToIdentifier]\n \n // Do NOT delete the entire descriptorKey bucket here \u2014 multiple descriptors\n // with identical messageData (e.g. two concurrent requests with undefined payload)\n // share the same bucket. The per-descriptor removeElement() calls below handle\n // individual cleanup. We only delete the bucket once it is fully empty.\n \n }\n \n \n // @ts-ignore\n if (document.cbsocketclientlogmessages) {\n console.log(\n \"Callback holder is handling message. [\", descriptorsForKey.firstElement?.key, \"] \",\n message,\n \" Descriptors for key is \",\n ...descriptorsForKey\n )\n }\n \n // Function to call completion function\n const callCompletionFunction = (\n descriptor: CBSocketCallbackHolderMessageDescriptor,\n storedResponseCondition = NO\n ) => {\n \n var messageData = message.messageData\n \n if (message.useStoredResponse && storedResponseCondition) {\n \n messageData = this.storedResponseForKey(descriptor.key, descriptor.messageDataHash)\n \n const responseHash = this.storedResponseHashObjectForKey(\n descriptor.key,\n descriptor.messageDataHash\n ).hash\n \n const localStorageKey = this.keyForRequestKeyAndRequestDataHash(\n descriptor.key,\n descriptor.messageDataHash\n )\n \n if (message.responseValidityDuration && this.storedResponseHashesDictionary[localStorageKey]) {\n \n this.storedResponseHashesDictionary[localStorageKey].validityDate = Date.now() +\n message.responseValidityDuration\n \n this.saveStoredResponseHashesDictionary(this.storedResponseHashesDictionary)\n \n }\n \n this._verifiedResponseHashesDictionary[responseHash] = YES\n \n console.log(\"Using stored response.\")\n \n }\n \n // Call completionFunction and set response data hash\n descriptor.completionFunction(messageData, sendResponseFunction)\n descriptor.responseDataHash = responseDataHash\n \n }\n \n \n descriptorsForKey.copy().forEach(function (\n this: CBSocketCallbackHolder,\n descriptor: CBSocketCallbackHolderMessageDescriptor,\n index: number,\n array: CBSocketCallbackHolderMessageDescriptor[]\n ) {\n \n \n if ((descriptor.completionPolicy == CBSocketClient.completionPolicy.directOnly &&\n descriptor.message.identifier == message.inResponseToIdentifier) || descriptor.completionPolicy ==\n CBSocketClient.completionPolicy.first || descriptor.completionPolicy ==\n CBSocketClient.completionPolicy.firstOnly || descriptor.completionPolicy ==\n CBSocketClient.completionPolicy.storedOrFirst) {\n \n // Calling completion function and removing descriptor\n \n if (!message.keepWaitingForResponses) {\n \n this.storeResponse(descriptor.key, descriptor.messageDataHash, message, responseDataHash!)\n \n descriptorsForKey.removeElement(descriptor)\n \n sendResponseFunction.respondingToMainResponse = YES\n \n }\n \n callCompletionFunction(descriptor, !message.keepWaitingForResponses)\n \n }\n else if (descriptor.completionPolicy == CBSocketClient.completionPolicy.all) {\n \n // Calling completion function\n callCompletionFunction(descriptor, !message.keepWaitingForResponses)\n \n // Marking descriptor as having been responded to\n if (!message.keepWaitingForResponses) {\n \n if (message.inResponseToIdentifier == descriptor.message.identifier) {\n \n sendResponseFunction.respondingToMainResponse = YES\n descriptor.mainResponseReceived = YES\n descriptorsForKey.removeElement(descriptor)\n \n }\n \n descriptor.anyMainResponseReceived = YES\n \n }\n \n \n }\n else if (descriptor.completionPolicy == CBSocketClient.completionPolicy.allDifferent) {\n \n // Calling completionFunction if messageData is different from previous\n if (descriptor.responseDataHash != responseDataHash) {\n \n callCompletionFunction(descriptor, !message.keepWaitingForResponses)\n \n }\n \n // Marking descriptor as having been responded to\n if (!message.keepWaitingForResponses) {\n \n if (message.inResponseToIdentifier == descriptor.message.identifier) {\n \n sendResponseFunction.respondingToMainResponse = YES\n descriptor.mainResponseReceived = YES\n descriptorsForKey.removeElement(descriptor)\n \n }\n \n descriptor.anyMainResponseReceived = YES\n \n }\n \n }\n else if (descriptor.completionPolicy == CBSocketClient.completionPolicy.last &&\n descriptor.message.identifier == message.inResponseToIdentifier) {\n \n if (!message.keepWaitingForResponses) {\n \n // Marking descriptor as having been responded to\n descriptor.mainResponseReceived = YES\n descriptor.anyMainResponseReceived = YES\n \n sendResponseFunction.respondingToMainResponse = YES\n \n }\n else {\n \n descriptor.completionFunction(message.messageData, sendResponseFunction)\n \n }\n \n }\n else if (descriptor.completionPolicy == CBSocketClient.completionPolicy.firstAndLast ||\n descriptor.completionPolicy == CBSocketClient.completionPolicy.firstAndLastIfDifferent) {\n \n if (!message.keepWaitingForResponses) {\n \n // Only calling completionFunction once as a first response call\n if (!descriptor.anyMainResponseReceived) {\n \n callCompletionFunction(descriptor, !message.keepWaitingForResponses)\n \n }\n \n // Marking descriptor as having been responded to\n if (descriptor.message.identifier == message.inResponseToIdentifier) {\n \n descriptor.mainResponseReceived = YES\n sendResponseFunction.respondingToMainResponse = YES\n \n }\n \n descriptor.anyMainResponseReceived = YES\n \n }\n else if (descriptor.message.identifier == message.inResponseToIdentifier &&\n message.keepWaitingForResponses) {\n \n descriptor.completionFunction(message.messageData, sendResponseFunction)\n \n }\n \n }\n \n }.bind(this))\n \n \n // Last message completion policies\n \n const allResponsesReceived = descriptorsForKey.allMatch(function (descriptorObject, index, array) {\n return descriptorObject.mainResponseReceived\n })\n \n descriptorsForKey.copy().forEach(function (\n this: CBSocketCallbackHolder,\n descriptor: CBSocketCallbackHolderMessageDescriptor,\n index: number,\n array: CBSocketCallbackHolderMessageDescriptor[]\n ) {\n \n if ((descriptor.completionPolicy == CBSocketClient.completionPolicy.last ||\n descriptor.completionPolicy == CBSocketClient.completionPolicy.firstAndLast) &&\n allResponsesReceived && !message.keepWaitingForResponses) {\n \n // Calling completionFunction\n callCompletionFunction(descriptor, !message.keepWaitingForResponses)\n \n // Cleaning up\n descriptorsForKey.removeElement(descriptor)\n \n }\n else if (descriptor.completionPolicy == CBSocketClient.completionPolicy.firstAndLastIfDifferent &&\n allResponsesReceived && !message.keepWaitingForResponses) {\n \n // Calling completionFunction if needed\n if (descriptor.responseDataHash != responseDataHash) {\n \n callCompletionFunction(descriptor, !message.keepWaitingForResponses)\n \n }\n \n // Cleaning up\n descriptorsForKey.removeElement(descriptor)\n \n }\n \n }.bind(this))\n \n \n // Clean up the bucket if all descriptors have been removed\n if (!message.keepWaitingForResponses && descriptorsForKey.length === 0) {\n \n delete this.messageDescriptors[descriptorKey]\n \n }\n \n }\n \n \n }\n \n \n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAAuB;AACvB,uBAA0D;
|
|
6
|
-
"names": ["objectHash"]
|
|
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,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AG;AAEpE,eAAO,KAAK,mBAAmB,aAAa;AAAA,MAEhD;AAAA,IAEJ;AAAA,EAGJ;AAGJ;",
|
|
6
|
+
"names": ["objectHash", "_a"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Socket } from "socket.io-client";
|
|
2
2
|
import { UIObject } from "../../uicore-ts";
|
|
3
3
|
import { CBCore } from "./CBCore";
|
|
4
|
-
import { CBSocketMessage, CBSocketMessageCompletionFunction, CBSocketMessageHandlerFunction, CBSocketMessageSendResponseFunction, CBSocketMultipleMessagecompletionFunction, SocketClientInterface } from "./CBDataInterfaces";
|
|
4
|
+
import { CBSocketKeepalivePayload, CBSocketMessage, CBSocketMessageCompletionFunction, CBSocketMessageHandlerFunction, CBSocketMessageSendResponseFunction, CBSocketMultipleMessagecompletionFunction, SocketClientInterface } from "./CBDataInterfaces";
|
|
5
5
|
import { CBSocketCallbackHolder } from "./CBSocketCallbackHolder";
|
|
6
6
|
declare interface CBSocketClientMessageToBeSent {
|
|
7
7
|
key: string;
|
|
@@ -19,6 +19,25 @@ declare interface CBSocketClientErrorMessage {
|
|
|
19
19
|
}
|
|
20
20
|
export declare function IS_SOCKET_ERROR(object: any): object is CBSocketClientErrorMessage;
|
|
21
21
|
export declare function IS_NOT_SOCKET_ERROR(object: any): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* A Promise returned by resultForMessageForKey.
|
|
24
|
+
* Exposes didReceiveKeepalive() for registering a keepalive callback
|
|
25
|
+
* in the same fluent style as the rest of the API.
|
|
26
|
+
*/
|
|
27
|
+
export interface CBSocketRequestPromise<T> extends Promise<T> {
|
|
28
|
+
/**
|
|
29
|
+
* Register a handler to be called each time a keepalive frame arrives
|
|
30
|
+
* for this request.
|
|
31
|
+
*
|
|
32
|
+
* @param handler Called with the payload sent by the server.
|
|
33
|
+
* @param extendsDefaultHandler When true (default) the application-level
|
|
34
|
+
* defaultKeepaliveHandler fires first, then
|
|
35
|
+
* this handler. When false this handler fires
|
|
36
|
+
* alone and the default is suppressed for this
|
|
37
|
+
* request.
|
|
38
|
+
*/
|
|
39
|
+
didReceiveKeepalive(handler: (payload: CBSocketKeepalivePayload) => void, extendsDefaultHandler?: boolean): CBSocketRequestPromise<T>;
|
|
40
|
+
}
|
|
22
41
|
export declare class CBSocketClient extends UIObject {
|
|
23
42
|
_socket: Socket;
|
|
24
43
|
_isConnectionEstablished: boolean;
|
|
@@ -33,6 +52,25 @@ export declare class CBSocketClient extends UIObject {
|
|
|
33
52
|
static responseMessageKey: string;
|
|
34
53
|
static multipleMessageKey: string;
|
|
35
54
|
static disconnectionMessage: CBSocketClientErrorMessage;
|
|
55
|
+
static timeoutMessage: CBSocketClientErrorMessage;
|
|
56
|
+
/**
|
|
57
|
+
* How long (in milliseconds) to wait for a server response before treating
|
|
58
|
+
* the request as failed. Set to 0 to disable timeouts entirely.
|
|
59
|
+
* Default: 30 000 ms (30 seconds).
|
|
60
|
+
*
|
|
61
|
+
* Each keepalive frame from the server resets this window, so long-running
|
|
62
|
+
* requests only time out if the server goes completely silent for this duration.
|
|
63
|
+
*/
|
|
64
|
+
requestTimeoutMs: number;
|
|
65
|
+
/**
|
|
66
|
+
* Application-level keepalive handler. Called for every keepalive frame
|
|
67
|
+
* received on any request, unless the per-call handler was registered with
|
|
68
|
+
* extendsDefaultHandler = false.
|
|
69
|
+
*
|
|
70
|
+
* Configure once at application startup:
|
|
71
|
+
* CBSocketClient.sharedInstance.defaultKeepaliveHandler = payload => { ... }
|
|
72
|
+
*/
|
|
73
|
+
defaultKeepaliveHandler?: (payload: CBSocketKeepalivePayload) => void;
|
|
36
74
|
constructor(core: CBCore);
|
|
37
75
|
get socket(): Socket<import("@socket.io/component-emitter").DefaultEventsMap, import("@socket.io/component-emitter").DefaultEventsMap>;
|
|
38
76
|
cancelUnsentMessages(messagesToCancel: CBSocketClientMessageToBeSent[]): void;
|
|
@@ -52,13 +90,18 @@ export declare class CBSocketClient extends UIObject {
|
|
|
52
90
|
sendUserBoundMessageForKey(key: keyof SocketClientInterface, message: any, completion?: CBSocketMessageCompletionFunction): void;
|
|
53
91
|
sendMessageForKeyWithPolicy(key: keyof SocketClientInterface, message: any, completionPolicy: keyof typeof CBSocketClient.completionPolicy, completion?: CBSocketMessageCompletionFunction): void;
|
|
54
92
|
sendMessageForKey(key: keyof SocketClientInterface, message: any, completion?: CBSocketMessageCompletionFunction): void;
|
|
55
|
-
resultForMessageForKey(key: keyof SocketClientInterface, message: any, completionPolicy?: keyof typeof CBSocketClient.completionPolicy, isUserBound?: boolean):
|
|
93
|
+
resultForMessageForKey(key: keyof SocketClientInterface, message: any, completionPolicy?: keyof typeof CBSocketClient.completionPolicy, isUserBound?: boolean): CBSocketRequestPromise<{
|
|
56
94
|
responseMessage: any;
|
|
57
95
|
result: any;
|
|
58
96
|
errorResult: any;
|
|
59
97
|
respondWithMessage: CBSocketMessageSendResponseFunction;
|
|
60
98
|
}>;
|
|
61
|
-
|
|
99
|
+
/**
|
|
100
|
+
* Finds the descriptor for the given request identifier and attaches the
|
|
101
|
+
* keepalive handler fields to it.
|
|
102
|
+
*/
|
|
103
|
+
_attachKeepaliveHandlerForIdentifier(identifier: string, handler: (payload: CBSocketKeepalivePayload) => void, extendsDefaultHandler: boolean): void;
|
|
104
|
+
_sendMessageForKey(key: string, message: any, inResponseToMessage?: CBSocketMessage<any>, keepMessageConnectionOpen?: boolean, completionPolicy?: keyof typeof CBSocketClient.completionPolicy, isUserBound?: boolean, didSendFunction?: () => void, completion?: CBSocketMessageCompletionFunction, didObtainIdentifier?: (identifier: string) => void): CBSocketClientMessageToBeSent | undefined;
|
|
62
105
|
sendMessagesAsGroup<FunctionReturnType extends object>(functionToCall: () => FunctionReturnType): FunctionReturnType;
|
|
63
106
|
sendAndReceiveMessagesAsGroup<FunctionReturnType extends object>(functionToCall: () => FunctionReturnType, completion?: CBSocketMultipleMessagecompletionFunction): FunctionReturnType;
|
|
64
107
|
didReceiveMessageForKey(key: string, message: CBSocketMessage<any>): void;
|
|
@@ -43,6 +43,15 @@ const _CBSocketClient = class _CBSocketClient extends import_uicore_ts.UIObject
|
|
|
43
43
|
this._messagesToBeSent = [];
|
|
44
44
|
this._subscribedKeys = {};
|
|
45
45
|
this._callbackHolder = new import_CBSocketCallbackHolder.CBSocketCallbackHolder(this);
|
|
46
|
+
/**
|
|
47
|
+
* How long (in milliseconds) to wait for a server response before treating
|
|
48
|
+
* the request as failed. Set to 0 to disable timeouts entirely.
|
|
49
|
+
* Default: 30 000 ms (30 seconds).
|
|
50
|
+
*
|
|
51
|
+
* Each keepalive frame from the server resets this window, so long-running
|
|
52
|
+
* requests only time out if the server goes completely silent for this duration.
|
|
53
|
+
*/
|
|
54
|
+
this.requestTimeoutMs = 3e4;
|
|
46
55
|
this._core = core;
|
|
47
56
|
this._socket = (0, import_socket.io)();
|
|
48
57
|
this.socket.on("connect", () => {
|
|
@@ -173,7 +182,8 @@ const _CBSocketClient = class _CBSocketClient extends import_uicore_ts.UIObject
|
|
|
173
182
|
this._sendMessageForKey(key, message, void 0, import_uicore_ts.NO, void 0, import_uicore_ts.NO, import_uicore_ts.nil, completion);
|
|
174
183
|
}
|
|
175
184
|
resultForMessageForKey(key, message, completionPolicy, isUserBound = import_uicore_ts.NO) {
|
|
176
|
-
|
|
185
|
+
let capturedIdentifier;
|
|
186
|
+
const basePromise = new Promise((resolve, reject) => {
|
|
177
187
|
this._sendMessageForKey(
|
|
178
188
|
key,
|
|
179
189
|
message,
|
|
@@ -187,18 +197,49 @@ const _CBSocketClient = class _CBSocketClient extends import_uicore_ts.UIObject
|
|
|
187
197
|
result: (0, import_uicore_ts.IF)(IS_NOT_SOCKET_ERROR(responseMessage))(() => responseMessage).ELSE((0, import_uicore_ts.RETURNER)(void 0)),
|
|
188
198
|
errorResult: (0, import_uicore_ts.IF)(IS_SOCKET_ERROR(responseMessage))(() => responseMessage).ELSE((0, import_uicore_ts.RETURNER)(void 0)),
|
|
189
199
|
respondWithMessage
|
|
190
|
-
})
|
|
200
|
+
}),
|
|
201
|
+
(identifier) => {
|
|
202
|
+
capturedIdentifier = identifier;
|
|
203
|
+
}
|
|
191
204
|
);
|
|
192
205
|
});
|
|
193
|
-
|
|
206
|
+
const requestPromise = basePromise;
|
|
207
|
+
requestPromise.didReceiveKeepalive = (handler, extendsDefaultHandler = import_uicore_ts.YES) => {
|
|
208
|
+
if (capturedIdentifier) {
|
|
209
|
+
this._attachKeepaliveHandlerForIdentifier(capturedIdentifier, handler, extendsDefaultHandler);
|
|
210
|
+
}
|
|
211
|
+
return requestPromise;
|
|
212
|
+
};
|
|
213
|
+
return requestPromise;
|
|
194
214
|
}
|
|
195
|
-
|
|
215
|
+
/**
|
|
216
|
+
* Finds the descriptor for the given request identifier and attaches the
|
|
217
|
+
* keepalive handler fields to it.
|
|
218
|
+
*/
|
|
219
|
+
_attachKeepaliveHandlerForIdentifier(identifier, handler, extendsDefaultHandler) {
|
|
220
|
+
const descriptorKey = this._callbackHolder.keysForIdentifiers[identifier];
|
|
221
|
+
if (!descriptorKey) {
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
const descriptors = this._callbackHolder.messageDescriptors[descriptorKey];
|
|
225
|
+
if (!descriptors) {
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
const descriptor = descriptors.find((d) => d.message.identifier === identifier);
|
|
229
|
+
if (!descriptor) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
descriptor.keepaliveHandler = handler;
|
|
233
|
+
descriptor.keepaliveHandlerOverridesDefault = !extendsDefaultHandler;
|
|
234
|
+
}
|
|
235
|
+
_sendMessageForKey(key, message, inResponseToMessage = {}, keepMessageConnectionOpen = import_uicore_ts.NO, completionPolicy = _CBSocketClient.completionPolicy.directOnly, isUserBound = import_uicore_ts.NO, didSendFunction = import_uicore_ts.nil, completion = import_uicore_ts.nil, didObtainIdentifier) {
|
|
196
236
|
var _a;
|
|
197
237
|
if ((0, import_uicore_ts.IS_NIL)(message)) {
|
|
198
238
|
message = "";
|
|
199
239
|
}
|
|
200
240
|
if (this._isConnectionEstablished && !this._collectMessagesToSendLater) {
|
|
201
241
|
const identifier = (0, import_uicore_ts.MAKE_ID)();
|
|
242
|
+
didObtainIdentifier == null ? void 0 : didObtainIdentifier(identifier);
|
|
202
243
|
const messageObject = {
|
|
203
244
|
messageData: message,
|
|
204
245
|
identifier,
|
|
@@ -339,6 +380,10 @@ _CBSocketClient.disconnectionMessage = {
|
|
|
339
380
|
_isCBSocketErrorMessage: import_uicore_ts.YES,
|
|
340
381
|
messageData: "Server disconnected"
|
|
341
382
|
};
|
|
383
|
+
_CBSocketClient.timeoutMessage = {
|
|
384
|
+
_isCBSocketErrorMessage: import_uicore_ts.YES,
|
|
385
|
+
messageData: "Request timed out"
|
|
386
|
+
};
|
|
342
387
|
_CBSocketClient.completionPolicy = {
|
|
343
388
|
"all": "all",
|
|
344
389
|
"allDifferent": "allDifferent",
|