@pluv/client 0.44.0 → 0.44.2

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.
@@ -1,5 +1,5 @@
1
1
 
2
- > @pluv/client@0.44.0 build /home/runner/work/pluv/pluv/packages/client
2
+ > @pluv/client@0.44.2 build /home/runner/work/pluv/pluv/packages/client
3
3
  > tsup src/index.ts --format esm,cjs --dts
4
4
 
5
5
  CLI Building entry: src/index.ts
@@ -8,11 +8,11 @@
8
8
  CLI Target: es6
9
9
  ESM Build start
10
10
  CJS Build start
11
- ESM dist/index.mjs 56.45 KB
12
- ESM ⚡️ Build success in 112ms
13
- CJS dist/index.js 57.76 KB
14
- CJS ⚡️ Build success in 112ms
11
+ CJS dist/index.js 58.23 KB
12
+ CJS ⚡️ Build success in 128ms
13
+ ESM dist/index.mjs 56.91 KB
14
+ ESM ⚡️ Build success in 129ms
15
15
  DTS Build start
16
- DTS ⚡️ Build success in 3446ms
17
- DTS dist/index.d.mts 25.36 KB
18
- DTS dist/index.d.ts 25.36 KB
16
+ DTS ⚡️ Build success in 3435ms
17
+ DTS dist/index.d.mts 25.38 KB
18
+ DTS dist/index.d.ts 25.38 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @pluv/client
2
2
 
3
+ ## 0.44.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 6cfd36f: Update `PluvRoom` to attempt to reconnect if currently disconnected when the window is re-focused.
8
+ - @pluv/crdt@0.44.2
9
+ - @pluv/types@0.44.2
10
+
11
+ ## 0.44.1
12
+
13
+ ### Patch Changes
14
+
15
+ - 67c081d: Fix `PluvRoom._reconnect` not being called with the last used metadata (from `PluvRoom.connect`).
16
+ - @pluv/crdt@0.44.1
17
+ - @pluv/types@0.44.1
18
+
3
19
  ## 0.44.0
4
20
 
5
21
  ### Minor Changes
package/dist/index.d.mts CHANGED
@@ -228,6 +228,7 @@ declare class PluvRoom<TIO extends IOLike<any, any>, TMetadata extends JsonObjec
228
228
  private _onNavigatorOffline;
229
229
  private _onNavigatorOnline;
230
230
  private _onVisibilityChange;
231
+ private _onWindowFocus;
231
232
  private _parseMessage;
232
233
  private _pollReconnect;
233
234
  private _reconnect;
package/dist/index.d.ts CHANGED
@@ -228,6 +228,7 @@ declare class PluvRoom<TIO extends IOLike<any, any>, TMetadata extends JsonObjec
228
228
  private _onNavigatorOffline;
229
229
  private _onNavigatorOnline;
230
230
  private _onVisibilityChange;
231
+ private _onWindowFocus;
231
232
  private _parseMessage;
232
233
  private _pollReconnect;
233
234
  private _reconnect;
package/dist/index.js CHANGED
@@ -859,11 +859,13 @@ var PluvRoom = class extends AbstractRoom {
859
859
  this._windowListeners = this._windowListeners || {
860
860
  onNavigatorOffline: this._onNavigatorOffline.bind(this),
861
861
  onNavigatorOnline: this._onNavigatorOnline.bind(this),
862
- onVisibilityChange: this._onVisibilityChange.bind(this)
862
+ onVisibilityChange: this._onVisibilityChange.bind(this),
863
+ onWindowFocus: this._onWindowFocus.bind(this)
863
864
  };
864
865
  window.addEventListener("offline", this._windowListeners.onNavigatorOffline);
865
866
  window.addEventListener("online", this._windowListeners.onNavigatorOnline);
866
867
  document.addEventListener("visibilitychange", this._windowListeners.onVisibilityChange);
868
+ window.addEventListener("focus", this._windowListeners.onWindowFocus);
867
869
  }
