@pluv/client 0.41.1 → 0.41.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.41.1 build /home/runner/work/pluv/pluv/packages/client
2
+ > @pluv/client@0.41.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
- CJS dist/index.js 55.51 KB
12
- CJS ⚡️ Build success in 131ms
13
- ESM dist/index.mjs 54.19 KB
14
- ESM ⚡️ Build success in 132ms
11
+ ESM dist/index.mjs 54.44 KB
12
+ ESM ⚡️ Build success in 116ms
13
+ CJS dist/index.js 55.76 KB
14
+ CJS ⚡️ Build success in 116ms
15
15
  DTS Build start
16
- DTS ⚡️ Build success in 3291ms
16
+ DTS ⚡️ Build success in 3794ms
17
17
  DTS dist/index.d.mts 24.58 KB
18
18
  DTS dist/index.d.ts 24.58 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @pluv/client
2
2
 
3
+ ## 0.41.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 37956d3: When presence is received for a user that is not currently being tracked, `PluvRoom` now automatically updates `others` to include the connection of the received presence.
8
+ - @pluv/crdt@0.41.2
9
+ - @pluv/types@0.41.2
10
+
3
11
  ## 0.41.1
4
12
 
5
13
  ### Patch Changes
package/dist/index.js CHANGED
@@ -334,7 +334,7 @@ var UsersManager = class {
334
334
  this._others = /* @__PURE__ */ new Map();
335
335
  this._presence = null;
336
336
  const { initialPresence, presence = null } = config;
337
- this._initialPresence = initialPresence;
337
+ this.initialPresence = initialPresence;
338
338
  this._myPresence = initialPresence;
339
339
  this._presence = presence;
340
340
  }
