@pluv/client 0.37.0 → 0.37.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.
- package/.turbo/turbo-build.log +8 -8
- package/CHANGELOG.md +33 -0
- package/dist/index.d.mts +8 -3
- package/dist/index.d.ts +8 -3
- package/dist/index.js +9 -3
- package/dist/index.mjs +9 -3
- package/package.json +6 -6
- package/src/PluvClient.ts +2 -1
- package/src/PluvRoom.ts +15 -5
- package/src/index.ts +1 -1
- package/src/types.ts +5 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @pluv/client@0.37.
|
|
2
|
+
> @pluv/client@0.37.2 build /home/runner/work/pluv/pluv/packages/client
|
|
3
3
|
> tsup src/index.ts --format esm,cjs --dts
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
@@ -8,11 +8,11 @@
|
|
|
8
8
|
[34mCLI[39m Target: es6
|
|
9
9
|
[34mESM[39m Build start
|
|
10
10
|
[34mCJS[39m Build start
|
|
11
|
-
[
|
|
12
|
-
[
|
|
13
|
-
[
|
|
14
|
-
[
|
|
11
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m47.50 KB[39m
|
|
12
|
+
[32mESM[39m ⚡️ Build success in 134ms
|
|
13
|
+
[32mCJS[39m [1mdist/index.js [22m[32m48.82 KB[39m
|
|
14
|
+
[32mCJS[39m ⚡️ Build success in 135ms
|
|
15
15
|
[34mDTS[39m Build start
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
17
|
-
[32mDTS[39m [1mdist/index.d.mts [22m[
|
|
18
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 3258ms
|
|
17
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m23.10 KB[39m
|
|
18
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m23.10 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
1
|
# @pluv/client
|
|
2
2
|
|
|
3
|
+
## 0.37.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 11920af: Updated the default `wsEndpoint` for `PluvClient` when `publicKey` is provided to be correct.
|
|
8
|
+
- @pluv/crdt@0.37.2
|
|
9
|
+
- @pluv/types@0.37.2
|
|
10
|
+
|
|
11
|
+
## 0.37.1
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- e923a8d: Added support for specifying the `publicKey` param for `createClient` as a function with metadata. This is particularly useful for non-static Next.js applications built with Cloudflare Pages.
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { createClient } from "@pluv/client";
|
|
19
|
+
import { z } from "zod";
|
|
20
|
+
|
|
21
|
+
export const client = createClient({
|
|
22
|
+
// Can be a string
|
|
23
|
+
publicKey: "pk_abc123...",
|
|
24
|
+
|
|
25
|
+
// Or can be a function
|
|
26
|
+
metadata: z.object({
|
|
27
|
+
publicKey: z.string().min(1, "Required"),
|
|
28
|
+
}),
|
|
29
|
+
publicKey: ({ metadata }) => metadata.publicKey,
|
|
30
|
+
});
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
- @pluv/crdt@0.37.1
|
|
34
|
+
- @pluv/types@0.37.1
|
|
35
|
+
|
|
3
36
|
## 0.37.0
|
|
4
37
|
|
|
5
38
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -31,6 +31,10 @@ type MergeEventRecords<TEventRecords extends EventRecord<string, any>[], TRoot e
|
|
|
31
31
|
] ? MergeEventRecords<ITail, Omit<TRoot, keyof IHead> & {
|
|
32
32
|
[P in keyof IHead]: TRoot extends Record<P, any> ? TRoot[P] | IHead[P] : IHead[P];
|
|
33
33
|
}> : Id<TRoot>;
|
|
34
|
+
interface PublicKeyParams<TMetadata extends JsonObject> {
|
|
35
|
+
metadata: TMetadata;
|
|
36
|
+
}
|
|
37
|
+
type PublicKey<TMetadata extends JsonObject> = string | ((params: PublicKeyParams<TMetadata>) => string);
|
|
34
38
|
type UpdateMyPresenceAction<TPresence extends JsonObject> = Partial<TPresence> | ((oldPresence: TPresence | null) => Partial<TPresence>);
|
|
35
39
|
interface UserInfo<TIO extends IOLike, TPresence extends JsonObject = {}> {
|
|
36
40
|
connectionId: string;
|
|
@@ -190,7 +194,7 @@ type RoomConfig<TIO extends IOLike, TMetadata extends JsonObject = {}, TPresence
|
|
|
190
194
|
addons?: readonly PluvRoomAddon<TIO, TMetadata, TPresence, TStorage>[];
|
|
191
195
|
debug?: boolean | PluvRoomDebug<TIO>;
|
|
192
196
|
onAuthorizationFail?: (error: Error) => void;
|
|
193
|
-
publicKey?:
|
|
197
|
+
publicKey?: PublicKey<TMetadata>;
|
|
194
198
|
router?: PluvRouter<TIO, TPresence, TStorage, TEvents>;
|
|
195
199
|
} & RoomEndpoints<TIO, TMetadata> & Pick<CrdtManagerOptions<TStorage>, "initialStorage"> & UsersManagerConfig<TPresence> & (keyof TMetadata extends never ? {
|
|
196
200
|
metadata?: undefined;
|
|
@@ -257,6 +261,7 @@ declare class PluvRoom<TIO extends IOLike<any, any>, TMetadata extends JsonObjec
|
|
|
257
261
|
private _getAddon;
|
|
258
262
|
private _getAuthFetchOptions;
|
|
259
263
|
private _getAuthorization;
|
|
264
|
+
private _getPublicKey;
|
|
260
265
|
private _getWsEndpoint;
|
|
261
266
|
private _handleExit;
|
|
262
267
|
private _handlePresenceUpdatedMessage;
|
|
@@ -299,7 +304,7 @@ type PluvClientOptions<TIO extends IOLike<any, any>, TPresence extends JsonObjec
|
|
|
299
304
|
initialStorage?: AbstractCrdtDocFactory<TStorage>;
|
|
300
305
|
metadata?: InputZodLike<TMetadata>;
|
|
301
306
|
presence?: InputZodLike<TPresence>;
|
|
302
|
-
publicKey?:
|
|
307
|
+
publicKey?: PublicKey<TMetadata>;
|
|
303
308
|
types: InferCallback<TIO>;
|
|
304
309
|
};
|
|
305
310
|
type CreateRoomOptions<TIO extends IOLike<any, any>, TPresence extends JsonObject, TStorage extends Record<string, CrdtType<any, any>>, TMetadata extends JsonObject, TEvents extends PluvRouterEventConfig<TIO, TPresence, TStorage> = {}> = {
|
|
@@ -393,4 +398,4 @@ declare const register: <TMetadata extends JsonObject>(params: RegisterParams<TM
|
|
|
393
398
|
wsEndpoint: (params: EndpointParams<TMetadata>) => string;
|
|
394
399
|
};
|
|
395
400
|
|
|
396
|
-
export { AbstractRoom, AbstractStorageStore, ConnectionState, type CreateRoomOptions, type InferCallback, type MergeEvents, MockedRoom, type MockedRoomConfig, type MockedRoomEvents, PluvClient, type PluvClientOptions, type PluvProcedureConfig, PluvRoom, type PluvRoomAddon, type PluvRoomAddonInput, type PluvRoomAddonResult, type PluvRoomDebug, PluvRouter, type PluvRouterEventConfig, type RegisterParams, type RoomEndpoints, type UserInfo, type WebSocketConnection, type WebSocketState, createClient, infer, register };
|
|
401
|
+
export { AbstractRoom, AbstractStorageStore, ConnectionState, type CreateRoomOptions, type InferCallback, type MergeEvents, MockedRoom, type MockedRoomConfig, type MockedRoomEvents, PluvClient, type PluvClientOptions, type PluvProcedureConfig, PluvRoom, type PluvRoomAddon, type PluvRoomAddonInput, type PluvRoomAddonResult, type PluvRoomDebug, PluvRouter, type PluvRouterEventConfig, type PublicKey, type PublicKeyParams, type RegisterParams, type RoomEndpoints, type UserInfo, type WebSocketConnection, type WebSocketState, createClient, infer, register };
|
package/dist/index.d.ts
CHANGED
|
@@ -31,6 +31,10 @@ type MergeEventRecords<TEventRecords extends EventRecord<string, any>[], TRoot e
|
|
|
31
31
|
] ? MergeEventRecords<ITail, Omit<TRoot, keyof IHead> & {
|
|
32
32
|
[P in keyof IHead]: TRoot extends Record<P, any> ? TRoot[P] | IHead[P] : IHead[P];
|
|
33
33
|
}> : Id<TRoot>;
|
|
34
|
+
interface PublicKeyParams<TMetadata extends JsonObject> {
|
|
35
|
+
metadata: TMetadata;
|
|
36
|
+
}
|
|
37
|
+
type PublicKey<TMetadata extends JsonObject> = string | ((params: PublicKeyParams<TMetadata>) => string);
|
|
34
38
|
type UpdateMyPresenceAction<TPresence extends JsonObject> = Partial<TPresence> | ((oldPresence: TPresence | null) => Partial<TPresence>);
|
|
35
39
|
interface UserInfo<TIO extends IOLike, TPresence extends JsonObject = {}> {
|
|
36
40
|
connectionId: string;
|
|
@@ -190,7 +194,7 @@ type RoomConfig<TIO extends IOLike, TMetadata extends JsonObject = {}, TPresence
|
|
|
190
194
|
addons?: readonly PluvRoomAddon<TIO, TMetadata, TPresence, TStorage>[];
|
|
191
195
|
debug?: boolean | PluvRoomDebug<TIO>;
|
|
192
196
|
onAuthorizationFail?: (error: Error) => void;
|
|
193
|
-
publicKey?:
|
|
197
|
+
publicKey?: PublicKey<TMetadata>;
|
|
194
198
|
router?: PluvRouter<TIO, TPresence, TStorage, TEvents>;
|
|
195
199
|
} & RoomEndpoints<TIO, TMetadata> & Pick<CrdtManagerOptions<TStorage>, "initialStorage"> & UsersManagerConfig<TPresence> & (keyof TMetadata extends never ? {
|
|
196
200
|
metadata?: undefined;
|
|
@@ -257,6 +261,7 @@ declare class PluvRoom<TIO extends IOLike<any, any>, TMetadata extends JsonObjec
|
|
|
257
261
|
private _getAddon;
|
|
258
262
|
private _getAuthFetchOptions;
|
|
259
263
|
private _getAuthorization;
|
|
264
|
+
private _getPublicKey;
|
|
260
265
|
private _getWsEndpoint;
|
|
261
266
|
private _handleExit;
|
|
262
267
|
private _handlePresenceUpdatedMessage;
|
|
@@ -299,7 +304,7 @@ type PluvClientOptions<TIO extends IOLike<any, any>, TPresence extends JsonObjec
|
|
|
299
304
|
initialStorage?: AbstractCrdtDocFactory<TStorage>;
|
|
300
305
|
metadata?: InputZodLike<TMetadata>;
|
|
301
306
|
presence?: InputZodLike<TPresence>;
|
|
302
|
-
publicKey?:
|
|
307
|
+
publicKey?: PublicKey<TMetadata>;
|
|
303
308
|
types: InferCallback<TIO>;
|
|
304
309
|
};
|
|
305
310
|
type CreateRoomOptions<TIO extends IOLike<any, any>, TPresence extends JsonObject, TStorage extends Record<string, CrdtType<any, any>>, TMetadata extends JsonObject, TEvents extends PluvRouterEventConfig<TIO, TPresence, TStorage> = {}> = {
|
|
@@ -393,4 +398,4 @@ declare const register: <TMetadata extends JsonObject>(params: RegisterParams<TM
|
|
|
393
398
|
wsEndpoint: (params: EndpointParams<TMetadata>) => string;
|
|
394
399
|
};
|
|
395
400
|
|
|
396
|
-
export { AbstractRoom, AbstractStorageStore, ConnectionState, type CreateRoomOptions, type InferCallback, type MergeEvents, MockedRoom, type MockedRoomConfig, type MockedRoomEvents, PluvClient, type PluvClientOptions, type PluvProcedureConfig, PluvRoom, type PluvRoomAddon, type PluvRoomAddonInput, type PluvRoomAddonResult, type PluvRoomDebug, PluvRouter, type PluvRouterEventConfig, type RegisterParams, type RoomEndpoints, type UserInfo, type WebSocketConnection, type WebSocketState, createClient, infer, register };
|
|
401
|
+
export { AbstractRoom, AbstractStorageStore, ConnectionState, type CreateRoomOptions, type InferCallback, type MergeEvents, MockedRoom, type MockedRoomConfig, type MockedRoomEvents, PluvClient, type PluvClientOptions, type PluvProcedureConfig, PluvRoom, type PluvRoomAddon, type PluvRoomAddonInput, type PluvRoomAddonResult, type PluvRoomDebug, PluvRouter, type PluvRouterEventConfig, type PublicKey, type PublicKeyParams, type RegisterParams, type RoomEndpoints, type UserInfo, type WebSocketConnection, type WebSocketState, createClient, infer, register };
|
package/dist/index.js
CHANGED
|
@@ -617,7 +617,7 @@ var PluvRoom = class extends AbstractRoom {
|
|
|
617
617
|
this._endpoints = { authEndpoint, wsEndpoint };
|
|
618
618
|
this._storageStore = storage;
|
|
619
619
|
if (typeof metadata !== "undefined") this._metadata = metadata;
|
|
620
|
-
if (
|
|
620
|
+
if (!!publicKey) this._publicKey = publicKey;
|
|
621
621
|
this._listeners = {
|
|
622
622
|
onAuthorizationFail: (error) => {
|
|
623
623
|
this._clearTimeout(this._timeouts.reconnect);
|
|
@@ -655,9 +655,10 @@ var PluvRoom = class extends AbstractRoom {
|
|
|
655
655
|
let authToken = null;
|
|
656
656
|
let webSocket;
|
|
657
657
|
try {
|
|
658
|
+
const publicKey = this._getPublicKey();
|
|
658
659
|
authToken = yield this._getAuthorization(this.id);
|
|
659
660
|
authToken && url.searchParams.set("token", encodeURIComponent(authToken));
|
|
660
|
-
|
|
661
|
+
publicKey && url.searchParams.set("public_key", encodeURIComponent(publicKey));
|
|
661
662
|
webSocket = new WebSocket(url.toString());
|
|
662
663
|
} catch (err) {
|
|
663
664
|
yield this._storageStore.destroy();
|
|
@@ -830,10 +831,15 @@ var PluvRoom = class extends AbstractRoom {
|
|
|
830
831
|
}
|
|
831
832
|
});
|
|
832
833
|
}
|
|
834
|
+
_getPublicKey() {
|
|
835
|
+
if (!this._publicKey) return null;
|
|
836
|
+
if (typeof this._publicKey === "string") return this._publicKey;
|
|
837
|
+
return this._publicKey({ metadata: this._metadata });
|
|
838
|
+
}
|
|
833
839
|
_getWsEndpoint(room) {
|
|
834
840
|
switch (typeof this._endpoints.wsEndpoint) {
|
|
835
841
|
case "undefined":
|
|
836
|
-
return `/api/pluv/room/${room}`;
|
|
842
|
+
return !!this._getPublicKey() ? `https://rooms.pluv.io/${room}` : `/api/pluv/room/${room}`;
|
|
837
843
|
case "string":
|
|
838
844
|
return this._endpoints.wsEndpoint;
|
|
839
845
|
default:
|
package/dist/index.mjs
CHANGED
|
@@ -586,7 +586,7 @@ var PluvRoom = class extends AbstractRoom {
|
|
|
586
586
|
this._endpoints = { authEndpoint, wsEndpoint };
|
|
587
587
|
this._storageStore = storage;
|
|
588
588
|
if (typeof metadata !== "undefined") this._metadata = metadata;
|
|
589
|
-
if (
|
|
589
|
+
if (!!publicKey) this._publicKey = publicKey;
|
|
590
590
|
this._listeners = {
|
|
591
591
|
onAuthorizationFail: (error) => {
|
|
592
592
|
this._clearTimeout(this._timeouts.reconnect);
|
|
@@ -624,9 +624,10 @@ var PluvRoom = class extends AbstractRoom {
|
|
|
624
624
|
let authToken = null;
|
|
625
625
|
let webSocket;
|
|
626
626
|
try {
|
|
627
|
+
const publicKey = this._getPublicKey();
|
|
627
628
|
authToken = yield this._getAuthorization(this.id);
|
|
628
629
|
authToken && url.searchParams.set("token", encodeURIComponent(authToken));
|
|
629
|
-
|
|
630
|
+
publicKey && url.searchParams.set("public_key", encodeURIComponent(publicKey));
|
|
630
631
|
webSocket = new WebSocket(url.toString());
|
|
631
632
|
} catch (err) {
|
|
632
633
|
yield this._storageStore.destroy();
|
|
@@ -799,10 +800,15 @@ var PluvRoom = class extends AbstractRoom {
|
|
|
799
800
|
}
|
|
800
801
|
});
|
|
801
802
|
}
|
|
803
|
+
_getPublicKey() {
|
|
804
|
+
if (!this._publicKey) return null;
|
|
805
|
+
if (typeof this._publicKey === "string") return this._publicKey;
|
|
806
|
+
return this._publicKey({ metadata: this._metadata });
|
|
807
|
+
}
|
|
802
808
|
_getWsEndpoint(room) {
|
|
803
809
|
switch (typeof this._endpoints.wsEndpoint) {
|
|
804
810
|
case "undefined":
|
|
805
|
-
return `/api/pluv/room/${room}`;
|
|
811
|
+
return !!this._getPublicKey() ? `https://rooms.pluv.io/${room}` : `/api/pluv/room/${room}`;
|
|
806
812
|
case "string":
|
|
807
813
|
return this._endpoints.wsEndpoint;
|
|
808
814
|
default:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pluv/client",
|
|
3
|
-
"version": "0.37.
|
|
3
|
+
"version": "0.37.2",
|
|
4
4
|
"description": "@pluv/io frontend client",
|
|
5
5
|
"author": "leedavidcs",
|
|
6
6
|
"license": "MIT",
|
|
@@ -17,16 +17,16 @@
|
|
|
17
17
|
"access": "public"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"wonka": "^6.3.
|
|
21
|
-
"@pluv/crdt": "^0.37.
|
|
22
|
-
"@pluv/types": "^0.37.
|
|
20
|
+
"wonka": "^6.3.5",
|
|
21
|
+
"@pluv/crdt": "^0.37.2",
|
|
22
|
+
"@pluv/types": "^0.37.2"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"eslint": "^8.57.1",
|
|
26
26
|
"tsup": "^8.4.0",
|
|
27
27
|
"typescript": "^5.8.2",
|
|
28
|
-
"@pluv/tsconfig": "^0.37.
|
|
29
|
-
"eslint-config-pluv": "^0.37.
|
|
28
|
+
"@pluv/tsconfig": "^0.37.2",
|
|
29
|
+
"eslint-config-pluv": "^0.37.2"
|
|
30
30
|
},
|
|
31
31
|
"scripts": {
|
|
32
32
|
"build": "tsup src/index.ts --format esm,cjs --dts",
|
package/src/PluvClient.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type { AuthEndpoint, PluvRoomAddon, PluvRoomDebug, RoomConfig, RoomEndpoi
|
|
|
6
6
|
import { PluvRoom } from "./PluvRoom";
|
|
7
7
|
import type { PluvRouterEventConfig } from "./PluvRouter";
|
|
8
8
|
import { PluvRouter } from "./PluvRouter";
|
|
9
|
+
import type { PublicKey } from "./types";
|
|
9
10
|
|
|
10
11
|
export type PluvClientOptions<
|
|
11
12
|
TIO extends IOLike<any, any>,
|
|
@@ -17,7 +18,7 @@ export type PluvClientOptions<
|
|
|
17
18
|
initialStorage?: AbstractCrdtDocFactory<TStorage>;
|
|
18
19
|
metadata?: InputZodLike<TMetadata>;
|
|
19
20
|
presence?: InputZodLike<TPresence>;
|
|
20
|
-
publicKey?:
|
|
21
|
+
publicKey?: PublicKey<TMetadata>;
|
|
21
22
|
types: InferCallback<TIO>;
|
|
22
23
|
};
|
|
23
24
|
|
package/src/PluvRoom.ts
CHANGED
|
@@ -35,6 +35,7 @@ import type {
|
|
|
35
35
|
EventResolver,
|
|
36
36
|
EventResolverContext,
|
|
37
37
|
InternalSubscriptions,
|
|
38
|
+
PublicKey,
|
|
38
39
|
UpdateMyPresenceAction,
|
|
39
40
|
UserInfo,
|
|
40
41
|
WebSocketConnection,
|
|
@@ -147,7 +148,7 @@ export type RoomConfig<
|
|
|
147
148
|
addons?: readonly PluvRoomAddon<TIO, TMetadata, TPresence, TStorage>[];
|
|
148
149
|
debug?: boolean | PluvRoomDebug<TIO>;
|
|
149
150
|
onAuthorizationFail?: (error: Error) => void;
|
|
150
|
-
publicKey?:
|
|
151
|
+
publicKey?: PublicKey<TMetadata>;
|
|
151
152
|
router?: PluvRouter<TIO, TPresence, TStorage, TEvents>;
|
|
152
153
|
} & RoomEndpoints<TIO, TMetadata> &
|
|
153
154
|
Pick<CrdtManagerOptions<TStorage>, "initialStorage"> &
|
|
@@ -174,7 +175,7 @@ export class PluvRoom<
|
|
|
174
175
|
private readonly _listeners: InternalListeners;
|
|
175
176
|
private readonly _metadata: TMetadata = {} as TMetadata;
|
|
176
177
|
private readonly _otherNotifier = new OtherNotifier<TIO>();
|
|
177
|
-
private readonly _publicKey:
|
|
178
|
+
private readonly _publicKey: PublicKey<TMetadata> | null = null;
|
|
178
179
|
private readonly _router: PluvRouter<TIO, TPresence, TStorage, TEvents>;
|
|
179
180
|
private readonly _stateNotifier = new StateNotifier<TIO, TPresence>();
|
|
180
181
|
private readonly _storageStore: AbstractStorageStore;
|
|
@@ -231,7 +232,7 @@ export class PluvRoom<
|
|
|
231
232
|
this._storageStore = storage;
|
|
232
233
|
|
|
233
234
|
if (typeof metadata !== "undefined") this._metadata = metadata;
|
|
234
|
-
if (
|
|
235
|
+
if (!!publicKey) this._publicKey = publicKey;
|
|
235
236
|
|
|
236
237
|
this._listeners = {
|
|
237
238
|
onAuthorizationFail: (error) => {
|
|
@@ -350,10 +351,12 @@ export class PluvRoom<
|
|
|
350
351
|
let webSocket: WebSocket;
|
|
351
352
|
|
|
352
353
|
try {
|
|
354
|
+
const publicKey = this._getPublicKey();
|
|
355
|
+
|
|
353
356
|
authToken = await this._getAuthorization(this.id);
|
|
354
357
|
|
|
355
358
|
authToken && url.searchParams.set("token", encodeURIComponent(authToken));
|
|
356
|
-
|
|
359
|
+
publicKey && url.searchParams.set("public_key", encodeURIComponent(publicKey));
|
|
357
360
|
|
|
358
361
|
webSocket = new WebSocket(url.toString());
|
|
359
362
|
} catch (err) {
|
|
@@ -734,10 +737,17 @@ export class PluvRoom<
|
|
|
734
737
|
}
|
|
735
738
|
}
|
|
736
739
|
|
|
740
|
+
private _getPublicKey(): string | null {
|
|
741
|
+
if (!this._publicKey) return null;
|
|
742
|
+
if (typeof this._publicKey === "string") return this._publicKey;
|
|
743
|
+
|
|
744
|
+
return this._publicKey({ metadata: this._metadata });
|
|
745
|
+
}
|
|
746
|
+
|
|
737
747
|
private _getWsEndpoint(room: string): string {
|
|
738
748
|
switch (typeof this._endpoints.wsEndpoint) {
|
|
739
749
|
case "undefined":
|
|
740
|
-
return `/api/pluv/room/${room}`;
|
|
750
|
+
return !!this._getPublicKey() ? `https://rooms.pluv.io/${room}` : `/api/pluv/room/${room}`;
|
|
741
751
|
case "string":
|
|
742
752
|
return this._endpoints.wsEndpoint;
|
|
743
753
|
default:
|
package/src/index.ts
CHANGED
|
@@ -16,4 +16,4 @@ export type { PluvRoomAddon, PluvRoomAddonInput, PluvRoomAddonResult, PluvRoomDe
|
|
|
16
16
|
export type { MergeEvents, PluvRouter, PluvRouterEventConfig } from "./PluvRouter";
|
|
17
17
|
export { register } from "./register";
|
|
18
18
|
export type { RegisterParams } from "./register";
|
|
19
|
-
export type { UserInfo, WebSocketConnection, WebSocketState } from "./types";
|
|
19
|
+
export type { PublicKey, PublicKeyParams, UserInfo, WebSocketConnection, WebSocketState } from "./types";
|
package/src/types.ts
CHANGED
|
@@ -53,6 +53,11 @@ export type MergeEventRecords<
|
|
|
53
53
|
>
|
|
54
54
|
: Id<TRoot>;
|
|
55
55
|
|
|
56
|
+
export interface PublicKeyParams<TMetadata extends JsonObject> {
|
|
57
|
+
metadata: TMetadata;
|
|
58
|
+
}
|
|
59
|
+
export type PublicKey<TMetadata extends JsonObject> = string | ((params: PublicKeyParams<TMetadata>) => string);
|
|
60
|
+
|
|
56
61
|
export type UpdateMyPresenceAction<TPresence extends JsonObject> =
|
|
57
62
|
| Partial<TPresence>
|
|
58
63
|
| ((oldPresence: TPresence | null) => Partial<TPresence>);
|