@websimai/socket-types 0.0.2 → 0.0.3
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/dist/index.d.mts +215 -0
- package/dist/index.mjs +1 -0
- package/package.json +26 -10
- package/LICENSE +0 -21
- package/src/globals.d.ts +0 -13
- package/src/index.d.ts +0 -4
- package/src/types/collection-api.d.ts +0 -70
- package/src/types/index.d.ts +0 -2
- package/src/types/query-api.d.ts +0 -7
- package/src/types/utils/index.d.ts +0 -3
- package/src/websim-socket-party.d.ts +0 -61
- package/src/websim-socket.d.ts +0 -134
- package/tsconfig.json +0 -31
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
//#region src/types/utils/index.d.ts
|
|
2
|
+
type Expand<T> = T extends infer O ? { [K in keyof O]: O[K] } : never;
|
|
3
|
+
type KeyValue = Record<string, any>;
|
|
4
|
+
//#endregion
|
|
5
|
+
//#region src/types/collection-api.d.ts
|
|
6
|
+
interface CollectionAPI<T extends string> {
|
|
7
|
+
getList: <TData extends KeyValue>() => Expand<TData & {
|
|
8
|
+
readonly id: string;
|
|
9
|
+
readonly $type: T;
|
|
10
|
+
readonly created_at: string;
|
|
11
|
+
readonly updated_at: string;
|
|
12
|
+
readonly user_id: string;
|
|
13
|
+
readonly username: string;
|
|
14
|
+
}>[];
|
|
15
|
+
create: <TData extends KeyValue>(data: TData) => Promise<Expand<TData & {
|
|
16
|
+
readonly id: string;
|
|
17
|
+
readonly $type: T;
|
|
18
|
+
readonly created_at: string;
|
|
19
|
+
readonly username: string;
|
|
20
|
+
}>>;
|
|
21
|
+
update: <T_Id extends string, TData extends KeyValue>(id: T_Id, data: TData) => Promise<Expand<TData & {
|
|
22
|
+
readonly id: T_Id;
|
|
23
|
+
readonly $type: T;
|
|
24
|
+
readonly created_at: string;
|
|
25
|
+
readonly username: string;
|
|
26
|
+
}>>;
|
|
27
|
+
upsert: <TData extends KeyValue & {
|
|
28
|
+
id?: T_Id;
|
|
29
|
+
}, T_Id extends string = string>(data: TData) => Promise<Expand<(TData extends {
|
|
30
|
+
id: T_Id;
|
|
31
|
+
} ? TData & KeyValue : TData) & {
|
|
32
|
+
readonly id: T_Id;
|
|
33
|
+
readonly $type: T;
|
|
34
|
+
readonly created_at: string;
|
|
35
|
+
readonly username: string;
|
|
36
|
+
}>>;
|
|
37
|
+
delete: (id: string) => Promise<void>;
|
|
38
|
+
subscribe: (callback: (records: Expand<KeyValue & {
|
|
39
|
+
id: string;
|
|
40
|
+
$type: T;
|
|
41
|
+
created_at: string;
|
|
42
|
+
updated_at: string;
|
|
43
|
+
user_id: string;
|
|
44
|
+
username: string;
|
|
45
|
+
}>[]) => void) => () => void;
|
|
46
|
+
filter: (filters: KeyValue) => CollectionAPI<T>;
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/types/peers.d.ts
|
|
50
|
+
type Peers = {
|
|
51
|
+
readonly [clientId: string]: {
|
|
52
|
+
readonly avatarUrl: string;
|
|
53
|
+
readonly username: string;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region src/types/query-api.d.ts
|
|
58
|
+
interface QueryAPI<T extends readonly KeyValue[] = readonly KeyValue[]> extends PromiseLike<T> {
|
|
59
|
+
getList(): Promise<T>;
|
|
60
|
+
subscribe(callback: (records: T) => void): () => void;
|
|
61
|
+
}
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region src/websim-socket-party.d.ts
|
|
64
|
+
interface WebsimSocketParty {
|
|
65
|
+
/**
|
|
66
|
+
* Object containing the client ID, avatar URL, and username of this connected client.
|
|
67
|
+
*/
|
|
68
|
+
readonly client: {
|
|
69
|
+
readonly id: string;
|
|
70
|
+
readonly avatarUrl: `https://${string}/${string}`;
|
|
71
|
+
readonly username: string;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Object containing all connected peers, including this client.
|
|
75
|
+
* This is always up-to-date.
|
|
76
|
+
*/
|
|
77
|
+
readonly peers: {
|
|
78
|
+
[id: string]: {
|
|
79
|
+
readonly avatarUrl: `https://${string}/${string}`;
|
|
80
|
+
readonly username: string;
|
|
81
|
+
readonly id: string;
|
|
82
|
+
readonly is_anonymous: boolean;
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
subscribe: (callback: (peers: Peers) => void) => () => void;
|
|
86
|
+
/**
|
|
87
|
+
* Object containing the current presence state of all connected peers, including this client.
|
|
88
|
+
* This is always up-to-date after initialization.
|
|
89
|
+
*/
|
|
90
|
+
readonly presence: KeyValue;
|
|
91
|
+
/**
|
|
92
|
+
* Updates the current client's presence state.
|
|
93
|
+
* @param presence The new presence state to set.
|
|
94
|
+
*/
|
|
95
|
+
updatePresence<TPresence extends KeyValue>(presence: TPresence): void;
|
|
96
|
+
/**
|
|
97
|
+
* Subscribe to presence updates from all peers.
|
|
98
|
+
* @param callback Function to call when presence changes.
|
|
99
|
+
* @returns Function to unsubscribe.
|
|
100
|
+
*/
|
|
101
|
+
subscribePresence<TPresence extends KeyValue>(callback: (presence: {
|
|
102
|
+
[clientId: string]: TPresence;
|
|
103
|
+
}) => void): () => void;
|
|
104
|
+
/**
|
|
105
|
+
* Object containing the current room-wide state.
|
|
106
|
+
* This is always up-to-date.
|
|
107
|
+
*/
|
|
108
|
+
readonly roomState: KeyValue;
|
|
109
|
+
}
|
|
110
|
+
//#endregion
|
|
111
|
+
//#region src/websim-socket.d.ts
|
|
112
|
+
declare class WebsimSocketClass {
|
|
113
|
+
constructor();
|
|
114
|
+
readonly CONNECTING: 0;
|
|
115
|
+
readonly OPEN: 1;
|
|
116
|
+
readonly CLOSING: 2;
|
|
117
|
+
readonly CLOSED: 3;
|
|
118
|
+
readonly binaryType: "arraybuffer" | (string & {});
|
|
119
|
+
readonly bufferedAmount: number;
|
|
120
|
+
readonly extensions: string;
|
|
121
|
+
readonly protocol: "ws" | "wss";
|
|
122
|
+
readonly readyState: 0 | 1 | 2 | 3;
|
|
123
|
+
readonly url: string;
|
|
124
|
+
accept(): void;
|
|
125
|
+
serializeAttachment(): void;
|
|
126
|
+
deserializeAttachment(): void;
|
|
127
|
+
onclose: ((this: WebSocket, ev: CloseEvent) => any) | null;
|
|
128
|
+
onerror: ((this: WebSocket, ev: Event) => any) | null;
|
|
129
|
+
onmessage: ((this: WebSocket, ev: MessageEvent) => any) | null;
|
|
130
|
+
onopen: ((this: WebSocket, ev: Event) => any) | null;
|
|
131
|
+
dispatchEvent(event: Event | MessageEvent | CloseEvent | ErrorEvent): boolean;
|
|
132
|
+
close(_code?: number, _reason?: string): void;
|
|
133
|
+
send<TData extends string | object>(data: TData): void;
|
|
134
|
+
query<TParams extends unknown = unknown>(queryString: string, params?: TParams[]): QueryAPI;
|
|
135
|
+
collection<T extends string>($type: T): CollectionAPI<T>;
|
|
136
|
+
readonly clientId: string;
|
|
137
|
+
/**
|
|
138
|
+
* Object containing information about the connected client and their peers.
|
|
139
|
+
*/
|
|
140
|
+
readonly party: WebsimSocketParty;
|
|
141
|
+
/**
|
|
142
|
+
* Legacy event handler for changes in connected peers.
|
|
143
|
+
* @param peers An object with client IDs as keys, each containing the client's avatar URL and username.
|
|
144
|
+
*/
|
|
145
|
+
onPeersChanged: ((peers: Peers) => any) | null;
|
|
146
|
+
/**
|
|
147
|
+
* Initialize the WebSocket connection.
|
|
148
|
+
* @returns A promise that resolves when initialization is complete.
|
|
149
|
+
*/
|
|
150
|
+
initialize(): Promise<void>;
|
|
151
|
+
/**
|
|
152
|
+
* Request a presence update from a specific client.
|
|
153
|
+
* @param clientId The ID of the client to request an update from.
|
|
154
|
+
* @param update The update to request.
|
|
155
|
+
*/
|
|
156
|
+
requestPresenceUpdate(clientId: string, update: KeyValue): void;
|
|
157
|
+
/**
|
|
158
|
+
* Subscribe to presence update requests from other clients.
|
|
159
|
+
* @param callback Function to call when a presence update is requested.
|
|
160
|
+
* @returns Function to unsubscribe.
|
|
161
|
+
*/
|
|
162
|
+
subscribePresenceUpdateRequests<TUpdateRequest extends KeyValue>(callback: (updateRequest: TUpdateRequest, fromClientId: string) => void): () => void;
|
|
163
|
+
/**
|
|
164
|
+
* Updates the room-wide state. This merges with existing state.
|
|
165
|
+
* @param delta The new state to merge with current room state.
|
|
166
|
+
*/
|
|
167
|
+
updateRoomState<TDelta extends KeyValue>(delta: TDelta): void;
|
|
168
|
+
/**
|
|
169
|
+
* Subscribe to room state updates.
|
|
170
|
+
* @param callback Function to call when room state changes.
|
|
171
|
+
* @returns Function to unsubscribe.
|
|
172
|
+
*/
|
|
173
|
+
subscribeRoomState<TRoomState extends KeyValue>(callback: (state: TRoomState) => void): () => void;
|
|
174
|
+
/**
|
|
175
|
+
* Object containing the current presence state of all connected peers, including this client.
|
|
176
|
+
* This is always up-to-date after initialization.
|
|
177
|
+
*/
|
|
178
|
+
readonly presence: {
|
|
179
|
+
[clientId: string]: KeyValue;
|
|
180
|
+
};
|
|
181
|
+
/**
|
|
182
|
+
* Object containing the current room-wide state.
|
|
183
|
+
* This is always up-to-date.
|
|
184
|
+
*/
|
|
185
|
+
readonly roomState: KeyValue;
|
|
186
|
+
/**
|
|
187
|
+
* Object containing all connected peers, including this client.
|
|
188
|
+
* This is always up-to-date.
|
|
189
|
+
*/
|
|
190
|
+
readonly peers: Peers;
|
|
191
|
+
/**
|
|
192
|
+
* Updates the current client's presence state.
|
|
193
|
+
* @param presence The new presence state to set.
|
|
194
|
+
*/
|
|
195
|
+
updatePresence<TPresence extends KeyValue>(presence: TPresence): void;
|
|
196
|
+
/**
|
|
197
|
+
* Subscribe to presence updates from all peers.
|
|
198
|
+
* @param callback Function to call when presence changes.
|
|
199
|
+
* @returns Function to unsubscribe.
|
|
200
|
+
*/
|
|
201
|
+
subscribePresence<TPresence extends KeyValue>(callback: (presence: {
|
|
202
|
+
[clientId: string]: TPresence;
|
|
203
|
+
}) => void): () => void;
|
|
204
|
+
}
|
|
205
|
+
//#endregion
|
|
206
|
+
//#region src/globals.d.ts
|
|
207
|
+
type WebsimSocketConstructor = typeof WebsimSocketClass;
|
|
208
|
+
declare global {
|
|
209
|
+
interface Window {
|
|
210
|
+
readonly WebsimSocket: WebsimSocketConstructor;
|
|
211
|
+
}
|
|
212
|
+
const WebsimSocket: WebsimSocketConstructor;
|
|
213
|
+
}
|
|
214
|
+
//#endregion
|
|
215
|
+
export { type CollectionAPI, type QueryAPI, type WebsimSocketClass };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/package.json
CHANGED
|
@@ -1,24 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@websimai/socket-types",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Type declarations for the `WebsimSocket` class",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"author": "GameRoMan",
|
|
6
7
|
"license": "MIT",
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
".": {
|
|
10
|
-
"types": "./src/index.d.ts"
|
|
11
|
-
}
|
|
8
|
+
"publishConfig": {
|
|
9
|
+
"access": "public"
|
|
12
10
|
},
|
|
13
|
-
"
|
|
14
|
-
"
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/websimnpm/websim.git",
|
|
14
|
+
"directory": "packages/socket-api-types"
|
|
15
15
|
},
|
|
16
16
|
"keywords": [
|
|
17
17
|
"websim",
|
|
18
18
|
"types",
|
|
19
19
|
"typescript"
|
|
20
20
|
],
|
|
21
|
-
"
|
|
22
|
-
"
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "bunx --bun tsdown",
|
|
23
|
+
"npm:publish": "bun run build && bun publish"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist/**/*",
|
|
27
|
+
"README.md",
|
|
28
|
+
"LICENSE"
|
|
29
|
+
],
|
|
30
|
+
"main": "./dist/index.mjs",
|
|
31
|
+
"module": "./dist/index.mjs",
|
|
32
|
+
"types": "./dist/index.d.mts",
|
|
33
|
+
"exports": {
|
|
34
|
+
".": "./dist/index.mjs",
|
|
35
|
+
"./package.json": "./package.json"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"tsdown": "^0.17.3"
|
|
23
39
|
}
|
|
24
40
|
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 Roman A
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
package/src/globals.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { WebsimSocket as WebsimSocketClass } from "./websim-socket";
|
|
2
|
-
|
|
3
|
-
type WebsimSocketConstructor = typeof WebsimSocketClass;
|
|
4
|
-
|
|
5
|
-
declare global {
|
|
6
|
-
interface Window {
|
|
7
|
-
readonly WebsimSocket: WebsimSocketConstructor;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const WebsimSocket: WebsimSocketConstructor;
|
|
11
|
-
|
|
12
|
-
type WebsimSocket = WebsimSocketClass;
|
|
13
|
-
}
|
package/src/index.d.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import type { KeyValue, Expand } from "./utils";
|
|
2
|
-
|
|
3
|
-
export interface CollectionAPI<T extends string> {
|
|
4
|
-
getList: <TData extends KeyValue>() => Expand<
|
|
5
|
-
TData & {
|
|
6
|
-
readonly id: string;
|
|
7
|
-
readonly $type: T;
|
|
8
|
-
readonly created_at: string;
|
|
9
|
-
readonly updated_at: string;
|
|
10
|
-
readonly user_id: string;
|
|
11
|
-
readonly username: string;
|
|
12
|
-
}
|
|
13
|
-
>[];
|
|
14
|
-
create: <TData extends KeyValue>(
|
|
15
|
-
data: TData
|
|
16
|
-
) => Promise<
|
|
17
|
-
Expand<
|
|
18
|
-
TData & {
|
|
19
|
-
readonly id: string;
|
|
20
|
-
readonly $type: T;
|
|
21
|
-
readonly created_at: string;
|
|
22
|
-
readonly username: string;
|
|
23
|
-
}
|
|
24
|
-
>
|
|
25
|
-
>;
|
|
26
|
-
update: <T_Id extends string, TData extends KeyValue>(
|
|
27
|
-
id: T_Id,
|
|
28
|
-
data: TData
|
|
29
|
-
) => Promise<
|
|
30
|
-
Expand<
|
|
31
|
-
TData & {
|
|
32
|
-
readonly id: T_Id;
|
|
33
|
-
readonly $type: T;
|
|
34
|
-
readonly created_at: string;
|
|
35
|
-
readonly username: string;
|
|
36
|
-
}
|
|
37
|
-
>
|
|
38
|
-
>;
|
|
39
|
-
upsert: <
|
|
40
|
-
TData extends KeyValue & { id?: T_Id },
|
|
41
|
-
T_Id extends string = string
|
|
42
|
-
>(
|
|
43
|
-
data: TData
|
|
44
|
-
) => Promise<
|
|
45
|
-
Expand<
|
|
46
|
-
(TData extends { id: T_Id } ? TData & KeyValue : TData) & {
|
|
47
|
-
readonly id: T_Id;
|
|
48
|
-
readonly $type: T;
|
|
49
|
-
readonly created_at: string;
|
|
50
|
-
readonly username: string;
|
|
51
|
-
}
|
|
52
|
-
>
|
|
53
|
-
>;
|
|
54
|
-
delete: (id: string) => Promise<void>;
|
|
55
|
-
subscribe: (
|
|
56
|
-
callback: (
|
|
57
|
-
records: Expand<
|
|
58
|
-
KeyValue & {
|
|
59
|
-
id: string;
|
|
60
|
-
$type: T;
|
|
61
|
-
created_at: string;
|
|
62
|
-
updated_at: string;
|
|
63
|
-
user_id: string;
|
|
64
|
-
username: string;
|
|
65
|
-
}
|
|
66
|
-
>[]
|
|
67
|
-
) => void
|
|
68
|
-
) => () => void;
|
|
69
|
-
filter: (filters: KeyValue) => CollectionAPI<T>;
|
|
70
|
-
}
|
package/src/types/index.d.ts
DELETED
package/src/types/query-api.d.ts
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import type { KeyValue } from "./types/utils";
|
|
2
|
-
|
|
3
|
-
export interface WebsimSocketParty {
|
|
4
|
-
/**
|
|
5
|
-
* Object containing the client ID, avatar URL, and username of this connected client.
|
|
6
|
-
*/
|
|
7
|
-
readonly client: {
|
|
8
|
-
readonly id: string;
|
|
9
|
-
readonly avatarUrl: `https://${string}/${string}`;
|
|
10
|
-
readonly username: string;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Object containing all connected peers, including this client.
|
|
15
|
-
* This is always up-to-date.
|
|
16
|
-
*/
|
|
17
|
-
readonly peers: {
|
|
18
|
-
[id: string]: {
|
|
19
|
-
readonly avatarUrl: `https://${string}/${string}`;
|
|
20
|
-
readonly username: string;
|
|
21
|
-
readonly id: string;
|
|
22
|
-
readonly is_anonymous: boolean;
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
subscribe: (
|
|
27
|
-
callback: (peers: {
|
|
28
|
-
[clientId: string]: {
|
|
29
|
-
avatarUrl: string;
|
|
30
|
-
username: string;
|
|
31
|
-
};
|
|
32
|
-
}) => void
|
|
33
|
-
) => () => void;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Object containing the current presence state of all connected peers, including this client.
|
|
37
|
-
* This is always up-to-date after initialization.
|
|
38
|
-
*/
|
|
39
|
-
readonly presence: KeyValue;
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Updates the current client's presence state.
|
|
43
|
-
* @param presence The new presence state to set.
|
|
44
|
-
*/
|
|
45
|
-
updatePresence<TPresence extends KeyValue>(presence: TPresence): void;
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Subscribe to presence updates from all peers.
|
|
49
|
-
* @param callback Function to call when presence changes.
|
|
50
|
-
* @returns Function to unsubscribe.
|
|
51
|
-
*/
|
|
52
|
-
subscribePresence<TPresence extends KeyValue>(
|
|
53
|
-
callback: (presence: { [clientId: string]: TPresence }) => void
|
|
54
|
-
): () => void;
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Object containing the current room-wide state.
|
|
58
|
-
* This is always up-to-date.
|
|
59
|
-
*/
|
|
60
|
-
readonly roomState: KeyValue;
|
|
61
|
-
}
|
package/src/websim-socket.d.ts
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import type { KeyValue } from "./types/utils";
|
|
2
|
-
|
|
3
|
-
import type { WebsimSocketParty } from "./websim-socket-party";
|
|
4
|
-
|
|
5
|
-
import type { CollectionAPI, QueryAPI } from "./types";
|
|
6
|
-
|
|
7
|
-
export class WebsimSocket {
|
|
8
|
-
constructor();
|
|
9
|
-
|
|
10
|
-
readonly CONNECTING: 0;
|
|
11
|
-
readonly OPEN: 1;
|
|
12
|
-
readonly CLOSING: 2;
|
|
13
|
-
readonly CLOSED: 3;
|
|
14
|
-
|
|
15
|
-
readonly binaryType: "arraybuffer" | (string & {});
|
|
16
|
-
readonly bufferedAmount: number;
|
|
17
|
-
readonly extensions: string;
|
|
18
|
-
readonly protocol: "ws" | "wss";
|
|
19
|
-
readonly readyState: 0 | 1 | 2 | 3;
|
|
20
|
-
readonly url: string;
|
|
21
|
-
|
|
22
|
-
accept(): void;
|
|
23
|
-
serializeAttachment(): void;
|
|
24
|
-
deserializeAttachment(): void;
|
|
25
|
-
|
|
26
|
-
onclose: ((this: WebSocket, ev: CloseEvent) => any) | null;
|
|
27
|
-
onerror: ((this: WebSocket, ev: Event) => any) | null;
|
|
28
|
-
onmessage: ((this: WebSocket, ev: MessageEvent) => any) | null;
|
|
29
|
-
onopen: ((this: WebSocket, ev: Event) => any) | null;
|
|
30
|
-
|
|
31
|
-
dispatchEvent(event: Event | MessageEvent | CloseEvent | ErrorEvent): boolean;
|
|
32
|
-
|
|
33
|
-
close(_code?: number, _reason?: string): void;
|
|
34
|
-
send<TData extends string | object>(data: TData): void;
|
|
35
|
-
|
|
36
|
-
query(queryString: string, params?: any[]): QueryAPI;
|
|
37
|
-
|
|
38
|
-
collection<T extends string>($type: T): CollectionAPI<T>;
|
|
39
|
-
|
|
40
|
-
readonly clientId: string;
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Object containing information about the connected client and their peers.
|
|
44
|
-
*/
|
|
45
|
-
readonly party: WebsimSocketParty;
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Legacy event handler for changes in connected peers.
|
|
49
|
-
* @param peers An object with client IDs as keys, each containing the client's avatar URL and username.
|
|
50
|
-
*/
|
|
51
|
-
onPeersChanged:
|
|
52
|
-
| ((peers: {
|
|
53
|
-
[clientId: string]: {
|
|
54
|
-
avatarUrl: string;
|
|
55
|
-
username: string;
|
|
56
|
-
};
|
|
57
|
-
}) => any)
|
|
58
|
-
| null;
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Initialize the WebSocket connection.
|
|
62
|
-
* @returns A promise that resolves when initialization is complete.
|
|
63
|
-
*/
|
|
64
|
-
initialize(): Promise<void>;
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Request a presence update from a specific client.
|
|
68
|
-
* @param clientId The ID of the client to request an update from.
|
|
69
|
-
* @param update The update to request.
|
|
70
|
-
*/
|
|
71
|
-
requestPresenceUpdate(clientId: string, update: KeyValue): void;
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Subscribe to presence update requests from other clients.
|
|
75
|
-
* @param callback Function to call when a presence update is requested.
|
|
76
|
-
* @returns Function to unsubscribe.
|
|
77
|
-
*/
|
|
78
|
-
subscribePresenceUpdateRequests<TUpdateRequest extends KeyValue>(
|
|
79
|
-
callback: (updateRequest: TUpdateRequest, fromClientId: string) => void
|
|
80
|
-
): () => void;
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Updates the room-wide state. This merges with existing state.
|
|
84
|
-
* @param delta The new state to merge with current room state.
|
|
85
|
-
*/
|
|
86
|
-
updateRoomState<TDelta extends KeyValue>(delta: TDelta): void;
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Subscribe to room state updates.
|
|
90
|
-
* @param callback Function to call when room state changes.
|
|
91
|
-
* @returns Function to unsubscribe.
|
|
92
|
-
*/
|
|
93
|
-
subscribeRoomState<TRoomState extends KeyValue>(
|
|
94
|
-
callback: (state: TRoomState) => void
|
|
95
|
-
): () => void;
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Object containing the current presence state of all connected peers, including this client.
|
|
99
|
-
* This is always up-to-date after initialization.
|
|
100
|
-
*/
|
|
101
|
-
readonly presence: { [clientId: string]: KeyValue };
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Object containing the current room-wide state.
|
|
105
|
-
* This is always up-to-date.
|
|
106
|
-
*/
|
|
107
|
-
readonly roomState: KeyValue;
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Object containing all connected peers, including this client.
|
|
111
|
-
* This is always up-to-date.
|
|
112
|
-
*/
|
|
113
|
-
readonly peers: {
|
|
114
|
-
[clientId: string]: {
|
|
115
|
-
avatarUrl: string;
|
|
116
|
-
username: string;
|
|
117
|
-
};
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Updates the current client's presence state.
|
|
122
|
-
* @param presence The new presence state to set.
|
|
123
|
-
*/
|
|
124
|
-
updatePresence<TPresence extends KeyValue>(presence: TPresence): void;
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Subscribe to presence updates from all peers.
|
|
128
|
-
* @param callback Function to call when presence changes.
|
|
129
|
-
* @returns Function to unsubscribe.
|
|
130
|
-
*/
|
|
131
|
-
subscribePresence<TPresence extends KeyValue>(
|
|
132
|
-
callback: (presence: { [clientId: string]: TPresence }) => void
|
|
133
|
-
): () => void;
|
|
134
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
// Environment setup & latest features
|
|
4
|
-
"lib": ["ESNext", "DOM"],
|
|
5
|
-
"target": "esnext",
|
|
6
|
-
"module": "preserve",
|
|
7
|
-
"moduleDetection": "force",
|
|
8
|
-
|
|
9
|
-
// Bundler mode
|
|
10
|
-
"moduleResolution": "bundler",
|
|
11
|
-
"allowImportingTsExtensions": true,
|
|
12
|
-
"noEmit": true,
|
|
13
|
-
|
|
14
|
-
// This is a type declarations package
|
|
15
|
-
"skipLibCheck": false,
|
|
16
|
-
"skipDefaultLibCheck": true,
|
|
17
|
-
|
|
18
|
-
// Max strictness
|
|
19
|
-
"strict": true,
|
|
20
|
-
"noFallthroughCasesInSwitch": true,
|
|
21
|
-
"noUncheckedIndexedAccess": true,
|
|
22
|
-
"noImplicitOverride": true,
|
|
23
|
-
"noUnusedLocals": true,
|
|
24
|
-
"noUnusedParameters": true,
|
|
25
|
-
"noPropertyAccessFromIndexSignature": true,
|
|
26
|
-
"noImplicitAny": true,
|
|
27
|
-
"strictNullChecks": true,
|
|
28
|
-
"forceConsistentCasingInFileNames": true,
|
|
29
|
-
"verbatimModuleSyntax": true
|
|
30
|
-
}
|
|
31
|
-
}
|