@inditextech/weave-store-azure-web-pubsub 3.3.1-SNAPSHOT.74.1 β 3.3.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/client.d.ts +1 -0
- package/dist/client.js +18 -5
- package/dist/server.d.ts +9 -0
- package/dist/server.js +32 -2
- package/package.json +3 -3
package/dist/client.d.ts
CHANGED
|
@@ -274,6 +274,7 @@ declare class WeaveStoreAzureWebPubSubSyncClient extends Emittery {
|
|
|
274
274
|
createWebSocket(connectionUrlExtraParams?: Record<string, string>): Promise<ReconnectingWebSocket>;
|
|
275
275
|
setAndEmitStatusInfo(status: WeaveStoreAzureWebPubSubSyncClientConnectionStatus): void;
|
|
276
276
|
private setupCheckHeartbeat;
|
|
277
|
+
private destroyCheckHeartbeat;
|
|
277
278
|
connect(connectionUrlExtraParams?: Record<string, string>): Promise<void>;
|
|
278
279
|
}
|
|
279
280
|
|
package/dist/client.js
CHANGED
|
@@ -3918,7 +3918,9 @@ var WeaveStoreAzureWebPubSubSyncClient = class extends Emittery {
|
|
|
3918
3918
|
connectionURL.searchParams.append(key, connectionUrlExtraParams[key]);
|
|
3919
3919
|
}
|
|
3920
3920
|
}
|
|
3921
|
-
const
|
|
3921
|
+
const controller = new AbortController();
|
|
3922
|
+
const timeout = setTimeout(() => controller.abort(), 5e3);
|
|
3923
|
+
const res = await this._fetchClient(connectionURL.toString(), { signal: controller.signal }).finally(() => clearTimeout(timeout));
|
|
3922
3924
|
if (res.ok) {
|
|
3923
3925
|
const data = await res.json();
|
|
3924
3926
|
return data.url;
|
|
@@ -3946,6 +3948,7 @@ var WeaveStoreAzureWebPubSubSyncClient = class extends Emittery {
|
|
|
3946
3948
|
error
|
|
3947
3949
|
});
|
|
3948
3950
|
}
|
|
3951
|
+
console.log("π [Azure Web PubSub] connecting", url);
|
|
3949
3952
|
return url;
|
|
3950
3953
|
}, AzureWebPubSubJsonProtocol);
|
|
3951
3954
|
websocket.binaryType = "arraybuffer";
|
|
@@ -3954,7 +3957,8 @@ var WeaveStoreAzureWebPubSubSyncClient = class extends Emittery {
|
|
|
3954
3957
|
this._initialized = false;
|
|
3955
3958
|
this.synced = false;
|
|
3956
3959
|
websocket.addEventListener("error", (e) => {
|
|
3957
|
-
console.error("
|
|
3960
|
+
console.error("β client error", e);
|
|
3961
|
+
this.destroyCheckHeartbeat();
|
|
3958
3962
|
if (this._initialized && websocket.retryCount > 0) {
|
|
3959
3963
|
this.setAndEmitStatusInfo(WEAVE_STORE_AZURE_WEB_PUBSUB_CONNECTION_STATUS.CONNECTING);
|
|
3960
3964
|
return;
|
|
@@ -3967,6 +3971,7 @@ var WeaveStoreAzureWebPubSubSyncClient = class extends Emittery {
|
|
|
3967
3971
|
if (message.type === MessageType.System) return;
|
|
3968
3972
|
const messageData = message.data;
|
|
3969
3973
|
if (messageData.type === "heartbeat") {
|
|
3974
|
+
console.log("[Azure Web PubSub] received heartbeat, updating last heartbeat time.");
|
|
3970
3975
|
this._lastHeartbeatTime = Date.now();
|
|
3971
3976
|
return;
|
|
3972
3977
|
}
|
|
@@ -3985,8 +3990,9 @@ var WeaveStoreAzureWebPubSubSyncClient = class extends Emittery {
|
|
|
3985
3990
|
const encoder = readMessage(this, buffer, true, messageData.f);
|
|
3986
3991
|
if (length(encoder) > 1) sendToControlGroup(this, this.topic, MessageDataType.Sync, toUint8Array(encoder));
|
|
3987
3992
|
};
|
|
3988
|
-
websocket.onclose = () => {
|
|
3989
|
-
|
|
3993
|
+
websocket.onclose = (e) => {
|
|
3994
|
+
console.log(`π« [Azure Web PubSub] closed, code: ${e.code}`);
|
|
3995
|
+
this.destroyCheckHeartbeat();
|
|
3990
3996
|
if ((this._ws?.retryCount ?? 0) > 0) this.setAndEmitStatusInfo(WEAVE_STORE_AZURE_WEB_PUBSUB_CONNECTION_STATUS.CONNECTING);
|
|
3991
3997
|
else this.setAndEmitStatusInfo(WEAVE_STORE_AZURE_WEB_PUBSUB_CONNECTION_STATUS.DISCONNECTED);
|
|
3992
3998
|
if (this._wsConnected) {
|
|
@@ -4000,8 +4006,11 @@ var WeaveStoreAzureWebPubSubSyncClient = class extends Emittery {
|
|
|
4000
4006
|
this._wsConnected = true;
|
|
4001
4007
|
this._initialized = true;
|
|
4002
4008
|
this._connectionRetries = this._connectionRetries++;
|
|
4009
|
+
console.log("β
[Azure Web PubSub] connected");
|
|
4003
4010
|
this.setupCheckHeartbeat();
|
|
4011
|
+
console.log(`π [Azure Web PubSub] join room <${this.topic}>`);
|
|
4004
4012
|
joinGroup(this, this.topic);
|
|
4013
|
+
console.log(`β
[Azure Web PubSub] room <${this.topic}> joined`);
|
|
4005
4014
|
const encoder = createEncoder();
|
|
4006
4015
|
writeVarUint(encoder, messageSyncStep1);
|
|
4007
4016
|
writeSyncStep1(encoder, this.doc);
|
|
@@ -4033,11 +4042,16 @@ var WeaveStoreAzureWebPubSubSyncClient = class extends Emittery {
|
|
|
4033
4042
|
this._checkHeartbeatId = setInterval(() => {
|
|
4034
4043
|
const now = Date.now();
|
|
4035
4044
|
if (now - this._lastHeartbeatTime > this._synClientOptions.heartbeat.checkWindowTimeMs) {
|
|
4045
|
+
console.log(`[Azure Web PubSub] heartbeat not received in ${this._synClientOptions.heartbeat.checkWindowTimeMs}ms window, handling it...`);
|
|
4036
4046
|
this.disconnect();
|
|
4037
4047
|
this.createWebSocket();
|
|
4038
4048
|
}
|
|
4039
4049
|
}, this._synClientOptions.heartbeat.checkIntervalMs);
|
|
4040
4050
|
}
|
|
4051
|
+
destroyCheckHeartbeat() {
|
|
4052
|
+
this._lastHeartbeatTime = 0;
|
|
4053
|
+
if (this._checkHeartbeatId) clearInterval(this._checkHeartbeatId);
|
|
4054
|
+
}
|
|
4041
4055
|
async connect(connectionUrlExtraParams) {
|
|
4042
4056
|
if (this._wsConnected || this._ws) return;
|
|
4043
4057
|
await this.createWebSocket(connectionUrlExtraParams);
|
|
@@ -4153,7 +4167,6 @@ var WeaveStoreAzureWebPubsub = class extends WeaveStore {
|
|
|
4153
4167
|
});
|
|
4154
4168
|
this.provider.on("error", () => {
|
|
4155
4169
|
this.handleConnectionStatusChange(WEAVE_STORE_CONNECTION_STATUS.DISCONNECTED);
|
|
4156
|
-
this.disconnect();
|
|
4157
4170
|
});
|
|
4158
4171
|
this.provider.on("status", (status) => {
|
|
4159
4172
|
this.handleConnectionStatusChange(status);
|
package/dist/server.d.ts
CHANGED
|
@@ -105,6 +105,7 @@ declare class WeaveStoreAzureWebPubSubSyncClient extends Emittery {
|
|
|
105
105
|
createWebSocket(connectionUrlExtraParams?: Record<string, string>): Promise<ReconnectingWebSocket>;
|
|
106
106
|
setAndEmitStatusInfo(status: WeaveStoreAzureWebPubSubSyncClientConnectionStatus): void;
|
|
107
107
|
private setupCheckHeartbeat;
|
|
108
|
+
private destroyCheckHeartbeat;
|
|
108
109
|
connect(connectionUrlExtraParams?: Record<string, string>): Promise<void>;
|
|
109
110
|
}
|
|
110
111
|
|
|
@@ -1039,6 +1040,7 @@ declare class WeaveStoreAzureWebPubSubSyncHost {
|
|
|
1039
1040
|
private _chunkedMessages;
|
|
1040
1041
|
private readonly _syncHostOptions;
|
|
1041
1042
|
private _heartbeatIntervalId;
|
|
1043
|
+
private _reconnectionTimeoutId;
|
|
1042
1044
|
private _resyncAttempt;
|
|
1043
1045
|
private _resyncIntervalId;
|
|
1044
1046
|
private _updateHandler;
|
|
@@ -1050,6 +1052,7 @@ declare class WeaveStoreAzureWebPubSubSyncHost {
|
|
|
1050
1052
|
createWebSocket(): Promise<void>;
|
|
1051
1053
|
start(): Promise<void>;
|
|
1052
1054
|
isConnected(): boolean;
|
|
1055
|
+
isReconnecting(): boolean;
|
|
1053
1056
|
stop(): Promise<void>;
|
|
1054
1057
|
simulateWebsocketError(): void;
|
|
1055
1058
|
private safeSend;
|
|
@@ -1089,6 +1092,9 @@ declare class WeaveAzureWebPubsubSyncHandler extends WebPubSubEventHandler {
|
|
|
1089
1092
|
getRoomSyncHost(roomId: string): WeaveStoreAzureWebPubSubSyncHost | undefined;
|
|
1090
1093
|
getRoomDocument(roomId: string): Promise<Y.Doc>;
|
|
1091
1094
|
clientConnect(roomId: string, connectionOptions?: WeaveStoreAzureWebPubSubSyncHostClientConnectOptions): Promise<string>;
|
|
1095
|
+
clientDisconnect(roomId: string): Promise<void>;
|
|
1096
|
+
clientTransportConnect(roomId: string): Promise<void>;
|
|
1097
|
+
clientTransportDisconnect(roomId: string): void;
|
|
1092
1098
|
}
|
|
1093
1099
|
|
|
1094
1100
|
//#endregion
|
|
@@ -1122,6 +1128,9 @@ declare class WeaveAzureWebPubsubServer extends Emittery {
|
|
|
1122
1128
|
removeEventListener<T>(event: string, callback: (payload: T) => void): void;
|
|
1123
1129
|
getRoomDocument(roomId: string): Promise<Y.Doc>;
|
|
1124
1130
|
clientConnect(roomId: string, connectionOptions?: WeaveStoreAzureWebPubSubSyncHostClientConnectOptions): Promise<string | null>;
|
|
1131
|
+
clientDisconnect(roomId: string): Promise<void>;
|
|
1132
|
+
clientTransportConnect(roomId: string): Promise<void>;
|
|
1133
|
+
clientTransportDisconnect(roomId: string): void;
|
|
1125
1134
|
}
|
|
1126
1135
|
|
|
1127
1136
|
//#endregion
|
package/dist/server.js
CHANGED
|
@@ -22723,6 +22723,7 @@ var WeaveStoreAzureWebPubSubSyncHost = class {
|
|
|
22723
22723
|
this._client = client;
|
|
22724
22724
|
this._chunkedMessages = new Map();
|
|
22725
22725
|
this._heartbeatIntervalId = null;
|
|
22726
|
+
this._reconnectionTimeoutId = null;
|
|
22726
22727
|
this._conn = null;
|
|
22727
22728
|
this._awareness = new Awareness(this.doc);
|
|
22728
22729
|
this._awarenessUpdateHandler = ({ added, updated, removed }, origin) => {
|
|
@@ -22850,13 +22851,13 @@ var WeaveStoreAzureWebPubSubSyncHost = class {
|
|
|
22850
22851
|
if (this._forceClose) return;
|
|
22851
22852
|
else {
|
|
22852
22853
|
this._reconnectAttempts++;
|
|
22853
|
-
const timeoutMs = 1e3 * Math.pow(1.5, this._reconnectAttempts - 1);
|
|
22854
|
+
const timeoutMs = Math.round(1e3 * Math.pow(1.5, this._reconnectAttempts - 1));
|
|
22854
22855
|
this.server.emitEvent("onWsReconnect", {
|
|
22855
22856
|
group: `${group}.host`,
|
|
22856
22857
|
connectionAttempt: this._reconnectAttempts,
|
|
22857
22858
|
timeoutMs
|
|
22858
22859
|
});
|
|
22859
|
-
setTimeout(() => {
|
|
22860
|
+
this._reconnectionTimeoutId = setTimeout(() => {
|
|
22860
22861
|
this.createWebSocket();
|
|
22861
22862
|
}, timeoutMs);
|
|
22862
22863
|
}
|
|
@@ -22874,12 +22875,19 @@ var WeaveStoreAzureWebPubSubSyncHost = class {
|
|
|
22874
22875
|
});
|
|
22875
22876
|
}
|
|
22876
22877
|
async start() {
|
|
22878
|
+
this._forceClose = false;
|
|
22879
|
+
this._reconnectAttempts = 0;
|
|
22880
|
+
if (this._reconnectionTimeoutId) clearTimeout(this._reconnectionTimeoutId);
|
|
22877
22881
|
await this.createWebSocket();
|
|
22878
22882
|
}
|
|
22879
22883
|
isConnected() {
|
|
22880
22884
|
return this._conn && this._conn.readyState === WebSocket.OPEN;
|
|
22881
22885
|
}
|
|
22886
|
+
isReconnecting() {
|
|
22887
|
+
return this._reconnectionTimeoutId !== null;
|
|
22888
|
+
}
|
|
22882
22889
|
async stop() {
|
|
22890
|
+
this._reconnectAttempts = 0;
|
|
22883
22891
|
this._forceClose = true;
|
|
22884
22892
|
if (this._conn?.readyState === WebSocket.OPEN) {
|
|
22885
22893
|
this._conn?.close();
|
|
@@ -23179,6 +23187,7 @@ var WeaveAzureWebPubsubSyncHandler = class extends WebPubSubEventHandler {
|
|
|
23179
23187
|
}
|
|
23180
23188
|
async getHostConnection(roomId) {
|
|
23181
23189
|
if (!this._rooms.has(roomId)) await this.setupRoomInstance(roomId);
|
|
23190
|
+
if (this._rooms.has(roomId) && !this._roomsSyncHost.get(roomId)?.isConnected() && !this._roomsSyncHost.get(roomId)?.isReconnecting()) await this._roomsSyncHost.get(roomId)?.start();
|
|
23182
23191
|
}
|
|
23183
23192
|
getRoomsLoaded() {
|
|
23184
23193
|
return Array.from(this._rooms.keys());
|
|
@@ -23200,6 +23209,18 @@ var WeaveAzureWebPubsubSyncHandler = class extends WebPubSubEventHandler {
|
|
|
23200
23209
|
const finalURL = `${token.url}&group=${roomId}`;
|
|
23201
23210
|
return finalURL;
|
|
23202
23211
|
}
|
|
23212
|
+
async clientDisconnect(roomId) {
|
|
23213
|
+
const roomSyncHost = this._roomsSyncHost.get(roomId);
|
|
23214
|
+
if (roomSyncHost) await this.destroyRoomInstance(roomId);
|
|
23215
|
+
}
|
|
23216
|
+
async clientTransportConnect(roomId) {
|
|
23217
|
+
const roomSyncHost = this._roomsSyncHost.get(roomId);
|
|
23218
|
+
if (roomSyncHost) await roomSyncHost.start();
|
|
23219
|
+
}
|
|
23220
|
+
clientTransportDisconnect(roomId) {
|
|
23221
|
+
const roomSyncHost = this._roomsSyncHost.get(roomId);
|
|
23222
|
+
if (roomSyncHost) roomSyncHost.stop();
|
|
23223
|
+
}
|
|
23203
23224
|
};
|
|
23204
23225
|
|
|
23205
23226
|
//#endregion
|
|
@@ -23248,6 +23269,15 @@ var WeaveAzureWebPubsubServer = class extends Emittery {
|
|
|
23248
23269
|
async clientConnect(roomId, connectionOptions) {
|
|
23249
23270
|
return await this.syncHandler.clientConnect(roomId, connectionOptions);
|
|
23250
23271
|
}
|
|
23272
|
+
async clientDisconnect(roomId) {
|
|
23273
|
+
await this.syncHandler.clientDisconnect(roomId);
|
|
23274
|
+
}
|
|
23275
|
+
async clientTransportConnect(roomId) {
|
|
23276
|
+
await this.syncHandler.clientTransportConnect(roomId);
|
|
23277
|
+
}
|
|
23278
|
+
clientTransportDisconnect(roomId) {
|
|
23279
|
+
this.syncHandler.clientTransportDisconnect(roomId);
|
|
23280
|
+
}
|
|
23251
23281
|
};
|
|
23252
23282
|
|
|
23253
23283
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inditextech/weave-store-azure-web-pubsub",
|
|
3
|
-
"version": "3.3.1
|
|
3
|
+
"version": "3.3.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Jesus Manuel PiΓ±eiro Cid <jesusmpc@inditex.com>",
|
|
@@ -57,8 +57,8 @@
|
|
|
57
57
|
"dependencies": {
|
|
58
58
|
"@azure/identity": "4.10.2",
|
|
59
59
|
"@azure/web-pubsub": "1.2.0",
|
|
60
|
-
"@inditextech/weave-types": "3.3.1
|
|
61
|
-
"@inditextech/weave-sdk": "3.3.1
|
|
60
|
+
"@inditextech/weave-types": "3.3.1",
|
|
61
|
+
"@inditextech/weave-sdk": "3.3.1",
|
|
62
62
|
"@syncedstore/core": "0.6.0",
|
|
63
63
|
"buffer": "6.0.3",
|
|
64
64
|
"reconnecting-websocket": "4.4.0",
|