868
870
  _attachWsListeners() {
869
871
  if (!this._state.webSocket) return;
@@ -904,8 +906,10 @@ var PluvRoom = class extends AbstractRoom {
904
906
  if (!this._windowListeners) return;
905
907
  if (typeof window === "undefined") return;
906
908
  if (typeof document === "undefined") return;
909
+ window.removeEventListener("offline", this._windowListeners.onNavigatorOffline);
907
910
  window.removeEventListener("online", this._windowListeners.onNavigatorOnline);
908
911
  document.removeEventListener("visibilitychange", this._windowListeners.onVisibilityChange);
912
+ window.removeEventListener("focus", this._windowListeners.onWindowFocus);
909
913
  this._windowListeners = null;
910
914
  }
911
915
  _detachWsListeners() {
@@ -1329,6 +1333,11 @@ var PluvRoom = class extends AbstractRoom {
1329
1333
  }
1330
1334
  });
1331
1335
  }
1336
+ _onWindowFocus() {
1337
+ return __async(this, null, function* () {
1338
+ return yield this._onVisibilityChange();
1339
+ });
1340
+ }
1332
1341
  _parseMessage(message) {
1333
1342
  if (typeof message.data !== "string") return null;
1334
1343
  try {
@@ -1375,7 +1384,9 @@ var PluvRoom = class extends AbstractRoom {
1375
1384
  webSocket.send(message);
1376
1385
  }
1377
1386
  _setMetadata(metadata) {
1378
- return this.metadata ? this.metadata.parse(metadata) : metadata;
1387
+ const parsed = this.metadata ? this.metadata.parse(metadata) : metadata;
1388
+ this._lastMetadata = parsed;
1389
+ return parsed;
1379
1390
  }
1380
1391
  _updateState(updater) {
1381
1392
  let authorization;
package/dist/index.mjs CHANGED
@@ -828,11 +828,13 @@ var PluvRoom = class extends AbstractRoom {
828
828
  this._windowListeners = this._windowListeners || {
829
829
  onNavigatorOffline: this._onNavigatorOffline.bind(this),
830
830
  onNavigatorOnline: this._onNavigatorOnline.bind(this),
831
- onVisibilityChange: this._onVisibilityChange.bind(this)
831
+ onVisibilityChange: this._onVisibilityChange.bind(this),
832
+ onWindowFocus: this._onWindowFocus.bind(this)
832
833
  };
833
834
  window.addEventListener("offline", this._windowListeners.onNavigatorOffline);
834
835
  window.addEventListener("online", this._windowListeners.onNavigatorOnline);
835
836
  document.addEventListener("visibilitychange", this._windowListeners.onVisibilityChange);
837
+ window.addEventListener("focus", this._windowListeners.onWindowFocus);
836
838
  }
837
839
  _attachWsListeners() {
838
840
  if (!this._state.webSocket) return;
@@ -873,8 +875,10 @@ var PluvRoom = class extends AbstractRoom {
873
875
  if (!this._windowListeners) return;
874
876
  if (typeof window === "undefined") return;
875
877
  if (typeof document === "undefined") return;
878
+ window.removeEventListener("offline", this._windowListeners.onNavigatorOffline);
876
879
  window.removeEventListener("online", this._windowListeners.onNavigatorOnline);
877
880
  document.removeEventListener("visibilitychange", this._windowListeners.onVisibilityChange);
881
+ window.removeEventListener("focus", this._windowListeners.onWindowFocus);
878
882
  this._windowListeners = null;
879
883
  }
880
884
  _detachWsListeners() {
@@ -1298,6 +1302,11 @@ var PluvRoom = class extends AbstractRoom {
1298
1302
  }
1299
1303
  });
1300
1304
  }
1305
+ _onWindowFocus() {
1306
+ return __async(this, null, function* () {
1307
+ return yield this._onVisibilityChange();
1308
+ });
1309
+ }
1301
1310
  _parseMessage(message) {
1302
1311
  if (typeof message.data !== "string") return null;
1303
1312
  try {
@@ -1344,7 +1353,9 @@ var PluvRoom = class extends AbstractRoom {
1344
1353
  webSocket.send(message);
1345
1354
  }
1346
1355
  _setMetadata(metadata) {
1347
- return this.metadata ? this.metadata.parse(metadata) : metadata;
1356
+ const parsed = this.metadata ? this.metadata.parse(metadata) : metadata;
1357
+ this._lastMetadata = parsed;
1358
+ return parsed;
1348
1359
  }
1349
1360
  _updateState(updater) {
1350
1361
  let authorization;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pluv/client",
3
- "version": "0.44.0",
3
+ "version": "0.44.2",
4
4
  "description": "@pluv/io frontend client",
5
5
  "author": "leedavidcs",
6
6
  "license": "MIT",
@@ -18,15 +18,15 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "wonka": "^6.3.5",
21
- "@pluv/crdt": "^0.44.0",
22
- "@pluv/types": "^0.44.0"
21
+ "@pluv/crdt": "^0.44.2",
22
+ "@pluv/types": "^0.44.2"
23
23
  },
24
24
  "devDependencies": {
25
25
  "eslint": "^9.25.1",
26
26
  "tsup": "^8.4.0",
27
27
  "typescript": "^5.8.3",
28
- "@pluv/tsconfig": "^0.44.0",
29
- "eslint-config-pluv": "^0.44.0"
28
+ "@pluv/tsconfig": "^0.44.2",
29
+ "eslint-config-pluv": "^0.44.2"
30
30
  },
31
31
  "scripts": {
32
32
  "build": "tsup src/index.ts --format esm,cjs --dts",
package/src/PluvRoom.ts CHANGED
@@ -82,6 +82,7 @@ interface WindowListeners {
82
82
  onNavigatorOffline: () => void;
83
83
  onNavigatorOnline: () => void;
84
84
  onVisibilityChange: () => void;
85
+ onWindowFocus: () => void;
85
86
  }
86
87
 
87
88
  interface WebSocketListeners {
@@ -619,11 +620,13 @@ export class PluvRoom<
619
620
  onNavigatorOffline: this._onNavigatorOffline.bind(this),
620
621
  onNavigatorOnline: this._onNavigatorOnline.bind(this),
621
622
  onVisibilityChange: this._onVisibilityChange.bind(this),
623
+ onWindowFocus: this._onWindowFocus.bind(this),
622
624
  };
623
625
 
624
626
  window.addEventListener("offline", this._windowListeners.onNavigatorOffline);
625
627
  window.addEventListener("online", this._windowListeners.onNavigatorOnline);
626
628
  document.addEventListener("visibilitychange", this._windowListeners.onVisibilityChange);
629
+ window.addEventListener("focus", this._windowListeners.onWindowFocus);
627
630
  }
628
631
 
629
632
  private _attachWsListeners(): void {
@@ -675,8 +678,10 @@ export class PluvRoom<
675
678
  if (typeof window === "undefined") return;
676
679
  if (typeof document === "undefined") return;
677
680
 
681
+ window.removeEventListener("offline", this._windowListeners.onNavigatorOffline);
678
682
  window.removeEventListener("online", this._windowListeners.onNavigatorOnline);
679
683
  document.removeEventListener("visibilitychange", this._windowListeners.onVisibilityChange);
684
+ window.removeEventListener("focus", this._windowListeners.onWindowFocus);
680
685
 
681
686
  this._windowListeners = null;
682
687
  }
@@ -1288,6 +1293,10 @@ export class PluvRoom<
1288
1293
  }
1289
1294
  }
1290
1295
 
1296
+ private async _onWindowFocus(): Promise<void> {
1297
+ return await this._onVisibilityChange();
1298
+ }
1299
+
1291
1300
  private _parseMessage(message: { data: string | ArrayBuffer }): IOEventMessage<TIO> | null {
1292
1301
  /**
1293
1302
  * !HACK
@@ -1371,7 +1380,11 @@ export class PluvRoom<
1371
1380
  }
1372
1381
 
1373
1382
  private _setMetadata(metadata: TMetadata): TMetadata {
1374
- return this.metadata ? this.metadata.parse(metadata) : metadata;
1383
+ const parsed = this.metadata ? this.metadata.parse(metadata) : metadata;
1384
+
1385
+ this._lastMetadata = parsed;
1386
+
1387
+ return parsed;
1375
1388
  }
1376
1389
 
1377
1390
  private _updateState(updater: (oldState: WebSocketState<TIO>) => WebSocketState<TIO>): WebSocketState<TIO> {