@azure/web-pubsub-client 1.0.3-alpha.20250619.1 → 1.0.3-alpha.20250730.1
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/dist/browser/errors/index.js +12 -0
- package/dist/browser/errors/index.js.map +1 -1
- package/dist/browser/protocols/jsonProtocolBase.js +9 -5
- package/dist/browser/protocols/jsonProtocolBase.js.map +1 -1
- package/dist/browser/protocols/webPubSubJsonProtocol.js +8 -10
- package/dist/browser/protocols/webPubSubJsonProtocol.js.map +1 -1
- package/dist/browser/protocols/webPubSubJsonReliableProtocol.js +8 -10
- package/dist/browser/protocols/webPubSubJsonReliableProtocol.js.map +1 -1
- package/dist/browser/webPubSubClient.js +57 -27
- package/dist/browser/webPubSubClient.js.map +1 -1
- package/dist/browser/websocket/websocketClient-browser.mjs.map +1 -1
- package/dist/browser/websocket/websocketClient.js +1 -0
- package/dist/commonjs/errors/index.js +12 -0
- package/dist/commonjs/errors/index.js.map +1 -1
- package/dist/commonjs/protocols/jsonProtocolBase.js +9 -5
- package/dist/commonjs/protocols/jsonProtocolBase.js.map +1 -1
- package/dist/commonjs/protocols/webPubSubJsonProtocol.js +8 -10
- package/dist/commonjs/protocols/webPubSubJsonProtocol.js.map +1 -1
- package/dist/commonjs/protocols/webPubSubJsonReliableProtocol.js +8 -10
- package/dist/commonjs/protocols/webPubSubJsonReliableProtocol.js.map +1 -1
- package/dist/commonjs/tsdoc-metadata.json +11 -11
- package/dist/commonjs/webPubSubClient.js +57 -27
- package/dist/commonjs/webPubSubClient.js.map +1 -1
- package/dist/commonjs/websocket/websocketClient.js +1 -0
- package/dist/commonjs/websocket/websocketClient.js.map +1 -1
- package/dist/esm/errors/index.js +12 -0
- package/dist/esm/errors/index.js.map +1 -1
- package/dist/esm/protocols/jsonProtocolBase.js +9 -5
- package/dist/esm/protocols/jsonProtocolBase.js.map +1 -1
- package/dist/esm/protocols/webPubSubJsonProtocol.js +8 -10
- package/dist/esm/protocols/webPubSubJsonProtocol.js.map +1 -1
- package/dist/esm/protocols/webPubSubJsonReliableProtocol.js +8 -10
- package/dist/esm/protocols/webPubSubJsonReliableProtocol.js.map +1 -1
- package/dist/esm/webPubSubClient.js +57 -27
- package/dist/esm/webPubSubClient.js.map +1 -1
- package/dist/esm/websocket/websocketClient.js +1 -0
- package/dist/esm/websocket/websocketClient.js.map +1 -1
- package/dist/react-native/errors/index.js +12 -0
- package/dist/react-native/errors/index.js.map +1 -1
- package/dist/react-native/protocols/jsonProtocolBase.js +9 -5
- package/dist/react-native/protocols/jsonProtocolBase.js.map +1 -1
- package/dist/react-native/protocols/webPubSubJsonProtocol.js +8 -10
- package/dist/react-native/protocols/webPubSubJsonProtocol.js.map +1 -1
- package/dist/react-native/protocols/webPubSubJsonReliableProtocol.js +8 -10
- package/dist/react-native/protocols/webPubSubJsonReliableProtocol.js.map +1 -1
- package/dist/react-native/webPubSubClient.js +57 -27
- package/dist/react-native/webPubSubClient.js.map +1 -1
- package/dist/react-native/websocket/websocketClient.js +1 -0
- package/dist/react-native/websocket/websocketClient.js.map +1 -1
- package/package.json +2 -2
|
@@ -4,6 +4,18 @@
|
|
|
4
4
|
* Error when sending message failed
|
|
5
5
|
*/
|
|
6
6
|
export class SendMessageError extends Error {
|
|
7
|
+
/**
|
|
8
|
+
* Error name
|
|
9
|
+
*/
|
|
10
|
+
name;
|
|
11
|
+
/**
|
|
12
|
+
* The ack id of the message
|
|
13
|
+
*/
|
|
14
|
+
ackId;
|
|
15
|
+
/**
|
|
16
|
+
* The error details from the service
|
|
17
|
+
*/
|
|
18
|
+
errorDetail;
|
|
7
19
|
/**
|
|
8
20
|
* Initialize a SendMessageError
|
|
9
21
|
* @param message - The error message
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/errors/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC;;GAEG;AACH,MAAM,OAAO,gBAAiB,SAAQ,KAAK;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/errors/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC;;GAEG;AACH,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IACzC;;OAEG;IACI,IAAI,CAAS;IACpB;;OAEG;IACI,KAAK,CAAU;IACtB;;OAEG;IACI,WAAW,CAAmB;IACrC;;;;OAIG;IACH,YAAY,OAAe,EAAE,OAAgC;QAC3D,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;QAC/B,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC3B,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IACzC,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AckMessageError } from \"../models/messages.js\";\n\n/**\n * Error when sending message failed\n */\nexport class SendMessageError extends Error {\n /**\n * Error name\n */\n public name: string;\n /**\n * The ack id of the message\n */\n public ackId?: number;\n /**\n * The error details from the service\n */\n public errorDetail?: AckMessageError;\n /**\n * Initialize a SendMessageError\n * @param message - The error message\n * @param ackMessage - The ack message\n */\n constructor(message: string, options: SendMessageErrorOptions) {\n super(message);\n this.name = \"SendMessageError\";\n this.ackId = options.ackId;\n this.errorDetail = options.errorDetail;\n }\n}\n\nexport interface SendMessageErrorOptions {\n /**\n * The ack id of the message\n */\n ackId?: number;\n /**\n * The error details from the service\n */\n errorDetail?: AckMessageError;\n}\n"]}
|
|
@@ -14,10 +14,10 @@ export function parseMessages(input) {
|
|
|
14
14
|
let returnMessage;
|
|
15
15
|
if (typedMessage.type === "system") {
|
|
16
16
|
if (typedMessage.event === "connected") {
|
|
17
|
-
returnMessage =
|
|
17
|
+
returnMessage = { ...parsedMessage, kind: "connected" };
|
|
18
18
|
}
|
|
19
19
|
else if (typedMessage.event === "disconnected") {
|
|
20
|
-
returnMessage =
|
|
20
|
+
returnMessage = { ...parsedMessage, kind: "disconnected" };
|
|
21
21
|
}
|
|
22
22
|
else {
|
|
23
23
|
// Forward compatible
|
|
@@ -30,14 +30,18 @@ export function parseMessages(input) {
|
|
|
30
30
|
if (data === null) {
|
|
31
31
|
return null;
|
|
32
32
|
}
|
|
33
|
-
returnMessage =
|
|
33
|
+
returnMessage = { ...parsedMessage, data: data, kind: "groupData" };
|
|
34
34
|
}
|
|
35
35
|
else if (typedMessage.from === "server") {
|
|
36
36
|
const data = parsePayload(parsedMessage.data, parsedMessage.dataType);
|
|
37
37
|
if (data === null) {
|
|
38
38
|
return null;
|
|
39
39
|
}
|
|
40
|
-
returnMessage =
|
|
40
|
+
returnMessage = {
|
|
41
|
+
...parsedMessage,
|
|
42
|
+
data: data,
|
|
43
|
+
kind: "serverData",
|
|
44
|
+
};
|
|
41
45
|
}
|
|
42
46
|
else {
|
|
43
47
|
// Forward compatible
|
|
@@ -45,7 +49,7 @@ export function parseMessages(input) {
|
|
|
45
49
|
}
|
|
46
50
|
}
|
|
47
51
|
else if (typedMessage.type === "ack") {
|
|
48
|
-
returnMessage =
|
|
52
|
+
returnMessage = { ...parsedMessage, kind: "ack" };
|
|
49
53
|
}
|
|
50
54
|
else {
|
|
51
55
|
// Forward compatible
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsonProtocolBase.js","sourceRoot":"","sources":["../../../src/protocols/jsonProtocolBase.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAYlC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,MAAM,UAAU,aAAa,CAAC,KAAa;IACzC,2HAA2H;IAC3H,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;IAC7E,CAAC;IAED,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI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AE,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC,UAAU,CAAgB,CAAC;IAC1F,CAAC;SAAM,CAAC;QACN,qBAAqB;QACrB,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n AckMessage,\n ConnectedMessage,\n DisconnectedMessage,\n GroupDataMessage,\n ServerDataMessage,\n WebPubSubDataType,\n WebPubSubMessage,\n} from \"../models/messages.js\";\nimport type { JSONTypes } from \"../webPubSubClient.js\";\nimport { Buffer } from \"buffer\";\n\nexport function parseMessages(input: string): WebPubSubMessage | null {\n // The interface does allow \"ArrayBuffer\" to be passed in, but this implementation does not. So let's throw a useful error.\n if (typeof input !== \"string\") {\n throw new Error(\"Invalid input for JSON hub protocol. Expected a string.\");\n }\n\n if (!input) {\n throw new Error(\"No input\");\n }\n\n const parsedMessage = JSON.parse(input);\n const typedMessage = parsedMessage as { type: string; from: string; event: string };\n let returnMessage: WebPubSubMessage;\n\n if (typedMessage.type === \"system\") {\n if (typedMessage.event === \"connected\") {\n returnMessage = { ...parsedMessage, kind: \"connected\" } as ConnectedMessage;\n } else if (typedMessage.event === \"disconnected\") {\n returnMessage = { ...parsedMessage, kind: \"disconnected\" } as DisconnectedMessage;\n } else {\n // Forward compatible\n return null;\n }\n } else if (typedMessage.type === \"message\") {\n if (typedMessage.from === \"group\") {\n const data = parsePayload(parsedMessage.data, parsedMessage.dataType as WebPubSubDataType);\n if (data === null) {\n return null;\n }\n returnMessage = { ...parsedMessage, data: data, kind: \"groupData\" } as GroupDataMessage;\n } else if (typedMessage.from === \"server\") {\n const data = parsePayload(parsedMessage.data, parsedMessage.dataType as WebPubSubDataType);\n if (data === null) {\n return null;\n }\n returnMessage = {\n ...parsedMessage,\n data: data,\n kind: \"serverData\",\n } as ServerDataMessage;\n } else {\n // Forward compatible\n return null;\n }\n } else if (typedMessage.type === \"ack\") {\n returnMessage = { ...parsedMessage, kind: \"ack\" } as AckMessage;\n } else {\n // Forward compatible\n return null;\n }\n return returnMessage;\n}\n\nexport function writeMessage(message: WebPubSubMessage): string {\n let data: any;\n switch (message.kind) {\n case \"joinGroup\": {\n data = { type: \"joinGroup\", group: message.group, ackId: message.ackId } as JoinGroupData;\n break;\n }\n case \"leaveGroup\": {\n data = { type: \"leaveGroup\", group: message.group, ackId: message.ackId } as LeaveGroupData;\n break;\n }\n case \"sendEvent\": {\n data = {\n type: \"event\",\n event: message.event,\n ackId: message.ackId,\n dataType: message.dataType,\n data: getPayload(message.data, message.dataType),\n } as SendEventData;\n break;\n }\n case \"sendToGroup\": {\n data = {\n type: \"sendToGroup\",\n group: message.group,\n ackId: message.ackId,\n dataType: message.dataType,\n data: getPayload(message.data, message.dataType),\n noEcho: message.noEcho,\n } as SendToGroupData;\n break;\n }\n case \"sequenceAck\": {\n data = { type: \"sequenceAck\", sequenceId: message.sequenceId } as SequenceAckData;\n break;\n }\n default: {\n throw new Error(`Unsupported type: ${message.kind}`);\n }\n }\n\n return JSON.stringify(data);\n}\n\ninterface JoinGroupData {\n readonly type: \"joinGroup\";\n group: string;\n ackId?: number;\n}\n\ninterface LeaveGroupData {\n readonly type: \"leaveGroup\";\n group: string;\n ackId?: number;\n}\n\ninterface SendToGroupData {\n readonly type: \"sendToGroup\";\n group: string;\n ackId?: number;\n dataType: WebPubSubDataType;\n data: any;\n noEcho: boolean;\n}\n\ninterface SendEventData {\n readonly type: \"event\";\n ackId?: number;\n dataType: WebPubSubDataType;\n data: any;\n event: string;\n}\n\ninterface SequenceAckData {\n readonly type: \"sequenceAck\";\n sequenceId: number;\n}\n\nfunction getPayload(data: JSONTypes | ArrayBuffer, dataType: WebPubSubDataType): any {\n switch (dataType) {\n case \"text\": {\n if (typeof data !== \"string\") {\n throw new TypeError(\"Message must be a string.\");\n }\n return data;\n }\n case \"json\": {\n return data;\n }\n case \"binary\":\n case \"protobuf\": {\n if (data instanceof ArrayBuffer) {\n return Buffer.from(data).toString(\"base64\");\n }\n throw new TypeError(\"Message must be a ArrayBuffer\");\n }\n }\n}\n\nfunction parsePayload(data: any, dataType: string): JSONTypes | ArrayBuffer | null {\n if (dataType === \"text\") {\n if (typeof data !== \"string\") {\n throw new TypeError(\"Message must be a string when dataType is text\");\n }\n return data as string;\n } else if (dataType === \"json\") {\n return data as JSONTypes;\n } else if (dataType === \"binary\" || dataType === \"protobuf\") {\n const buf = Buffer.from(data as string, \"base64\");\n return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength) as ArrayBuffer;\n } else {\n // Forward compatible\n return null;\n }\n}\n"]}
|
|
@@ -5,16 +5,14 @@ import * as base from "./jsonProtocolBase.js";
|
|
|
5
5
|
* The "json.webpubsub.azure.v1" protocol
|
|
6
6
|
*/
|
|
7
7
|
export class WebPubSubJsonProtocolImpl {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
this.name = "json.webpubsub.azure.v1";
|
|
17
|
-
}
|
|
8
|
+
/**
|
|
9
|
+
* True if the protocol supports reliable features
|
|
10
|
+
*/
|
|
11
|
+
isReliableSubProtocol = false;
|
|
12
|
+
/**
|
|
13
|
+
* The name of subprotocol. Name will be used in websocket subprotocol
|
|
14
|
+
*/
|
|
15
|
+
name = "json.webpubsub.azure.v1";
|
|
18
16
|
/**
|
|
19
17
|
* Creates WebPubSubMessage objects from the specified serialized representation.
|
|
20
18
|
* @param input - The serialized representation
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webPubSubJsonProtocol.js","sourceRoot":"","sources":["../../../src/protocols/webPubSubJsonProtocol.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,KAAK,IAAI,MAAM,uBAAuB,CAAC;AAE9C;;GAEG;AACH,MAAM,OAAO,yBAAyB;
|
|
1
|
+
{"version":3,"file":"webPubSubJsonProtocol.js","sourceRoot":"","sources":["../../../src/protocols/webPubSubJsonProtocol.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,KAAK,IAAI,MAAM,uBAAuB,CAAC;AAE9C;;GAEG;AACH,MAAM,OAAO,yBAAyB;IACpC;;OAEG;IACa,qBAAqB,GAAG,KAAK,CAAC;IAE9C;;OAEG;IACa,IAAI,GAAG,yBAAyB,CAAC;IAEjD;;;OAGG;IACI,aAAa,CAAC,KAAa;QAChC,OAAO,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC;IAED;;;OAGG;IACI,YAAY,CAAC,OAAyB;QAC3C,OAAO,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IACpC,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { WebPubSubClientProtocol } from \"./index.js\";\nimport type { WebPubSubMessage } from \"../models/messages.js\";\nimport * as base from \"./jsonProtocolBase.js\";\n\n/**\n * The \"json.webpubsub.azure.v1\" protocol\n */\nexport class WebPubSubJsonProtocolImpl implements WebPubSubClientProtocol {\n /**\n * True if the protocol supports reliable features\n */\n public readonly isReliableSubProtocol = false;\n\n /**\n * The name of subprotocol. Name will be used in websocket subprotocol\n */\n public readonly name = \"json.webpubsub.azure.v1\";\n\n /**\n * Creates WebPubSubMessage objects from the specified serialized representation.\n * @param input - The serialized representation\n */\n public parseMessages(input: string): WebPubSubMessage | null {\n return base.parseMessages(input);\n }\n\n /**\n * Write WebPubSubMessage to string\n * @param message - The message to be written\n */\n public writeMessage(message: WebPubSubMessage): string {\n return base.writeMessage(message);\n }\n}\n"]}
|
|
@@ -5,16 +5,14 @@ import * as base from "./jsonProtocolBase.js";
|
|
|
5
5
|
* The "json.reliable.webpubsub.azure.v1" protocol
|
|
6
6
|
*/
|
|
7
7
|
export class WebPubSubJsonReliableProtocolImpl {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
this.name = "json.reliable.webpubsub.azure.v1";
|
|
17
|
-
}
|
|
8
|
+
/**
|
|
9
|
+
* True if the protocol supports reliable features
|
|
10
|
+
*/
|
|
11
|
+
isReliableSubProtocol = true;
|
|
12
|
+
/**
|
|
13
|
+
* The name of subprotocol. Name will be used in websocket subprotocol
|
|
14
|
+
*/
|
|
15
|
+
name = "json.reliable.webpubsub.azure.v1";
|
|
18
16
|
/**
|
|
19
17
|
* Creates WebPubSubMessage objects from the specified serialized representation.
|
|
20
18
|
* @param input - The serialized representation
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webPubSubJsonReliableProtocol.js","sourceRoot":"","sources":["../../../src/protocols/webPubSubJsonReliableProtocol.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,KAAK,IAAI,MAAM,uBAAuB,CAAC;AAE9C;;GAEG;AACH,MAAM,OAAO,iCAAiC;
|
|
1
|
+
{"version":3,"file":"webPubSubJsonReliableProtocol.js","sourceRoot":"","sources":["../../../src/protocols/webPubSubJsonReliableProtocol.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,KAAK,IAAI,MAAM,uBAAuB,CAAC;AAE9C;;GAEG;AACH,MAAM,OAAO,iCAAiC;IAC5C;;OAEG;IACa,qBAAqB,GAAG,IAAI,CAAC;IAE7C;;OAEG;IACa,IAAI,GAAG,kCAAkC,CAAC;IAE1D;;;OAGG;IACI,aAAa,CAAC,KAAa;QAChC,OAAO,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC;IAED;;;OAGG;IACI,YAAY,CAAC,OAAyB;QAC3C,OAAO,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IACpC,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { WebPubSubClientProtocol } from \"./index.js\";\nimport type { WebPubSubMessage } from \"../models/messages.js\";\nimport * as base from \"./jsonProtocolBase.js\";\n\n/**\n * The \"json.reliable.webpubsub.azure.v1\" protocol\n */\nexport class WebPubSubJsonReliableProtocolImpl implements WebPubSubClientProtocol {\n /**\n * True if the protocol supports reliable features\n */\n public readonly isReliableSubProtocol = true;\n\n /**\n * The name of subprotocol. Name will be used in websocket subprotocol\n */\n public readonly name = \"json.reliable.webpubsub.azure.v1\";\n\n /**\n * Creates WebPubSubMessage objects from the specified serialized representation.\n * @param input - The serialized representation\n */\n public parseMessages(input: string): WebPubSubMessage | null {\n return base.parseMessages(input);\n }\n\n /**\n * Write WebPubSubMessage to string\n * @param message - The message to be written\n */\n public writeMessage(message: WebPubSubMessage): string {\n return base.writeMessage(message);\n }\n}\n"]}
|
|
@@ -19,16 +19,35 @@ var WebPubSubClientState;
|
|
|
19
19
|
* The WebPubSub client
|
|
20
20
|
*/
|
|
21
21
|
export class WebPubSubClient {
|
|
22
|
+
_protocol;
|
|
23
|
+
_credential;
|
|
24
|
+
_options;
|
|
25
|
+
_groupMap;
|
|
26
|
+
_ackMap;
|
|
27
|
+
_sequenceId;
|
|
28
|
+
_messageRetryPolicy;
|
|
29
|
+
_reconnectRetryPolicy;
|
|
30
|
+
_quickSequenceAckDiff = 300;
|
|
31
|
+
_activeTimeoutInMs = 20000;
|
|
32
|
+
_emitter = new EventEmitter();
|
|
33
|
+
_state;
|
|
34
|
+
_isStopping = false;
|
|
35
|
+
_ackId;
|
|
36
|
+
_activeKeepaliveTask;
|
|
37
|
+
// connection lifetime
|
|
38
|
+
_wsClient;
|
|
39
|
+
_uri;
|
|
40
|
+
_lastCloseEvent;
|
|
41
|
+
_lastDisconnectedMessage;
|
|
42
|
+
_connectionId;
|
|
43
|
+
_reconnectionToken;
|
|
44
|
+
_isInitialConnected = false;
|
|
45
|
+
_sequenceAckTask;
|
|
22
46
|
nextAckId() {
|
|
23
47
|
this._ackId = this._ackId + 1;
|
|
24
48
|
return this._ackId;
|
|
25
49
|
}
|
|
26
50
|
constructor(credential, options) {
|
|
27
|
-
this._quickSequenceAckDiff = 300;
|
|
28
|
-
this._activeTimeoutInMs = 20000;
|
|
29
|
-
this._emitter = new EventEmitter();
|
|
30
|
-
this._isStopping = false;
|
|
31
|
-
this._isInitialConnected = false;
|
|
32
51
|
if (typeof credential === "string") {
|
|
33
52
|
this._credential = { getClientAccessUrl: credential };
|
|
34
53
|
}
|
|
@@ -156,11 +175,10 @@ export class WebPubSubClient {
|
|
|
156
175
|
* @param abortSignal - The abort signal
|
|
157
176
|
*/
|
|
158
177
|
async sendEvent(eventName, content, dataType, options) {
|
|
159
|
-
return this._operationExecuteWithRetry(() => this._sendEventAttempt(eventName, content, dataType, options), options
|
|
178
|
+
return this._operationExecuteWithRetry(() => this._sendEventAttempt(eventName, content, dataType, options), options?.abortSignal);
|
|
160
179
|
}
|
|
161
180
|
async _sendEventAttempt(eventName, content, dataType, options) {
|
|
162
|
-
|
|
163
|
-
const fireAndForget = (_a = options === null || options === void 0 ? void 0 : options.fireAndForget) !== null && _a !== void 0 ? _a : false;
|
|
181
|
+
const fireAndForget = options?.fireAndForget ?? false;
|
|
164
182
|
if (!fireAndForget) {
|
|
165
183
|
return this._sendMessageWithAckId((id) => {
|
|
166
184
|
return {
|
|
@@ -170,7 +188,7 @@ export class WebPubSubClient {
|
|
|
170
188
|
ackId: id,
|
|
171
189
|
event: eventName,
|
|
172
190
|
};
|
|
173
|
-
}, options
|
|
191
|
+
}, options?.ackId, options?.abortSignal);
|
|
174
192
|
}
|
|
175
193
|
const message = {
|
|
176
194
|
kind: "sendEvent",
|
|
@@ -178,7 +196,7 @@ export class WebPubSubClient {
|
|
|
178
196
|
data: content,
|
|
179
197
|
event: eventName,
|
|
180
198
|
};
|
|
181
|
-
await this._sendMessage(message, options
|
|
199
|
+
await this._sendMessage(message, options?.abortSignal);
|
|
182
200
|
return { isDuplicated: false };
|
|
183
201
|
}
|
|
184
202
|
/**
|
|
@@ -187,7 +205,7 @@ export class WebPubSubClient {
|
|
|
187
205
|
* @param options - The join group options
|
|
188
206
|
*/
|
|
189
207
|
async joinGroup(groupName, options) {
|
|
190
|
-
return this._operationExecuteWithRetry(() => this._joinGroupAttempt(groupName, options), options
|
|
208
|
+
return this._operationExecuteWithRetry(() => this._joinGroupAttempt(groupName, options), options?.abortSignal);
|
|
191
209
|
}
|
|
192
210
|
async _joinGroupAttempt(groupName, options) {
|
|
193
211
|
const group = this._getOrAddGroup(groupName);
|
|
@@ -202,7 +220,7 @@ export class WebPubSubClient {
|
|
|
202
220
|
ackId: id,
|
|
203
221
|
kind: "joinGroup",
|
|
204
222
|
};
|
|
205
|
-
}, options
|
|
223
|
+
}, options?.ackId, options?.abortSignal);
|
|
206
224
|
}
|
|
207
225
|
/**
|
|
208
226
|
* Leave the client from group
|
|
@@ -211,7 +229,7 @@ export class WebPubSubClient {
|
|
|
211
229
|
* @param abortSignal - The abort signal
|
|
212
230
|
*/
|
|
213
231
|
async leaveGroup(groupName, options) {
|
|
214
|
-
return this._operationExecuteWithRetry(() => this._leaveGroupAttempt(groupName, options), options
|
|
232
|
+
return this._operationExecuteWithRetry(() => this._leaveGroupAttempt(groupName, options), options?.abortSignal);
|
|
215
233
|
}
|
|
216
234
|
async _leaveGroupAttempt(groupName, options) {
|
|
217
235
|
const group = this._getOrAddGroup(groupName);
|
|
@@ -221,7 +239,7 @@ export class WebPubSubClient {
|
|
|
221
239
|
ackId: id,
|
|
222
240
|
kind: "leaveGroup",
|
|
223
241
|
};
|
|
224
|
-
}, options
|
|
242
|
+
}, options?.ackId, options?.abortSignal);
|
|
225
243
|
group.isJoined = false;
|
|
226
244
|
return result;
|
|
227
245
|
}
|
|
@@ -234,12 +252,11 @@ export class WebPubSubClient {
|
|
|
234
252
|
* @param abortSignal - The abort signal
|
|
235
253
|
*/
|
|
236
254
|
async sendToGroup(groupName, content, dataType, options) {
|
|
237
|
-
return this._operationExecuteWithRetry(() => this._sendToGroupAttempt(groupName, content, dataType, options), options
|
|
255
|
+
return this._operationExecuteWithRetry(() => this._sendToGroupAttempt(groupName, content, dataType, options), options?.abortSignal);
|
|
238
256
|
}
|
|
239
257
|
async _sendToGroupAttempt(groupName, content, dataType, options) {
|
|
240
|
-
|
|
241
|
-
const
|
|
242
|
-
const noEcho = (_b = options === null || options === void 0 ? void 0 : options.noEcho) !== null && _b !== void 0 ? _b : false;
|
|
258
|
+
const fireAndForget = options?.fireAndForget ?? false;
|
|
259
|
+
const noEcho = options?.noEcho ?? false;
|
|
243
260
|
if (!fireAndForget) {
|
|
244
261
|
return this._sendMessageWithAckId((id) => {
|
|
245
262
|
return {
|
|
@@ -250,7 +267,7 @@ export class WebPubSubClient {
|
|
|
250
267
|
ackId: id,
|
|
251
268
|
noEcho: noEcho,
|
|
252
269
|
};
|
|
253
|
-
}, options
|
|
270
|
+
}, options?.ackId, options?.abortSignal);
|
|
254
271
|
}
|
|
255
272
|
const message = {
|
|
256
273
|
kind: "sendToGroup",
|
|
@@ -259,7 +276,7 @@ export class WebPubSubClient {
|
|
|
259
276
|
data: content,
|
|
260
277
|
noEcho: noEcho,
|
|
261
278
|
};
|
|
262
|
-
await this._sendMessage(message, options
|
|
279
|
+
await this._sendMessage(message, options?.abortSignal);
|
|
263
280
|
return { isDuplicated: false };
|
|
264
281
|
}
|
|
265
282
|
_getWebSocketClientFactory() {
|
|
@@ -279,7 +296,7 @@ export class WebPubSubClient {
|
|
|
279
296
|
try {
|
|
280
297
|
await this._sendMessage(message);
|
|
281
298
|
}
|
|
282
|
-
catch
|
|
299
|
+
catch {
|
|
283
300
|
this._sequenceId.tryUpdate(seqId); // If sending failed, mark it as updated so that it can be sent again.
|
|
284
301
|
}
|
|
285
302
|
}
|
|
@@ -297,7 +314,7 @@ export class WebPubSubClient {
|
|
|
297
314
|
try {
|
|
298
315
|
client.close();
|
|
299
316
|
}
|
|
300
|
-
catch
|
|
317
|
+
catch {
|
|
301
318
|
/** empty */
|
|
302
319
|
}
|
|
303
320
|
reject(new Error(`The client is stopped`));
|
|
@@ -599,7 +616,7 @@ export class WebPubSubClient {
|
|
|
599
616
|
recovered = true;
|
|
600
617
|
return;
|
|
601
618
|
}
|
|
602
|
-
catch
|
|
619
|
+
catch {
|
|
603
620
|
await delay(1000);
|
|
604
621
|
}
|
|
605
622
|
}
|
|
@@ -728,7 +745,7 @@ export class WebPubSubClient {
|
|
|
728
745
|
throw err;
|
|
729
746
|
}
|
|
730
747
|
await delay(delayInMs);
|
|
731
|
-
if (signal
|
|
748
|
+
if (signal?.aborted) {
|
|
732
749
|
throw err;
|
|
733
750
|
}
|
|
734
751
|
}
|
|
@@ -736,6 +753,8 @@ export class WebPubSubClient {
|
|
|
736
753
|
}
|
|
737
754
|
}
|
|
738
755
|
class RetryPolicy {
|
|
756
|
+
_retryOptions;
|
|
757
|
+
_maxRetriesToGetMaxDelay;
|
|
739
758
|
constructor(retryOptions) {
|
|
740
759
|
this._retryOptions = retryOptions;
|
|
741
760
|
this._maxRetriesToGetMaxDelay = Math.ceil(Math.log2(this._retryOptions.maxRetryDelayInMs) -
|
|
@@ -765,12 +784,16 @@ class RetryPolicy {
|
|
|
765
784
|
}
|
|
766
785
|
}
|
|
767
786
|
class WebPubSubGroup {
|
|
787
|
+
name;
|
|
788
|
+
isJoined = false;
|
|
768
789
|
constructor(name) {
|
|
769
|
-
this.isJoined = false;
|
|
770
790
|
this.name = name;
|
|
771
791
|
}
|
|
772
792
|
}
|
|
773
793
|
class AckEntity {
|
|
794
|
+
_promise;
|
|
795
|
+
_resolve;
|
|
796
|
+
_reject;
|
|
774
797
|
constructor(ackId) {
|
|
775
798
|
this._promise = new Promise((resolve, reject) => {
|
|
776
799
|
this._resolve = resolve;
|
|
@@ -778,6 +801,7 @@ class AckEntity {
|
|
|
778
801
|
});
|
|
779
802
|
this.ackId = ackId;
|
|
780
803
|
}
|
|
804
|
+
ackId;
|
|
781
805
|
promise() {
|
|
782
806
|
return this._promise;
|
|
783
807
|
}
|
|
@@ -789,6 +813,8 @@ class AckEntity {
|
|
|
789
813
|
}
|
|
790
814
|
}
|
|
791
815
|
class SequenceId {
|
|
816
|
+
_sequenceId;
|
|
817
|
+
_isUpdate;
|
|
792
818
|
constructor() {
|
|
793
819
|
this._sequenceId = 0;
|
|
794
820
|
this._isUpdate = false;
|
|
@@ -815,6 +841,10 @@ class SequenceId {
|
|
|
815
841
|
}
|
|
816
842
|
}
|
|
817
843
|
class AbortableTask {
|
|
844
|
+
_func;
|
|
845
|
+
_abortController;
|
|
846
|
+
_interval;
|
|
847
|
+
_obj;
|
|
818
848
|
constructor(func, interval, obj) {
|
|
819
849
|
this._func = func;
|
|
820
850
|
this._abortController = new AbortController();
|
|
@@ -826,7 +856,7 @@ class AbortableTask {
|
|
|
826
856
|
try {
|
|
827
857
|
this._abortController.abort();
|
|
828
858
|
}
|
|
829
|
-
catch
|
|
859
|
+
catch {
|
|
830
860
|
/** empty */
|
|
831
861
|
}
|
|
832
862
|
}
|
|
@@ -836,7 +866,7 @@ class AbortableTask {
|
|
|
836
866
|
try {
|
|
837
867
|
await this._func(this._obj);
|
|
838
868
|
}
|
|
839
|
-
catch
|
|
869
|
+
catch {
|
|
840
870
|
/** empty */
|
|
841
871
|
}
|
|
842
872
|
finally {
|