@inditextech/weave-store-websockets 2.5.0 → 2.7.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/dist/client.d.ts CHANGED
@@ -22,11 +22,14 @@ type FetchRoom = (roomId: string) => Promise<Uint8Array | null>;
22
22
  declare class WeaveStoreWebsockets extends WeaveStore {
23
23
  private websocketOptions;
24
24
  private roomId;
25
- private initialized;
25
+ private initialRoomData;
26
+ private started;
26
27
  protected provider: WebsocketProvider;
27
28
  protected name: string;
28
29
  protected supportsUndoManager: boolean;
29
- constructor(storeOptions: WeaveStoreOptions, websocketOptions: WeaveStoreWebsocketsOptions);
30
+ constructor(initialRoomData: Uint8Array | FetchInitialState | undefined, storeOptions: WeaveStoreOptions, websocketOptions: WeaveStoreWebsocketsOptions);
31
+ setup(): void;
32
+ private loadRoomInitialData;
30
33
  private init;
31
34
  connect(): void;
32
35
  disconnect(): void;
package/dist/client.js CHANGED
@@ -10,33 +10,46 @@ const WEAVE_STORE_WEBSOCKETS = "store-websockets";
10
10
  var WeaveStoreWebsockets = class extends WeaveStore {
11
11
  name = WEAVE_STORE_WEBSOCKETS;
12
12
  supportsUndoManager = true;
13
- constructor(storeOptions, websocketOptions) {
13
+ constructor(initialRoomData, storeOptions, websocketOptions) {
14
14
  super(storeOptions);
15
15
  const { roomId } = websocketOptions;
16
16
  this.websocketOptions = websocketOptions;
17
17
  this.roomId = roomId;
18
+ this.initialRoomData = initialRoomData;
19
+ this.started = false;
18
20
  this.init();
19
21
  }
22
+ setup() {
23
+ super.setup();
24
+ }
25
+ loadRoomInitialData() {
26
+ if (this.initialRoomData && this.initialRoomData instanceof Uint8Array) this.loadDocument(this.initialRoomData);
27
+ if (this.initialRoomData && typeof this.initialRoomData === "function") this.loadDefaultDocument(this.initialRoomData);
28
+ if (!this.initialRoomData) this.loadDefaultDocument();
29
+ this.initialRoomData = void 0;
30
+ }
20
31
  init() {
21
32
  const { wsOptions: { serverUrl } } = this.websocketOptions;
22
- this.initialized = false;
23
33
  this.provider = new WebsocketProvider(serverUrl, this.roomId, this.getDocument(), {
24
34
  connect: false,
25
35
  disableBc: true
26
36
  });
27
37
  this.provider.on("status", ({ status }) => {
28
38
  this.handleConnectionStatusChange(status);
29
- if (!this.initialized && status === "connected") this.initialized = true;
39
+ if (status === WEAVE_STORE_CONNECTION_STATUS.CONNECTED && !this.started) {
40
+ this.loadRoomInitialData();
41
+ this.started = true;
42
+ }
30
43
  });
31
44
  this.provider.on("connection-close", () => {
32
- if (this.initialized) {
45
+ if (this.started) {
33
46
  this.handleConnectionStatusChange(WEAVE_STORE_CONNECTION_STATUS.CONNECTING);
34
47
  return;
35
48
  }
36
49
  this.handleConnectionStatusChange(WEAVE_STORE_CONNECTION_STATUS.DISCONNECTED);
37
50
  });
38
51
  this.provider.on("connection-error", () => {
39
- if (this.initialized) {
52
+ if (this.started) {
40
53
  this.handleConnectionStatusChange(WEAVE_STORE_CONNECTION_STATUS.DISCONNECTED);
41
54
  return;
42
55
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inditextech/weave-store-websockets",
3
- "version": "2.5.0",
3
+ "version": "2.7.0",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Jesus Manuel Piñeiro Cid <jesusmpc@inditex.com>",
@@ -56,8 +56,8 @@
56
56
  "version:release": "npm version $RELEASE_VERSION -m \"[npm-scripts] prepare release $RELEASE_VERSION\" --tag-version-prefix \"\""
57
57
  },
58
58
  "dependencies": {
59
- "@inditextech/weave-types": "2.5.0",
60
- "@inditextech/weave-sdk": "2.5.0",
59
+ "@inditextech/weave-types": "2.7.0",
60
+ "@inditextech/weave-sdk": "2.7.0",
61
61
  "@syncedstore/core": "0.6.0",
62
62
  "ws": "8.18.1",
63
63
  "y-websocket": "3.0.0"