@pluv/client 0.41.7 → 0.42.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.
@@ -1,5 +1,5 @@
1
1
 
2
- > @pluv/client@0.41.7 build /home/runner/work/pluv/pluv/packages/client
2
+ > @pluv/client@0.42.0 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 55.12 KB
12
- ESM ⚡️ Build success in 110ms
13
- CJS dist/index.js 56.44 KB
14
- CJS ⚡️ Build success in 116ms
11
+ ESM dist/index.mjs 55.91 KB
12
+ ESM ⚡️ Build success in 112ms
13
+ CJS dist/index.js 57.22 KB
14
+ CJS ⚡️ Build success in 118ms
15
15
  DTS Build start
16
- DTS ⚡️ Build success in 3198ms
17
- DTS dist/index.d.mts 24.58 KB
18
- DTS dist/index.d.ts 24.58 KB
16
+ DTS ⚡️ Build success in 3444ms
17
+ DTS dist/index.d.mts 24.61 KB
18
+ DTS dist/index.d.ts 24.61 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @pluv/client
2
2
 
3
+ ## 0.42.0
4
+
5
+ ### Patch Changes
6
+
7
+ - 7ae56bf: Periodically sync connection ids with the server to clear stale connections.
8
+ - @pluv/crdt@0.42.0
9
+ - @pluv/types@0.42.0
10
+
3
11
  ## 0.41.7
4
12
 
5
13
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -206,6 +206,7 @@ declare class PluvRoom<TIO extends IOLike<any, any>, TMetadata extends JsonObjec
206
206
  private _handleRegisteredMessage;
207
207
  private _handleStorageReceivedMessage;
208
208
  private _handleStorageUpdatedMessage;
209
+ private _handleSyncStateReceived;
209
210
  private _handleUserJoinedMessage;
210
211
  private _heartbeat;
211
212
  private _logDebug;
package/dist/index.d.ts CHANGED
@@ -206,6 +206,7 @@ declare class PluvRoom<TIO extends IOLike<any, any>, TMetadata extends JsonObjec
206
206
  private _handleRegisteredMessage;
207
207
  private _handleStorageReceivedMessage;
208
208
  private _handleStorageUpdatedMessage;
209
+ private _handleSyncStateReceived;
209
210
  private _handleUserJoinedMessage;
210
211
  private _heartbeat;
211
212
  private _logDebug;
package/dist/index.js CHANGED
@@ -1113,6 +1113,21 @@ var PluvRoom = class extends AbstractRoom {
1113
1113
  );
1114
1114
  this._crdtNotifier.rootSubject.next(storageRoot);
1115
1115
  }
