@s2script/sdk 0.18.0 → 0.19.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/package.json +1 -1
- package/ws.d.ts +21 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@s2script/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"license": "MIT OR Apache-2.0",
|
|
5
5
|
"description": "s2script SDK — the builtin capability types (imported as @s2script/sdk/entity, …) plus the `s2s` CLI for building Source 2 / CS2 plugins.",
|
|
6
6
|
"type": "module",
|
package/ws.d.ts
CHANGED
|
@@ -13,17 +13,36 @@ export interface WebSocket {
|
|
|
13
13
|
/** Close the connection. */
|
|
14
14
|
close(): void;
|
|
15
15
|
}
|
|
16
|
+
/** Options for {@link WebSocket.connect}. */
|
|
17
|
+
export interface WebSocketInit {
|
|
18
|
+
/**
|
|
19
|
+
* Extra headers to send on the opening handshake — the usual reason being a
|
|
20
|
+
* credential the server requires, e.g. `Authorization: Bearer <token>`.
|
|
21
|
+
*
|
|
22
|
+
* Headers the handshake owns are refused, and the connect rejects rather than
|
|
23
|
+
* silently dropping them: `Host`, `Connection`, `Upgrade`, any
|
|
24
|
+
* `Sec-WebSocket-*`, `Content-Length`, `Transfer-Encoding`. Values containing
|
|
25
|
+
* control characters are refused for the same reason.
|
|
26
|
+
*/
|
|
27
|
+
headers?: Record<string, string>;
|
|
28
|
+
}
|
|
29
|
+
|
|
16
30
|
/** Entry point for opening WebSocket connections. */
|
|
17
31
|
export declare const WebSocket: {
|
|
18
32
|
/**
|
|
19
33
|
* Connect to a WebSocket server (`wss://` for TLS) off the game thread.
|
|
20
34
|
* @returns Resolves on the open handshake with the live {@link WebSocket} handle.
|
|
21
|
-
* @throws Rejects on connect failure (bad URL, refused, TLS/handshake error).
|
|
35
|
+
* @throws Rejects on connect failure (bad URL, refused, TLS/handshake error, or a refused header).
|
|
22
36
|
* @example
|
|
23
37
|
* import { WebSocket } from "@s2script/sdk/ws";
|
|
24
38
|
* const ws = await WebSocket.connect("wss://ws.postman-echo.com/raw");
|
|
25
39
|
* ws.onMessage((data) => { console.log("echo:", data); ws.close(); });
|
|
26
40
|
* ws.send("hello-from-s2script");
|
|
41
|
+
* @example
|
|
42
|
+
* // A server that authenticates the handshake rather than the first frame.
|
|
43
|
+
* const ws = await WebSocket.connect("wss://maul.example/v2/ws", {
|
|
44
|
+
* headers: { Authorization: `Bearer ${jwt}` },
|
|
45
|
+
* });
|
|
27
46
|
*/
|
|
28
|
-
connect(url: string): Promise<WebSocket>;
|
|
47
|
+
connect(url: string, init?: WebSocketInit): Promise<WebSocket>;
|
|
29
48
|
};
|