@inditextech/weave-store-azure-web-pubsub 1.3.1 → 2.0.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 +5 -1
- package/dist/client.js +35 -6
- package/dist/server.d.ts +2 -1
- package/dist/server.js +19 -39
- package/package.json +3 -3
package/dist/client.d.ts
CHANGED
|
@@ -214,11 +214,15 @@ declare class WeaveStoreAzureWebPubSubSyncClient extends Emittery {
|
|
|
214
214
|
declare class WeaveStoreAzureWebPubsub extends WeaveStore {
|
|
215
215
|
private azureWebPubsubOptions;
|
|
216
216
|
private roomId;
|
|
217
|
+
private started;
|
|
218
|
+
private initialRoomData;
|
|
217
219
|
protected provider: WeaveStoreAzureWebPubSubSyncClient;
|
|
218
220
|
protected name: string;
|
|
219
221
|
protected supportsUndoManager: boolean;
|
|
220
222
|
protected awarenessCallback: (changes: any) => void;
|
|
221
|
-
constructor(storeOptions: WeaveStoreOptions, azureWebPubsubOptions: Pick<WeaveStoreAzureWebPubsubOptions, "roomId" | "url"> & Partial<Omit<WeaveStoreAzureWebPubsubOptions, "roomId" | "url">>);
|
|
223
|
+
constructor(initialRoomData: Uint8Array | FetchInitialState | undefined, storeOptions: WeaveStoreOptions, azureWebPubsubOptions: Pick<WeaveStoreAzureWebPubsubOptions, "roomId" | "url"> & Partial<Omit<WeaveStoreAzureWebPubsubOptions, "roomId" | "url">>);
|
|
224
|
+
setup(): void;
|
|
225
|
+
private loadRoomInitialData;
|
|
222
226
|
private init;
|
|
223
227
|
emitEvent<T>(name: string, payload?: T): void;
|
|
224
228
|
getClientId(): string | null;
|
package/dist/client.js
CHANGED
|
@@ -3863,7 +3863,8 @@ var WeaveStoreAzureWebPubSubSyncClient = class extends Emittery {
|
|
|
3863
3863
|
this._wsConnected = false;
|
|
3864
3864
|
this._initialized = false;
|
|
3865
3865
|
this.synced = false;
|
|
3866
|
-
websocket.addEventListener("error", () => {
|
|
3866
|
+
websocket.addEventListener("error", (e) => {
|
|
3867
|
+
if (e) console.error("Websocket error", e);
|
|
3867
3868
|
if (this._initialized && websocket.retryCount > 0) {
|
|
3868
3869
|
this._status = "connecting";
|
|
3869
3870
|
this.emit("status", this._status);
|
|
@@ -3925,14 +3926,25 @@ var WeaveStoreAzureWebPubSubSyncClient = class extends Emittery {
|
|
|
3925
3926
|
await this.createWebSocket();
|
|
3926
3927
|
}
|
|
3927
3928
|
};
|
|
3929
|
+
function safeSend(data) {
|
|
3930
|
+
const MAX_BYTES = 64 * 1024;
|
|
3931
|
+
const bytes = new TextEncoder().encode(data);
|
|
3932
|
+
if (bytes.byteLength > MAX_BYTES) {
|
|
3933
|
+
console.warn(`Message too large: ${bytes.byteLength} bytes (limit ${MAX_BYTES}). Skipping send.`);
|
|
3934
|
+
return false;
|
|
3935
|
+
}
|
|
3936
|
+
return true;
|
|
3937
|
+
}
|
|
3928
3938
|
function joinGroup(client, group) {
|
|
3929
|
-
|
|
3939
|
+
const payload = JSON.stringify({
|
|
3930
3940
|
type: MessageType.JoinGroup,
|
|
3931
3941
|
group
|
|
3932
|
-
})
|
|
3942
|
+
});
|
|
3943
|
+
if (!safeSend(payload)) return;
|
|
3944
|
+
client.ws?.send(payload);
|
|
3933
3945
|
}
|
|
3934
3946
|
function sendToControlGroup(client, group, type, u8) {
|
|
3935
|
-
|
|
3947
|
+
const payload = JSON.stringify({
|
|
3936
3948
|
type: MessageType.SendToGroup,
|
|
3937
3949
|
group: `${group}.host`,
|
|
3938
3950
|
data: {
|
|
@@ -3940,7 +3952,9 @@ function sendToControlGroup(client, group, type, u8) {
|
|
|
3940
3952
|
f: client.id,
|
|
3941
3953
|
c: Buffer$1.from(u8).toString("base64")
|
|
3942
3954
|
}
|
|
3943
|
-
})
|
|
3955
|
+
});
|
|
3956
|
+
if (!safeSend(payload)) return;
|
|
3957
|
+
client.ws?.send(payload);
|
|
3944
3958
|
}
|
|
3945
3959
|
|
|
3946
3960
|
//#endregion
|
|
@@ -3957,13 +3971,24 @@ const WEAVE_STORE_AZURE_WEB_PUBSUB_DEFAULT_CONFIG = { resyncIntervalMs: 15e3 };
|
|
|
3957
3971
|
var WeaveStoreAzureWebPubsub = class extends WeaveStore {
|
|
3958
3972
|
name = WEAVE_STORE_AZURE_WEB_PUBSUB;
|
|
3959
3973
|
supportsUndoManager = true;
|
|
3960
|
-
constructor(storeOptions, azureWebPubsubOptions) {
|
|
3974
|
+
constructor(initialRoomData, storeOptions, azureWebPubsubOptions) {
|
|
3961
3975
|
super(storeOptions);
|
|
3962
3976
|
const { roomId } = azureWebPubsubOptions;
|
|
3963
3977
|
this.azureWebPubsubOptions = (0, import_merge.default)(WEAVE_STORE_AZURE_WEB_PUBSUB_DEFAULT_CONFIG, azureWebPubsubOptions);
|
|
3964
3978
|
this.roomId = roomId;
|
|
3979
|
+
this.initialRoomData = initialRoomData;
|
|
3980
|
+
this.started = false;
|
|
3965
3981
|
this.init();
|
|
3966
3982
|
}
|
|
3983
|
+
setup() {
|
|
3984
|
+
super.setup();
|
|
3985
|
+
}
|
|
3986
|
+
loadRoomInitialData() {
|
|
3987
|
+
if (this.initialRoomData && this.initialRoomData instanceof Uint8Array) this.loadDocument(this.initialRoomData);
|
|
3988
|
+
if (this.initialRoomData && typeof this.initialRoomData === "function") this.loadDefaultDocument(this.initialRoomData);
|
|
3989
|
+
if (!this.initialRoomData) this.loadDefaultDocument();
|
|
3990
|
+
this.initialRoomData = void 0;
|
|
3991
|
+
}
|
|
3967
3992
|
init() {
|
|
3968
3993
|
const { url } = this.azureWebPubsubOptions;
|
|
3969
3994
|
this.provider = new WeaveStoreAzureWebPubSubSyncClient(this, url, this.roomId, this.getDocument(), {
|
|
@@ -3980,6 +4005,10 @@ var WeaveStoreAzureWebPubsub = class extends WeaveStore {
|
|
|
3980
4005
|
});
|
|
3981
4006
|
this.provider.on("status", (status) => {
|
|
3982
4007
|
this.handleConnectionStatusChange(status);
|
|
4008
|
+
if (status === WEAVE_STORE_CONNECTION_STATUS.CONNECTED && !this.started) {
|
|
4009
|
+
this.loadRoomInitialData();
|
|
4010
|
+
this.started = true;
|
|
4011
|
+
}
|
|
3983
4012
|
});
|
|
3984
4013
|
}
|
|
3985
4014
|
emitEvent(name, payload) {
|
package/dist/server.d.ts
CHANGED
|
@@ -882,6 +882,7 @@ declare class WeaveStoreAzureWebPubSubSyncHost {
|
|
|
882
882
|
start(): Promise<void>;
|
|
883
883
|
stop(): Promise<void>;
|
|
884
884
|
simulateWebsocketError(): void;
|
|
885
|
+
private safeSend;
|
|
885
886
|
private broadcast;
|
|
886
887
|
private send;
|
|
887
888
|
private onClientInit;
|
|
@@ -910,7 +911,7 @@ declare class WeaveAzureWebPubsubSyncHandler extends WebPubSubEventHandler {
|
|
|
910
911
|
private getHostConnection;
|
|
911
912
|
getRoomsLoaded(): string[];
|
|
912
913
|
getRoomSyncHost(roomId: string): WeaveStoreAzureWebPubSubSyncHost | undefined;
|
|
913
|
-
clientConnect(roomId: string): Promise<string
|
|
914
|
+
clientConnect(roomId: string): Promise<string>;
|
|
914
915
|
}
|
|
915
916
|
|
|
916
917
|
//#endregion
|
package/dist/server.js
CHANGED
|
@@ -8,6 +8,7 @@ import { URL as URL$1 } from "node:url";
|
|
|
8
8
|
import { EOL } from "node:os";
|
|
9
9
|
import process$1 from "node:process";
|
|
10
10
|
import { WebSocket } from "ws";
|
|
11
|
+
import { defaultInitialState } from "@inditextech/weave-sdk/server";
|
|
11
12
|
|
|
12
13
|
//#region rolldown:runtime
|
|
13
14
|
var __create = Object.create;
|
|
@@ -22937,8 +22938,17 @@ var WeaveStoreAzureWebPubSubSyncHost = class {
|
|
|
22937
22938
|
simulateWebsocketError() {
|
|
22938
22939
|
if (this._conn) this._conn.emit("error", new Error("Simulated connection failure"));
|
|
22939
22940
|
}
|
|
22941
|
+
safeSend(data) {
|
|
22942
|
+
const MAX_BYTES = 64 * 1024;
|
|
22943
|
+
const bytes = new TextEncoder().encode(data);
|
|
22944
|
+
if (bytes.byteLength > MAX_BYTES) {
|
|
22945
|
+
console.warn(`Message too large: ${bytes.byteLength} bytes (limit ${MAX_BYTES}). Skipping send.`);
|
|
22946
|
+
return false;
|
|
22947
|
+
}
|
|
22948
|
+
return true;
|
|
22949
|
+
}
|
|
22940
22950
|
broadcast(group, from$1, u8) {
|
|
22941
|
-
|
|
22951
|
+
const payload = JSON.stringify({
|
|
22942
22952
|
type: MessageType.SendToGroup,
|
|
22943
22953
|
group,
|
|
22944
22954
|
noEcho: true,
|
|
@@ -22946,10 +22956,12 @@ var WeaveStoreAzureWebPubSubSyncHost = class {
|
|
|
22946
22956
|
f: from$1,
|
|
22947
22957
|
c: Buffer.from(u8).toString("base64")
|
|
22948
22958
|
}
|
|
22949
|
-
})
|
|
22959
|
+
});
|
|
22960
|
+
if (!this.safeSend(payload)) return;
|
|
22961
|
+
this._conn?.send?.(payload);
|
|
22950
22962
|
}
|
|
22951
22963
|
send(group, to, u8) {
|
|
22952
|
-
|
|
22964
|
+
const payload = JSON.stringify({
|
|
22953
22965
|
type: MessageType.SendToGroup,
|
|
22954
22966
|
group,
|
|
22955
22967
|
noEcho: true,
|
|
@@ -22957,7 +22969,9 @@ var WeaveStoreAzureWebPubSubSyncHost = class {
|
|
|
22957
22969
|
t: to,
|
|
22958
22970
|
c: Buffer.from(u8).toString("base64")
|
|
22959
22971
|
}
|
|
22960
|
-
})
|
|
22972
|
+
});
|
|
22973
|
+
if (!this.safeSend(payload)) return;
|
|
22974
|
+
this._conn?.send?.(payload);
|
|
22961
22975
|
}
|
|
22962
22976
|
onClientInit(group, data) {
|
|
22963
22977
|
const encoder = createEncoder();
|
|
@@ -23101,11 +23115,7 @@ var WeaveAzureWebPubsubSyncHandler = class extends WebPubSubEventHandler {
|
|
|
23101
23115
|
return this._roomsSyncHost.get(roomId);
|
|
23102
23116
|
}
|
|
23103
23117
|
async clientConnect(roomId) {
|
|
23104
|
-
|
|
23105
|
-
await this.getHostConnection(roomId);
|
|
23106
|
-
} catch (ex) {
|
|
23107
|
-
return null;
|
|
23108
|
-
}
|
|
23118
|
+
await this.getHostConnection(roomId);
|
|
23109
23119
|
const token = await this._client.getClientAccessToken({
|
|
23110
23120
|
groups: [roomId],
|
|
23111
23121
|
roles: [`webpubsub.joinLeaveGroup.${roomId}`, `webpubsub.sendToGroup.${roomId}.host`]
|
|
@@ -23115,36 +23125,6 @@ var WeaveAzureWebPubsubSyncHandler = class extends WebPubSubEventHandler {
|
|
|
23115
23125
|
}
|
|
23116
23126
|
};
|
|
23117
23127
|
|
|
23118
|
-
//#endregion
|
|
23119
|
-
//#region src/server/default-initial-state.ts
|
|
23120
|
-
const yjsLayer = function(id) {
|
|
23121
|
-
const newLayerMap = new yjs_default.Map();
|
|
23122
|
-
newLayerMap.set("key", id);
|
|
23123
|
-
newLayerMap.set("type", "layer");
|
|
23124
|
-
const newLayerMapProps = new yjs_default.Map();
|
|
23125
|
-
newLayerMapProps.set("id", id);
|
|
23126
|
-
newLayerMapProps.set("nodeType", "layer");
|
|
23127
|
-
newLayerMapProps.set("children", new yjs_default.Array());
|
|
23128
|
-
newLayerMap.set("props", newLayerMapProps);
|
|
23129
|
-
return newLayerMap;
|
|
23130
|
-
};
|
|
23131
|
-
function defaultInitialState(doc) {
|
|
23132
|
-
const children = new yjs_default.Array();
|
|
23133
|
-
children.insert(0, [
|
|
23134
|
-
yjsLayer("gridLayer"),
|
|
23135
|
-
yjsLayer("mainLayer"),
|
|
23136
|
-
yjsLayer("selectionLayer"),
|
|
23137
|
-
yjsLayer("usersPointersLayer"),
|
|
23138
|
-
yjsLayer("utilityLayer")
|
|
23139
|
-
]);
|
|
23140
|
-
const stageProps = new yjs_default.Map();
|
|
23141
|
-
stageProps.set("id", "stage");
|
|
23142
|
-
stageProps.set("children", children);
|
|
23143
|
-
doc.getMap("weave").set("key", "stage");
|
|
23144
|
-
doc.getMap("weave").set("type", "stage");
|
|
23145
|
-
doc.getMap("weave").set("props", stageProps);
|
|
23146
|
-
}
|
|
23147
|
-
|
|
23148
23128
|
//#endregion
|
|
23149
23129
|
//#region src/server/azure-web-pubsub-server.ts
|
|
23150
23130
|
var WeaveAzureWebPubsubServer = class extends Emittery {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inditextech/weave-store-azure-web-pubsub",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.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": "
|
|
61
|
-
"@inditextech/weave-sdk": "
|
|
60
|
+
"@inditextech/weave-types": "2.0.1",
|
|
61
|
+
"@inditextech/weave-sdk": "2.0.1",
|
|
62
62
|
"@syncedstore/core": "0.6.0",
|
|
63
63
|
"buffer": "6.0.3",
|
|
64
64
|
"reconnecting-websocket": "4.4.0",
|