@pluv/client 0.20.0 → 0.21.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/.turbo/turbo-build.log +15 -15
- package/CHANGELOG.md +11 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +15 -6
- package/dist/index.mjs +15 -6
- package/package.json +7 -7
- package/src/PluvRoom.ts +32 -9
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
|
|
2
|
-
> @pluv/client@0.
|
|
2
|
+
> @pluv/client@0.21.0 build /home/runner/work/pluv/pluv/packages/client
|
|
3
3
|
> tsup src/index.ts --format esm,cjs --dts
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
5
|
+
[34mCLI[39m Building entry: src/index.ts
|
|
6
|
+
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
|
+
[34mCLI[39m tsup v8.2.4
|
|
8
|
+
[34mCLI[39m Target: es6
|
|
9
|
+
[34mESM[39m Build start
|
|
10
|
+
[34mCJS[39m Build start
|
|
11
|
+
[32mCJS[39m [1mdist/index.js [22m[32m43.15 KB[39m
|
|
12
|
+
[32mCJS[39m ⚡️ Build success in 145ms
|
|
13
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m41.89 KB[39m
|
|
14
|
+
[32mESM[39m ⚡️ Build success in 156ms
|
|
15
|
+
[34mDTS[39m Build start
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 3134ms
|
|
17
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m14.60 KB[39m
|
|
18
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m14.60 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @pluv/client
|
|
2
2
|
|
|
3
|
+
## 0.21.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- b98ab6b: Internal updates to platforms (i.e. `@pluv/platform-cloudflare` and `@pluv/platform-node`) to be able to support Cloudflare Worker Websocket Hibernation APIs.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- @pluv/crdt@0.21.0
|
|
12
|
+
- @pluv/types@0.21.0
|
|
13
|
+
|
|
3
14
|
## 0.20.0
|
|
4
15
|
|
|
5
16
|
### Minor Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -287,6 +287,6 @@ declare class PluvClient<TIO extends IOLike = IOLike> {
|
|
|
287
287
|
private _logDebug;
|
|
288
288
|
}
|
|
289
289
|
|
|
290
|
-
declare const createClient: <TIO extends IOLike
|
|
290
|
+
declare const createClient: <TIO extends IOLike = IOLike<_pluv_types.IOAuthorize<any, any, any>, {}>>(options: PluvClientOptions<TIO>) => PluvClient<TIO>;
|
|
291
291
|
|
|
292
292
|
export { AbstractRoom, AbstractStorageStore, ConnectionState, MockedRoom, type MockedRoomConfig, type MockedRoomEvents, PluvClient, type PluvClientOptions, PluvRoom, type PluvRoomAddon, type PluvRoomAddonInput, type PluvRoomAddonResult, type PluvRoomDebug, type UserInfo, type WebSocketConnection, type WebSocketState, createClient };
|
package/dist/index.d.ts
CHANGED
|
@@ -287,6 +287,6 @@ declare class PluvClient<TIO extends IOLike = IOLike> {
|
|
|
287
287
|
private _logDebug;
|
|
288
288
|
}
|
|
289
289
|
|
|
290
|
-
declare const createClient: <TIO extends IOLike
|
|
290
|
+
declare const createClient: <TIO extends IOLike = IOLike<_pluv_types.IOAuthorize<any, any, any>, {}>>(options: PluvClientOptions<TIO>) => PluvClient<TIO>;
|
|
291
291
|
|
|
292
292
|
export { AbstractRoom, AbstractStorageStore, ConnectionState, MockedRoom, type MockedRoomConfig, type MockedRoomEvents, PluvClient, type PluvClientOptions, PluvRoom, type PluvRoomAddon, type PluvRoomAddonInput, type PluvRoomAddonResult, type PluvRoomDebug, type UserInfo, type WebSocketConnection, type WebSocketState, createClient };
|
package/dist/index.js
CHANGED
|
@@ -1027,7 +1027,7 @@ var PluvRoom = class extends AbstractRoom {
|
|
|
1027
1027
|
_heartbeat() {
|
|
1028
1028
|
this._clearTimeout(this._timeouts.pong);
|
|
1029
1029
|
this._timeouts.pong = setTimeout(this._reconnect.bind(this), PONG_TIMEOUT_MS);
|
|
1030
|
-
this._sendMessage({
|
|
1030
|
+
this._sendMessage('{"type":"$PING","data":{}}');
|
|
1031
1031
|
}
|
|
1032
1032
|
_logDebug(...data) {
|
|
1033
1033
|
var _a;
|
|
@@ -1205,11 +1205,20 @@ var PluvRoom = class extends AbstractRoom {
|
|
|
1205
1205
|
_sendMessage(data) {
|
|
1206
1206
|
const webSocket = this._state.webSocket;
|
|
1207
1207
|
if ((webSocket == null ? void 0 : webSocket.readyState) !== WebSocket.OPEN) return;
|
|
1208
|
-
const
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1208
|
+
const dataType = (() => {
|
|
1209
|
+
var _a, _b, _c;
|
|
1210
|
+
if (typeof data === "object") return (_a = data.type) != null ? _a : null;
|
|
1211
|
+
if (typeof data !== "string") return null;
|
|
1212
|
+
try {
|
|
1213
|
+
return (_c = (_b = JSON.parse(data)) == null ? void 0 : _b.type) != null ? _c : null;
|
|
1214
|
+
} catch (e) {
|
|
1215
|
+
return null;
|
|
1216
|
+
}
|
|
1217
|
+
})();
|
|
1218
|
+
const shouldLog = typeof this._debug === "boolean" ? this._debug : !dataType ? false : this._debug.input.some((value) => value === data.type);
|
|
1219
|
+
if (shouldLog) this._logDebug("WebSocket event sent: ", data.type, data);
|
|
1220
|
+
const message = typeof data === "string" ? data : JSON.stringify(data);
|
|
1221
|
+
webSocket.send(message);
|
|
1213
1222
|
}
|
|
1214
1223
|
_updateState(updater) {
|
|
1215
1224
|
let authorization;
|
package/dist/index.mjs
CHANGED
|
@@ -998,7 +998,7 @@ var PluvRoom = class extends AbstractRoom {
|
|
|
998
998
|
_heartbeat() {
|
|
999
999
|
this._clearTimeout(this._timeouts.pong);
|
|
1000
1000
|
this._timeouts.pong = setTimeout(this._reconnect.bind(this), PONG_TIMEOUT_MS);
|
|
1001
|
-
this._sendMessage({
|
|
1001
|
+
this._sendMessage('{"type":"$PING","data":{}}');
|
|
1002
1002
|
}
|
|
1003
1003
|
_logDebug(...data) {
|
|
1004
1004
|
var _a;
|
|
@@ -1176,11 +1176,20 @@ var PluvRoom = class extends AbstractRoom {
|
|
|
1176
1176
|
_sendMessage(data) {
|
|
1177
1177
|
const webSocket = this._state.webSocket;
|
|
1178
1178
|
if ((webSocket == null ? void 0 : webSocket.readyState) !== WebSocket.OPEN) return;
|
|
1179
|
-
const
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1179
|
+
const dataType = (() => {
|
|
1180
|
+
var _a, _b, _c;
|
|
1181
|
+
if (typeof data === "object") return (_a = data.type) != null ? _a : null;
|
|
1182
|
+
if (typeof data !== "string") return null;
|
|
1183
|
+
try {
|
|
1184
|
+
return (_c = (_b = JSON.parse(data)) == null ? void 0 : _b.type) != null ? _c : null;
|
|
1185
|
+
} catch (e) {
|
|
1186
|
+
return null;
|
|
1187
|
+
}
|
|
1188
|
+
})();
|
|
1189
|
+
const shouldLog = typeof this._debug === "boolean" ? this._debug : !dataType ? false : this._debug.input.some((value) => value === data.type);
|
|
1190
|
+
if (shouldLog) this._logDebug("WebSocket event sent: ", data.type, data);
|
|
1191
|
+
const message = typeof data === "string" ? data : JSON.stringify(data);
|
|
1192
|
+
webSocket.send(message);
|
|
1184
1193
|
}
|
|
1185
1194
|
_updateState(updater) {
|
|
1186
1195
|
let authorization;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pluv/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.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.4",
|
|
21
|
-
"@pluv/crdt": "^0.
|
|
22
|
-
"@pluv/types": "^0.
|
|
21
|
+
"@pluv/crdt": "^0.21.0",
|
|
22
|
+
"@pluv/types": "^0.21.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"eslint": "^8.57.0",
|
|
26
|
-
"tsup": "^8.
|
|
27
|
-
"typescript": "^5.4
|
|
28
|
-
"@pluv/tsconfig": "^0.
|
|
29
|
-
"eslint-config-pluv": "^0.
|
|
26
|
+
"tsup": "^8.2.4",
|
|
27
|
+
"typescript": "^5.5.4",
|
|
28
|
+
"@pluv/tsconfig": "^0.21.0",
|
|
29
|
+
"eslint-config-pluv": "^0.21.0"
|
|
30
30
|
},
|
|
31
31
|
"scripts": {
|
|
32
32
|
"build": "tsup src/index.ts --format esm,cjs --dts",
|
package/src/PluvRoom.ts
CHANGED
|
@@ -763,7 +763,7 @@ export class PluvRoom<
|
|
|
763
763
|
this._stateNotifier.subjects["my-presence"].next(presence);
|
|
764
764
|
this._stateNotifier.subjects["myself"].next(myself);
|
|
765
765
|
|
|
766
|
-
const update = this._state.connection.count > 1 ? this._crdtManager.doc.getEncodedState() ?? null : null;
|
|
766
|
+
const update = this._state.connection.count > 1 ? (this._crdtManager.doc.getEncodedState() ?? null) : null;
|
|
767
767
|
|
|
768
768
|
this._sendMessage({
|
|
769
769
|
type: "$INITIALIZE_SESSION",
|
|
@@ -871,7 +871,13 @@ export class PluvRoom<
|
|
|
871
871
|
this._clearTimeout(this._timeouts.pong);
|
|
872
872
|
this._timeouts.pong = setTimeout(this._reconnect.bind(this), PONG_TIMEOUT_MS);
|
|
873
873
|
|
|
874
|
-
|
|
874
|
+
/**
|
|
875
|
+
* !HACK
|
|
876
|
+
* @description Send data as a stable string so that the server can react to this in a
|
|
877
|
+
* consistent way.
|
|
878
|
+
* @date July 8, 2024
|
|
879
|
+
*/
|
|
880
|
+
this._sendMessage('{"type":"$PING","data":{}}');
|
|
875
881
|
}
|
|
876
882
|
|
|
877
883
|
private _logDebug(...data: any[]): void {
|
|
@@ -1092,19 +1098,36 @@ export class PluvRoom<
|
|
|
1092
1098
|
await this.connect();
|
|
1093
1099
|
}
|
|
1094
1100
|
|
|
1095
|
-
private _sendMessage
|
|
1101
|
+
private _sendMessage(data: string): void;
|
|
1102
|
+
private _sendMessage<TMessage extends EventMessage<string, any> = EventMessage<string, any>>(data: TMessage): void;
|
|
1103
|
+
private _sendMessage(data: any): void {
|
|
1096
1104
|
const webSocket = this._state.webSocket;
|
|
1097
1105
|
|
|
1098
1106
|
if (webSocket?.readyState !== WebSocket.OPEN) return;
|
|
1099
1107
|
|
|
1100
|
-
const
|
|
1101
|
-
typeof
|
|
1108
|
+
const dataType: string | null = ((): string | null => {
|
|
1109
|
+
if (typeof data === "object") return data.type ?? null;
|
|
1110
|
+
if (typeof data !== "string") return null;
|
|
1102
1111
|
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1112
|
+
try {
|
|
1113
|
+
return JSON.parse(data)?.type ?? null;
|
|
1114
|
+
} catch {
|
|
1115
|
+
return null;
|
|
1116
|
+
}
|
|
1117
|
+
})();
|
|
1118
|
+
|
|
1119
|
+
const shouldLog: boolean =
|
|
1120
|
+
typeof this._debug === "boolean"
|
|
1121
|
+
? this._debug
|
|
1122
|
+
: !dataType
|
|
1123
|
+
? false
|
|
1124
|
+
: this._debug.input.some((value) => value === data.type);
|
|
1125
|
+
|
|
1126
|
+
if (shouldLog) this._logDebug("WebSocket event sent: ", data.type, data);
|
|
1127
|
+
|
|
1128
|
+
const message = typeof data === "string" ? data : JSON.stringify(data);
|
|
1106
1129
|
|
|
1107
|
-
webSocket.send(
|
|
1130
|
+
webSocket.send(message);
|
|
1108
1131
|
}
|
|
1109
1132
|
|
|
1110
1133
|
private _updateState(updater: (oldState: WebSocketState<TIO>) => WebSocketState<TIO>): WebSocketState<TIO> {
|