@@ -347,7 +347,7 @@ var UsersManager = class {
347
347
  addConnection(userInfo) {
348
348
  var _a;
349
349
  const data = __spreadProps(__spreadValues({}, userInfo), {
350
- presence: (_a = userInfo.presence) != null ? _a : this._initialPresence
350
+ presence: (_a = userInfo.presence) != null ? _a : this.initialPresence
351
351
  });
352
352
  const myClientId = !!this._myself ? this.getClientId(this._myself) : null;
353
353
  const clientId = this.getClientId(data);
@@ -434,7 +434,7 @@ var UsersManager = class {
434
434
  setMyself(userInfo) {
435
435
  var _a;
436
436
  const connectionId = userInfo.connectionId;
437
- const presence = (_a = userInfo.presence) != null ? _a : this._initialPresence;
437
+ const presence = (_a = userInfo.presence) != null ? _a : this.initialPresence;
438
438
  this._myself = __spreadProps(__spreadValues({}, userInfo), { presence });
439
439
  this._myPresence = presence;
440
440
  const clientId = this.getClientId(this._myself);
@@ -983,9 +983,19 @@ var PluvRoom = class extends AbstractRoom {
983
983
  this._stateNotifier.subjects.myself.next(this._usersManager.myself);
984
984
  return;
985
985
  }
986
- const other = this._usersManager.getOther(connectionId);
986
+ if (!!clientId) {
987
+ const other = this._usersManager.getOther(connectionId);
988
+ this._otherNotifier.subject(clientId).next(other);
989
+ } else {
990
+ const added = this._usersManager.addConnection({
991
+ connectionId,
992
+ presence: __spreadValues(__spreadValues({}, this._usersManager.initialPresence), data.presence),
993
+ user: message.user
994
+ });
995
+ const other = this._usersManager.getOther(connectionId);
996
+ this._otherNotifier.subject(added.clientId).next(other);
997
+ }
987
998
  const others = this._usersManager.getOthers();
988
- if (!!clientId) this._otherNotifier.subject(clientId).next(other);
989
999
  this._stateNotifier.subjects.others.next(others);
990
1000
  }
991
1001
  _handleReceiveOthers(message) {
@@ -1086,7 +1096,6 @@ var PluvRoom = class extends AbstractRoom {
1086
1096
  this._crdtNotifier.rootSubject.next(storageRoot);
1087
1097
  }
1088
1098
  _handleUserJoinedMessage(message) {
1089
- var _a;
1090
1099
  const { connectionId } = message;
1091
1100
  if (!connectionId) return;
1092
1101
  if (!this._state.webSocket) throw new Error("Could not find WebSocket");
@@ -1097,15 +1106,14 @@ var PluvRoom = class extends AbstractRoom {
1097
1106
  this._sendMessage({ type: "$getOthers", data: {} });
1098
1107
  return;
1099
1108
  }
1100
- const result = this._usersManager.addConnection({
1109
+ const added = this._usersManager.addConnection({
1101
1110
  connectionId,
1102
1111
  presence: data.presence,
1103
1112
  user: data.user
1104
1113
  });
1105
- const clientId = (_a = result == null ? void 0 : result.clientId) != null ? _a : null;
1106
1114
  const other = this._usersManager.getOther(connectionId);
1107
1115
  const others = this._usersManager.getOthers();
1108
- if (!!clientId) this._otherNotifier.subject(clientId).next(other);
1116
+ this._otherNotifier.subject(added.clientId).next(other);
1109
1117
  this._stateNotifier.subjects.others.next(others);
1110
1118
  }
1111
1119
  _heartbeat() {
package/dist/index.mjs CHANGED
@@ -303,7 +303,7 @@ var UsersManager = class {
303
303
  this._others = /* @__PURE__ */ new Map();
304
304
  this._presence = null;
305
305
  const { initialPresence, presence = null } = config;
306
- this._initialPresence = initialPresence;
306
+ this.initialPresence = initialPresence;
307
307
  this._myPresence = initialPresence;
308
308
  this._presence = presence;
309
309
  }
@@ -316,7 +316,7 @@ var UsersManager = class {
316
316
  addConnection(userInfo) {
317
317
  var _a;
318
318
  const data = __spreadProps(__spreadValues({}, userInfo), {
319
- presence: (_a = userInfo.presence) != null ? _a : this._initialPresence
319
+ presence: (_a = userInfo.presence) != null ? _a : this.initialPresence
320
320
  });
321
321
  const myClientId = !!this._myself ? this.getClientId(this._myself) : null;
322
322
  const clientId = this.getClientId(data);
@@ -403,7 +403,7 @@ var UsersManager = class {
403
403
  setMyself(userInfo) {
404
404
  var _a;
405
405
  const connectionId = userInfo.connectionId;
406
- const presence = (_a = userInfo.presence) != null ? _a : this._initialPresence;
406
+ const presence = (_a = userInfo.presence) != null ? _a : this.initialPresence;
407
407
  this._myself = __spreadProps(__spreadValues({}, userInfo), { presence });
408
408
  this._myPresence = presence;
409
409
  const clientId = this.getClientId(this._myself);
@@ -952,9 +952,19 @@ var PluvRoom = class extends AbstractRoom {
952
952
  this._stateNotifier.subjects.myself.next(this._usersManager.myself);
953
953
  return;
954
954
  }
955
- const other = this._usersManager.getOther(connectionId);
955
+ if (!!clientId) {
956
+ const other = this._usersManager.getOther(connectionId);
957
+ this._otherNotifier.subject(clientId).next(other);
958
+ } else {
959
+ const added = this._usersManager.addConnection({
960
+ connectionId,
961
+ presence: __spreadValues(__spreadValues({}, this._usersManager.initialPresence), data.presence),
962
+ user: message.user
963
+ });
964
+ const other = this._usersManager.getOther(connectionId);
965
+ this._otherNotifier.subject(added.clientId).next(other);
966
+ }
956
967
  const others = this._usersManager.getOthers();
957
- if (!!clientId) this._otherNotifier.subject(clientId).next(other);
958
968
  this._stateNotifier.subjects.others.next(others);
959
969
  }
960
970
  _handleReceiveOthers(message) {
@@ -1055,7 +1065,6 @@ var PluvRoom = class extends AbstractRoom {
1055
1065
  this._crdtNotifier.rootSubject.next(storageRoot);
1056
1066
  }
1057
1067
  _handleUserJoinedMessage(message) {
1058
- var _a;
1059
1068
  const { connectionId } = message;
1060
1069
  if (!connectionId) return;
1061
1070
  if (!this._state.webSocket) throw new Error("Could not find WebSocket");
@@ -1066,15 +1075,14 @@ var PluvRoom = class extends AbstractRoom {
1066
1075
  this._sendMessage({ type: "$getOthers", data: {} });
1067
1076
  return;
1068
1077
  }
1069
- const result = this._usersManager.addConnection({
1078
+ const added = this._usersManager.addConnection({
1070
1079
  connectionId,
1071
1080
  presence: data.presence,
1072
1081
  user: data.user
1073
1082
  });
1074
- const clientId = (_a = result == null ? void 0 : result.clientId) != null ? _a : null;
1075
1083
  const other = this._usersManager.getOther(connectionId);
1076
1084
  const others = this._usersManager.getOthers();
1077
- if (!!clientId) this._otherNotifier.subject(clientId).next(other);
1085
+ this._otherNotifier.subject(added.clientId).next(other);
1078
1086
  this._stateNotifier.subjects.others.next(others);
1079
1087
  }
1080
1088
  _heartbeat() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pluv/client",
3
- "version": "0.41.1",
3
+ "version": "0.41.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.41.1",
22
- "@pluv/types": "^0.41.1"
21
+ "@pluv/types": "^0.41.2",
22
+ "@pluv/crdt": "^0.41.2"
23
23
  },
24
24
  "devDependencies": {
25
25
  "eslint": "^9.25.0",
26
26
  "tsup": "^8.4.0",
27
27
  "typescript": "^5.8.3",
28
- "@pluv/tsconfig": "^0.41.1",
29
- "eslint-config-pluv": "^0.41.1"
28
+ "@pluv/tsconfig": "^0.41.2",
29
+ "eslint-config-pluv": "^0.41.2"
30
30
  },
31
31
  "scripts": {
32
32
  "build": "tsup src/index.ts --format esm,cjs --dts",
package/src/PluvRoom.ts CHANGED
@@ -77,9 +77,6 @@ export const DEFAULT_PLUV_CLIENT_ADDON = <
77
77
  storage: new StorageStore(input.room.id),
78
78
  });
79
79
 
80
- interface CloseWsOptions {
81
- connectionState?: ConnectionState;
82
- }
83
80
  interface WindowListeners {
84
81
  onNavigatorOffline: () => void;
85
82
  onNavigatorOnline: () => void;
@@ -857,10 +854,28 @@ export class PluvRoom<
857
854
  return;
858
855
  }
859
856
 
860
- const other = this._usersManager.getOther(connectionId);
857
+ if (!!clientId) {
858
+ const other = this._usersManager.getOther(connectionId);
859
+
860
+ this._otherNotifier.subject(clientId).next(other);
861
+ } else {
862
+ /**
863
+ * !HACK
864
+ * @description User could not be found. Add the connection to keep others up-to-date
865
+ * @date April 19, 2025
866
+ */
867
+ const added = this._usersManager.addConnection({
868
+ connectionId,
869
+ presence: { ...this._usersManager.initialPresence, ...data.presence } as TPresence,
870
+ user: message.user as Id<InferIOAuthorizeUser<InferIOAuthorize<TIO>>>,
871
+ });
872
+ const other = this._usersManager.getOther(connectionId);
873
+
874
+ this._otherNotifier.subject(added.clientId).next(other);
875
+ }
876
+
861
877
  const others = this._usersManager.getOthers();
862
878
 
863
- if (!!clientId) this._otherNotifier.subject(clientId).next(other);
864
879
  this._stateNotifier.subjects.others.next(others);
865
880
  }
866
881
 
@@ -1020,17 +1035,16 @@ export class PluvRoom<
1020
1035
  return;
1021
1036
  }
1022
1037
 
1023
- const result = this._usersManager.addConnection({
1038
+ const added = this._usersManager.addConnection({
1024
1039
  connectionId,
1025
1040
  presence: data.presence as TPresence,
1026
1041
  user: data.user,
1027
1042
  });
1028
1043
 
1029
- const clientId = result?.clientId ?? null;
1030
1044
  const other = this._usersManager.getOther(connectionId);
1031
1045
  const others = this._usersManager.getOthers();
1032
1046
 
1033
- if (!!clientId) this._otherNotifier.subject(clientId).next(other);
1047
+ this._otherNotifier.subject(added.clientId).next(other);
1034
1048
  this._stateNotifier.subjects.others.next(others);
1035
1049
  }
1036
1050
 
@@ -28,7 +28,7 @@ export class UsersManager<TIO extends IOLike, TPresence extends JsonObject = {}>
28
28
  fromClientId: new Map<[clientId: string][0], Set<[connectionId: string][0]>>(),
29
29
  };
30
30
 
31
- private _initialPresence: TPresence;
31
+ public readonly initialPresence: TPresence;
32
32
  /**
33
33
  * @description This presence can be updated while the user is not
34
34
  * connected.
@@ -44,7 +44,8 @@ export class UsersManager<TIO extends IOLike, TPresence extends JsonObject = {}>
44
44
  constructor(config: UsersManagerConfig<TPresence>) {
45
45
  const { initialPresence, presence = null } = config;
46
46
 
47
- this._initialPresence = initialPresence as TPresence;
47
+ this.initialPresence = initialPresence as TPresence;
48
+
48
49
  this._myPresence = initialPresence as TPresence;
49
50
  this._presence = presence;
50
51
  }
@@ -62,7 +63,7 @@ export class UsersManager<TIO extends IOLike, TPresence extends JsonObject = {}>
62
63
  ): AddConnectionResult<TIO, TPresence> {
63
64
  const data: UserInfo<TIO, TPresence> = {
64
65
  ...userInfo,
65
- presence: userInfo.presence ?? this._initialPresence,
66
+ presence: userInfo.presence ?? this.initialPresence,
66
67
  };
67
68
 
68
69
  const myClientId = !!this._myself ? this.getClientId(this._myself) : null;
@@ -205,7 +206,7 @@ export class UsersManager<TIO extends IOLike, TPresence extends JsonObject = {}>
205
206
 
206
207
  public setMyself(userInfo: OptionalProps<UserInfo<TIO, TPresence>, "presence">): void {
207
208
  const connectionId = userInfo.connectionId;
208
- const presence = userInfo.presence ?? this._initialPresence;
209
+ const presence = userInfo.presence ?? this.initialPresence;
209
210
 
210
211
  this._myself = { ...userInfo, presence };
211
212
  this._myPresence = presence;