1116
+ _handleSyncStateReceived(message) {
1117
+ var _a;
1118
+ const { connectionId } = message;
1119
+ if (!connectionId) return;
1120
+ if (!this._state.webSocket) throw new Error("Could not find WebSocket");
1121
+ if (!this._usersManager.myself) return;
1122
+ const data = message.data;
1123
+ const active = new Set((_a = data == null ? void 0 : data.connectionIds) != null ? _a : []);
1124
+ const quitters = this._usersManager.getOthers().filter((other) => !active.has(other.connectionId));
1125
+ quitters.forEach((quitter) => {
1126
+ this._usersManager.deleteConnection(quitter.connectionId);
1127
+ });
1128
+ const remaining = this._usersManager.getOthers();
1129
+ this._stateNotifier.subjects.others.next(remaining);
1130
+ }
1116
1131
  _handleUserJoinedMessage(message) {
1117
1132
  const { connectionId } = message;
1118
1133
  if (!connectionId) return;
@@ -1250,6 +1265,10 @@ var PluvRoom = class extends AbstractRoom {
1250
1265
  this._handleStorageUpdatedMessage(message);
1251
1266
  return;
1252
1267
  }
1268
+ case "$syncStateReceived": {
1269
+ this._handleSyncStateReceived(message);
1270
+ return;
1271
+ }
1253
1272
  case "$userJoined": {
1254
1273
  this._handleUserJoinedMessage(message);
1255
1274
  return;
package/dist/index.mjs CHANGED
@@ -1082,6 +1082,21 @@ var PluvRoom = class extends AbstractRoom {
1082
1082
  );
1083
1083
  this._crdtNotifier.rootSubject.next(storageRoot);
1084
1084
  }
1085
+ _handleSyncStateReceived(message) {
1086
+ var _a;
1087
+ const { connectionId } = message;
1088
+ if (!connectionId) return;
1089
+ if (!this._state.webSocket) throw new Error("Could not find WebSocket");
1090
+ if (!this._usersManager.myself) return;
1091
+ const data = message.data;
1092
+ const active = new Set((_a = data == null ? void 0 : data.connectionIds) != null ? _a : []);
1093
+ const quitters = this._usersManager.getOthers().filter((other) => !active.has(other.connectionId));
1094
+ quitters.forEach((quitter) => {
1095
+ this._usersManager.deleteConnection(quitter.connectionId);
1096
+ });
1097
+ const remaining = this._usersManager.getOthers();
1098
+ this._stateNotifier.subjects.others.next(remaining);
1099
+ }
1085
1100
  _handleUserJoinedMessage(message) {
1086
1101
  const { connectionId } = message;
1087
1102
  if (!connectionId) return;
@@ -1219,6 +1234,10 @@ var PluvRoom = class extends AbstractRoom {
1219
1234
  this._handleStorageUpdatedMessage(message);
1220
1235
  return;
1221
1236
  }
1237
+ case "$syncStateReceived": {
1238
+ this._handleSyncStateReceived(message);
1239
+ return;
1240
+ }
1222
1241
  case "$userJoined": {
1223
1242
  this._handleUserJoinedMessage(message);
1224
1243
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pluv/client",
3
- "version": "0.41.7",
3
+ "version": "0.42.0",
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.41.7",
22
- "@pluv/types": "^0.41.7"
21
+ "@pluv/crdt": "^0.42.0",
22
+ "@pluv/types": "^0.42.0"
23
23
  },
24
24
  "devDependencies": {
25
- "eslint": "^9.25.0",
25
+ "eslint": "^9.25.1",
26
26
  "tsup": "^8.4.0",
27
27
  "typescript": "^5.8.3",
28
- "@pluv/tsconfig": "^0.41.7",
29
- "eslint-config-pluv": "^0.41.7"
28
+ "@pluv/tsconfig": "^0.42.0",
29
+ "eslint-config-pluv": "^0.42.0"
30
30
  },
31
31
  "scripts": {
32
32
  "build": "tsup src/index.ts --format esm,cjs --dts",
package/src/PluvRoom.ts CHANGED
@@ -1017,6 +1017,28 @@ export class PluvRoom<
1017
1017
  this._crdtNotifier.rootSubject.next(storageRoot);
1018
1018
  }
1019
1019
 
1020
+ private _handleSyncStateReceived(message: IOEventMessage<TIO>): void {
1021
+ const { connectionId } = message;
1022
+
1023
+ if (!connectionId) return;
1024
+ // Should not reach here
1025
+ if (!this._state.webSocket) throw new Error("Could not find WebSocket");
1026
+ if (!this._usersManager.myself) return;
1027
+
1028
+ const data = message.data as BaseIOEventRecord<InferIOAuthorize<TIO>>["$syncStateReceived"];
1029
+ const active = new Set(data?.connectionIds ?? []);
1030
+
1031
+ const quitters = this._usersManager.getOthers().filter((other) => !active.has(other.connectionId));
1032
+
1033
+ quitters.forEach((quitter) => {
1034
+ this._usersManager.deleteConnection(quitter.connectionId);
1035
+ });
1036
+
1037
+ const remaining = this._usersManager.getOthers();
1038
+
1039
+ this._stateNotifier.subjects.others.next(remaining);
1040
+ }
1041
+
1020
1042
  private _handleUserJoinedMessage(message: IOEventMessage<TIO>): void {
1021
1043
  const { connectionId } = message;
1022
1044
 
@@ -1190,6 +1212,10 @@ export class PluvRoom<
1190
1212
  this._handleStorageUpdatedMessage(message);
1191
1213
  return;
1192
1214
  }
1215
+ case "$syncStateReceived": {
1216
+ this._handleSyncStateReceived(message);
1217
+ return;
1218
+ }
1193
1219
  case "$userJoined": {
1194
1220
  this._handleUserJoinedMessage(message);
1195
1221
  return;