uws-react-native 0.0.9 → 0.0.10

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.
Files changed (48) hide show
  1. package/README.md +27 -7
  2. package/cpp/UwsReactNativeModule.h +77 -0
  3. package/cpp/app/TemplatedAppObject.h +28 -0
  4. package/cpp/app/WebSocketBehaviorImpl.h +48 -0
  5. package/cpp/app/WebSocketObject.h +64 -0
  6. package/lib/commonjs/_internal/native-modules/NativeUwsReactNative.js.map +1 -1
  7. package/lib/commonjs/modules/CompressOptions.js +89 -101
  8. package/lib/commonjs/modules/CompressOptions.js.map +1 -1
  9. package/lib/commonjs/types/WebSocketBehavior.js +6 -0
  10. package/lib/commonjs/types/WebSocketBehavior.js.map +1 -0
  11. package/lib/module/_internal/native-modules/NativeUwsReactNative.js.map +1 -1
  12. package/lib/module/modules/CompressOptions.js +85 -101
  13. package/lib/module/modules/CompressOptions.js.map +1 -1
  14. package/lib/module/types/WebSocketBehavior.js +4 -0
  15. package/lib/module/types/WebSocketBehavior.js.map +1 -0
  16. package/lib/typescript/commonjs/_internal/native-modules/NativeUwsReactNative.d.ts +76 -0
  17. package/lib/typescript/commonjs/_internal/native-modules/NativeUwsReactNative.d.ts.map +1 -1
  18. package/lib/typescript/commonjs/modules/CompressOptions.d.ts +81 -0
  19. package/lib/typescript/commonjs/modules/CompressOptions.d.ts.map +1 -1
  20. package/lib/typescript/commonjs/types/WebSocket.d.ts +42 -43
  21. package/lib/typescript/commonjs/types/WebSocket.d.ts.map +1 -1
  22. package/lib/typescript/commonjs/types/WebSocketBehavior.d.ts +101 -0
  23. package/lib/typescript/commonjs/types/WebSocketBehavior.d.ts.map +1 -0
  24. package/lib/typescript/module/_internal/native-modules/NativeUwsReactNative.d.ts +76 -0
  25. package/lib/typescript/module/_internal/native-modules/NativeUwsReactNative.d.ts.map +1 -1
  26. package/lib/typescript/module/modules/CompressOptions.d.ts +81 -0
  27. package/lib/typescript/module/modules/CompressOptions.d.ts.map +1 -1
  28. package/lib/typescript/module/types/WebSocket.d.ts +42 -43
  29. package/lib/typescript/module/types/WebSocket.d.ts.map +1 -1
  30. package/lib/typescript/module/types/WebSocketBehavior.d.ts +101 -0
  31. package/lib/typescript/module/types/WebSocketBehavior.d.ts.map +1 -0
  32. package/lib/typescript/tsconfig.tsbuildinfo +1 -1
  33. package/package.json +1 -1
  34. package/src/_internal/native-modules/NativeUwsReactNative.ts +95 -0
  35. package/src/modules/CompressOptions.ts +101 -101
  36. package/src/types/TemplatedApp.ts +3 -3
  37. package/src/types/WebSocket.ts +59 -60
  38. package/src/types/WebSocketBehavior.ts +161 -0
  39. package/src/types/index.ts +1 -1
  40. package/lib/commonjs/types/WebSocketBehaviour.js +0 -139
  41. package/lib/commonjs/types/WebSocketBehaviour.js.map +0 -1
  42. package/lib/module/types/WebSocketBehaviour.js +0 -139
  43. package/lib/module/types/WebSocketBehaviour.js.map +0 -1
  44. package/lib/typescript/commonjs/types/WebSocketBehaviour.d.ts +0 -1
  45. package/lib/typescript/commonjs/types/WebSocketBehaviour.d.ts.map +0 -1
  46. package/lib/typescript/module/types/WebSocketBehaviour.d.ts +0 -1
  47. package/lib/typescript/module/types/WebSocketBehaviour.d.ts.map +0 -1
  48. package/src/types/WebSocketBehaviour.ts +0 -137
@@ -16,6 +16,82 @@ export interface Spec extends TurboModule {
16
16
  body: unknown, contentType: string) => unknown;
17
17
  _us_listen_socket_close: (id: CodegenTypes.Int32) => void;
18
18
  _us_socket_local_port: (id: CodegenTypes.Int32) => number;
19
+ /**
20
+ * No compression (always a good idea if you operate using an efficient binary protocol)
21
+ */
22
+ DISABLED: () => number;
23
+ /**
24
+ * Zero memory overhead compression.
25
+ */
26
+ SHARED_COMPRESSOR: () => number;
27
+ /**
28
+ * Zero memory overhead decompression.
29
+ */
30
+ SHARED_DECOMPRESSOR: () => number;
31
+ /**
32
+ * Sliding dedicated compress window, requires 3KB of memory per socket
33
+ */
34
+ DEDICATED_COMPRESSOR_3KB: () => number;
35
+ /**
36
+ * Sliding dedicated compress window, requires 4KB of memory per socket
37
+ */
38
+ DEDICATED_COMPRESSOR_4KB: () => number;
39
+ /**
40
+ * Sliding dedicated compress window, requires 8KB of memory per socket
41
+ */
42
+ DEDICATED_COMPRESSOR_8KB: () => number;
43
+ /**
44
+ * Sliding dedicated compress window, requires 16KB of memory per socket
45
+ */
46
+ DEDICATED_COMPRESSOR_16KB: () => number;
47
+ /**
48
+ * Sliding dedicated compress window, requires 32KB of memory per socket
49
+ */
50
+ DEDICATED_COMPRESSOR_32KB: () => number;
51
+ /**
52
+ * Sliding dedicated compress window, requires 64KB of memory per socket
53
+ */
54
+ DEDICATED_COMPRESSOR_64KB: () => number;
55
+ /**
56
+ * Sliding dedicated compress window, requires 128KB of memory per socket
57
+ */
58
+ DEDICATED_COMPRESSOR_128KB: () => number;
59
+ /**
60
+ * Sliding dedicated compress window, requires 256KB of memory per socket
61
+ */
62
+ DEDICATED_COMPRESSOR_256KB: () => number;
63
+ /**
64
+ * Sliding dedicated decompress window, requires 32KB of memory per socket (plus about 23KB)
65
+ */
66
+ DEDICATED_DECOMPRESSOR_32KB: () => number;
67
+ /**
68
+ * Sliding dedicated decompress window, requires 16KB of memory per socket (plus about 23KB)
69
+ */
70
+ DEDICATED_DECOMPRESSOR_16KB: () => number;
71
+ /**
72
+ * Sliding dedicated decompress window, requires 8KB of memory per socket (plus about 23KB)
73
+ */
74
+ DEDICATED_DECOMPRESSOR_8KB: () => number;
75
+ /**
76
+ * Sliding dedicated decompress window, requires 4KB of memory per socket (plus about 23KB)
77
+ */
78
+ DEDICATED_DECOMPRESSOR_4KB: () => number;
79
+ /**
80
+ * Sliding dedicated decompress window, requires 2KB of memory per socket (plus about 23KB)
81
+ */
82
+ DEDICATED_DECOMPRESSOR_2KB: () => number;
83
+ /**
84
+ * Sliding dedicated decompress window, requires 1KB of memory per socket (plus about 23KB)
85
+ */
86
+ DEDICATED_DECOMPRESSOR_1KB: () => number;
87
+ /**
88
+ * Sliding dedicated decompress window, requires 512B of memory per socket (plus about 23KB)
89
+ */
90
+ DEDICATED_DECOMPRESSOR_512B: () => number;
91
+ /**
92
+ * Sliding dedicated decompress window, requires 32KB of memory per socket (plus about 23KB)
93
+ */
94
+ DEDICATED_DECOMPRESSOR: () => number;
19
95
  }
20
96
  declare const _default: Spec;
21
97
  export default _default;
@@ -1 +1 @@
1
- {"version":3,"file":"NativeUwsReactNative.d.ts","sourceRoot":"","sources":["../../../../../src/_internal/native-modules/NativeUwsReactNative.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,MAAM,cAAc,CAAA;AAErB;;GAEG;AACH,MAAM,WAAW,IAAK,SAAQ,WAAW;IACxC,GAAG,EAAE;IACJ;;OAEG;IACH,UAAU,CAAC,EAAE,YAAY,CAAC,YAAY,KAClC,YAAY,CAAC,YAAY,CAAC;IAE/B,QAAQ,EAAE;IACT;;;OAGG;IACH,IAAI,EAAE,OAAO,EACb,WAAW,EAAE,MAAM,KACf,OAAO,CAAC;IAEb,uBAAuB,EAAE,CACxB,EAAE,EAAE,YAAY,CAAC,KAAK,KAElB,IAAI,CAAC;IAEV,qBAAqB,EAAE,CACtB,EAAE,EAAE,YAAY,CAAC,KAAK,KAElB,MAAM,CAAC;CACZ;;AAED,wBAEC"}
1
+ {"version":3,"file":"NativeUwsReactNative.d.ts","sourceRoot":"","sources":["../../../../../src/_internal/native-modules/NativeUwsReactNative.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,MAAM,cAAc,CAAA;AAErB;;GAEG;AACH,MAAM,WAAW,IAAK,SAAQ,WAAW;IACxC,GAAG,EAAE;IACJ;;OAEG;IACH,UAAU,CAAC,EAAE,YAAY,CAAC,YAAY,KAClC,YAAY,CAAC,YAAY,CAAC;IAE/B,QAAQ,EAAE;IACT;;;OAGG;IACH,IAAI,EAAE,OAAO,EACb,WAAW,EAAE,M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ise OR.
3
+ */
4
+ export declare enum CompressOptions {
5
+ /**
6
+ * No compression (always a good idea if you operate using an efficient binary protocol)
7
+ */
8
+ DISABLED,
9
+ /**
10
+ * Zero memory overhead compression.
11
+ */
12
+ SHARED_COMPRESSOR,
13
+ /**
14
+ * Zero memory overhead decompression.
15
+ */
16
+ SHARED_DECOMPRESSOR,
17
+ /**
18
+ * Sliding dedicated compress window, requires 3KB of memory per socket
19
+ */
20
+ DEDICATED_COMPRESSOR_3KB,
21
+ /**
22
+ * Sliding dedicated compress window, requires 4KB of memory per socket
23
+ */
24
+ DEDICATED_COMPRESSOR_4KB,
25
+ /**
26
+ * Sliding dedicated compress window, requires 8KB of memory per socket
27
+ */
28
+ DEDICATED_COMPRESSOR_8KB,
29
+ /**
30
+ * Sliding dedicated compress window, requires 16KB of memory per socket
31
+ */
32
+ DEDICATED_COMPRESSOR_16KB,
33
+ /**
34
+ * Sliding dedicated compress window, requires 32KB of memory per socket
35
+ */
36
+ DEDICATED_COMPRESSOR_32KB,
37
+ /**
38
+ * Sliding dedicated compress window, requires 64KB of memory per socket
39
+ */
40
+ DEDICATED_COMPRESSOR_64KB,
41
+ /**
42
+ * Sliding dedicated compress window, requires 128KB of memory per socket
43
+ */
44
+ DEDICATED_COMPRESSOR_128KB,
45
+ /**
46
+ * Sliding dedicated compress window, requires 256KB of memory per socket
47
+ */
48
+ DEDICATED_COMPRESSOR_256KB,
49
+ /**
50
+ * Sliding dedicated decompress window, requires 32KB of memory per socket (plus about 23KB)
51
+ */
52
+ DEDICATED_DECOMPRESSOR_32KB,
53
+ /**
54
+ * Sliding dedicated decompress window, requires 16KB of memory per socket (plus about 23KB)
55
+ */
56
+ DEDICATED_DECOMPRESSOR_16KB,
57
+ /**
58
+ * Sliding dedicated decompress window, requires 8KB of memory per socket (plus about 23KB)
59
+ */
60
+ DEDICATED_DECOMPRESSOR_8KB,
61
+ /**
62
+ * Sliding dedicated decompress window, requires 4KB of memory per socket (plus about 23KB)
63
+ */
64
+ DEDICATED_DECOMPRESSOR_4KB,
65
+ /**
66
+ * Sliding dedicated decompress window, requires 2KB of memory per socket (plus about 23KB)
67
+ */
68
+ DEDICATED_DECOMPRESSOR_2KB,
69
+ /**
70
+ * Sliding dedicated decompress window, requires 1KB of memory per socket (plus about 23KB)
71
+ */
72
+ DEDICATED_DECOMPRESSOR_1KB,
73
+ /**
74
+ * Sliding dedicated decompress window, requires 512B of memory per socket (plus about 23KB)
75
+ */
76
+ DEDICATED_DECOMPRESSOR_512B,
77
+ /**
78
+ * Sliding dedicated decompress window, requires 32KB of memory per socket (plus about 23KB)
79
+ */
80
+ DEDICATED_DECOMPRESSOR
81
+ }
1
82
  //# sourceMappingURL=CompressOptions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"CompressOptions.d.ts","sourceRoot":"","sources":["../../../../src/modules/CompressOptions.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"CompressOptions.d.ts","sourceRoot":"","sources":["../../../../src/modules/CompressOptions.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,oBAAY,eAAe;IAC1B;;OAEG;IACH,QAA8C;IAE9C;;OAEG;IACH,iBAA8D;IAE9D;;OAEG;IACH,mBAAkE;IAElE;;OAEG;IACH,wBAA0E;IAE1E;;OAEG;IACH,wBAA0E;IAE1E;;OAEG;IACH,wBAA0E;IAE1E;;OAEG;IACH,yBAA4E;IAE5E;;OAEG;IACH,yBAA4E;IAE5E;;OAEG;IACH,yBAA4E;IAE5E;;OAEG;IACH,0BAA8E;IAE9E;;OAEG;IACH,0BAA8E;IAE9E;;OAEG;IACH,2BAAgF;IAEhF;;OAEG;IACH,2BAAgF;IAEhF;;OAEG;IACH,0BAA8E;IAE9E;;OAEG;IACH,0BAA8E;IAE9E;;OAEG;IACH,0BAA8E;IAE9E;;OAEG;IACH,0BAA8E;IAE9E;;OAEG;IACH,2BAAgF;IAEhF;;OAEG;IACH,sBAAuE;CACvE"}
@@ -3,80 +3,71 @@ import type { RecognizedString } from "./RecognizedString";
3
3
  * A WebSocket connection that is valid from open to close event.
4
4
  * Read more about this in the user manual.
5
5
  */
6
- export interface WebSocket {
6
+ export interface WebSocket<UserData> {
7
7
  /**
8
- * Sends a message. Returns 1 for success, 2 for dropped due to backpressure limit, and 0 for built up backpressure that will drain over time. You can check backpressure before or after sending by calling getBufferedAmount().
9
- *
10
- * Make sure you properly understand the concept of backpressure. Check the backpressure example file.
8
+ * Forcefully closes this WebSocket. Immediately calls the close handler.
9
+ * No WebSocket close message is sent.
11
10
  */
12
- send(message: RecognizedString, isBinary?: boolean, compress?: boolean): number;
11
+ close(): void;
13
12
  /**
14
- * Returns the bytes buffered in backpressure. This is similar to the bufferedAmount property in the browser counterpart.
15
- * Check backpressure example.
13
+ * See `HttpResponse.cork`.
14
+ * Takes a function in which the socket is corked (packing many sends into one single syscall/SSL block)
16
15
  */
17
- getBufferedAmount(): number;
16
+ cork(cb: () => void): WebSocket<UserData>;
18
17
  /**
19
18
  * Gracefully closes this WebSocket. Immediately calls the close handler.
20
19
  * A WebSocket close message is sent with code and shortMessage.
21
20
  */
22
21
  end(code?: number, shortMessage?: RecognizedString): void;
23
22
  /**
24
- * Forcefully closes this WebSocket. Immediately calls the close handler.
25
- * No WebSocket close message is sent.
26
- */
27
- close(): void;
28
- /**
29
- * Sends a ping control message. Returns sendStatus similar to WebSocket.send (regarding backpressure). This helper function correlates to WebSocket::send(message, uWS::OpCode::PING, ...) in C++.
23
+ * Returns the bytes buffered in backpressure. This is similar to the bufferedAmount property in the browser counterpart.
24
+ * Check backpressure example.
30
25
  */
31
- ping(message?: RecognizedString): number;
26
+ getBufferedAmount(): number;
32
27
  /**
33
- * Subscribe to a topic.
28
+ * Returns the remote IP address. Note that the returned IP is binary, not text.
29
+ *
30
+ * IPv4 is 4 byte long and can be converted to text by printing every byte as a digit between 0 and 255.
31
+ * IPv6 is 16 byte long and can be converted to text in similar ways, but you typically print digits in HEX.
32
+ *
33
+ * See getRemoteAddressAsText() for a text version.
34
34
  */
35
- subscribe(topic: RecognizedString): boolean;
35
+ getRemoteAddress(): ArrayBuffer;
36
36
  /**
37
- * Unsubscribe from a topic. Returns true on success, if the WebSocket was subscribed.
37
+ * Returns the remote IP address as text.
38
38
  */
39
- unsubscribe(topic: RecognizedString): boolean;
39
+ getRemoteAddressAsText(): string;
40
40
  /**
41
- * Returns whether this websocket is subscribed to topic.
41
+ * Returns the remote port number.
42
42
  */
43
- isSubscribed(topic: RecognizedString): boolean;
43
+ getRemotePort(): number;
44
44
  /**
45
45
  * Returns a list of topics this websocket is subscribed to.
46
46
  */
47
47
  getTopics(): string[];
48
48
  /**
49
- * Publish a message under topic. Backpressure is managed according to maxBackpressure, closeOnBackpressureLimit settings.
50
- * Order is guaranteed since v20.
51
- */
52
- publish(topic: RecognizedString, message: RecognizedString, isBinary?: boolean, compress?: boolean): boolean;
53
- /**
54
- * See `HttpResponse.cork`. Takes a function in which the socket is corked (packing many sends into one single syscall/SSL block)
49
+ * Returns the UserData object.
55
50
  */
56
- cork(cb: () => void): WebSocket;
51
+ getUserData(): UserData;
57
52
  /**
58
- * Returns the remote IP address. Note that the returned IP is binary, not text.
59
- *
60
- * IPv4 is 4 byte long and can be converted to text by printing every byte as a digit between 0 and 255.
61
- * IPv6 is 16 byte long and can be converted to text in similar ways, but you typically print digits in HEX.
62
- *
63
- * See getRemoteAddressAsText() for a text version.
64
- *
65
- * @experimental It's an experimental due to unstable of ArrayBuffer support from React Native.
53
+ * Returns whether this websocket is subscribed to topic.
66
54
  */
67
- getRemoteAddress(): ArrayBuffer;
55
+ isSubscribed(topic: RecognizedString): boolean;
68
56
  /**
69
- * Returns the remote IP address as text.
57
+ * Sends a ping control message. Returns sendStatus similar to WebSocket.send (regarding backpressure). This helper function correlates to WebSocket::send(message, uWS::OpCode::PING, ...) in C++.
70
58
  */
71
- getRemoteAddressAsText(): string;
59
+ ping(message?: RecognizedString): number;
72
60
  /**
73
- * Returns the remote port number.
61
+ * Publish a message under topic. Backpressure is managed according to maxBackpressure, closeOnBackpressureLimit settings.
62
+ * Order is guaranteed since v20.
74
63
  */
75
- getRemotePort(): number;
64
+ publish(topic: RecognizedString, message: RecognizedString, isBinary?: boolean, compress?: boolean): boolean;
76
65
  /**
77
- * Returns the UserData ~object~ string.
66
+ * Sends a message. Returns 1 for success, 2 for dropped due to backpressure limit, and 0 for built up backpressure that will drain over time. You can check backpressure before or after sending by calling getBufferedAmount().
67
+ *
68
+ * Make sure you properly understand the concept of backpressure. Check the backpressure example file.
78
69
  */
79
- getUserData(): string;
70
+ send(message: RecognizedString, isBinary?: boolean, compress?: boolean): number;
80
71
  /**
81
72
  * Sends the first fragment of a fragmented message. Use for sending large messages in chunks.
82
73
  * Returns 1 for success, 2 for dropped due to backpressure limit, and 0 for built up backpressure.
@@ -92,5 +83,13 @@ export interface WebSocket {
92
83
  * Returns 1 for success, 2 for dropped due to backpressure limit, and 0 for built up backpressure.
93
84
  */
94
85
  sendLastFragment(message: RecognizedString, compress?: boolean): number;
86
+ /**
87
+ * Subscribe to a topic.
88
+ */
89
+ subscribe(topic: RecognizedString): boolean;
90
+ /**
91
+ * Unsubscribe from a topic. Returns true on success, if the WebSocket was subscribed.
92
+ */
93
+ unsubscribe(topic: RecognizedString): boolean;
95
94
  }
96
95
  //# sourceMappingURL=WebSocket.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"WebSocket.d.ts","sourceRoot":"","sources":["../../../../src/types/WebSocket.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,gBAAgB,EAChB,MAAM,oBAAoB,CAAA;AAE3B;;;GAGG;AACH,MAAM,WAAW,SAAS;IACzB;;;;OAIM;IACN,IAAI,CACH,OAAO,EAAE,gBAAgB,EACzB,QAAQ,CAAC,EAAE,OAAO,EAClB,QAAQ,CAAC,EAAE,OAAO,GACf,MAAM,CAAC;IAEX;;;OAGM;IACN,iBAAiB,IAAK,MAAM,CAAC;IAE7B;;;OAGM;IACN,GAAG,CACF,IAAI,CAAC,EAAE,MAAM,E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ACN,YAAY,CACX,OAAO,EAAE,gBAAgB,EACzB,QAAQ,CAAC,EAAE,OAAO,GACf,MAAM,CAAC;IAEX;;;OAGM;IACN,gBAAgB,CACf,OAAO,EAAE,gBAAgB,EACzB,QAAQ,CAAC,EAAE,OAAO,GACf,MAAM,CAAC;IAEX;;OAEG;IACH,SAAS,CACR,KAAK,EAAE,gBAAgB,GACpB,OAAO,CAAC;IAEZ;;OAEG;IACH,WAAW,CACV,KAAK,EAAE,gBAAgB,GACpB,OAAO,CAAC;CACZ"}
@@ -0,0 +1,101 @@
1
+ import type { CompressOptions } from "../modules/CompressOptions";
2
+ import type { HttpRequest } from "./HttpRequest";
3
+ import type { HttpResponse } from "./HttpResponse";
4
+ import type { WebSocket } from "./WebSocket";
5
+ import type { us_socket_context_t } from "./us_socket_context_t";
6
+ /**
7
+ * A structure holding settings and handlers for a WebSocket URL route handler.
8
+ */
9
+ export interface WebSocketBehavior<UserData> {
10
+ /**
11
+ * Handler for close event, no matter if error, timeout or graceful close.
12
+ * You may not use WebSocket after this event.
13
+ * Do not send on this WebSocket from within here, it is closed.
14
+ */
15
+ close?: (ws: WebSocket<UserData>, code: number, message: ArrayBuffer) => void;
16
+ /**
17
+ * Whether or not we should automatically close the socket when a message is dropped due to backpressure. Defaults to false.
18
+ */
19
+ closeOnBackpressureLimit?: boolean;
20
+ /**
21
+ * What permessage-deflate compression to use. uWS.DISABLED, uWS.SHARED_COMPRESSOR or any of the uWS.DEDICATED_COMPRESSOR_xxxKB. Defaults to uWS.DISABLED.
22
+ *
23
+ * Combine any compressor with any decompressor using bitwise OR.
24
+ */
25
+ compression?: CompressOptions;
26
+ /**
27
+ * Handler for when WebSocket backpressure drains.
28
+ * Check `ws.getBufferedAmount()`.
29
+ * Use this to guide / drive your backpressure throttling.
30
+ */
31
+ drain?: (ws: WebSocket<UserData>) => void;
32
+ /**
33
+ * Handler for a dropped WebSocket message.
34
+ * Messages can be dropped due to specified backpressure settings.
35
+ * Messages are given as ArrayBuffer no matter if they are binary or not.
36
+ * Given ArrayBuffer is valid during the lifetime of this callback
37
+ * (until first await or return) and will be neutered.
38
+ */
39
+ dropped?: (ws: WebSocket<UserData>, message: ArrayBuffer, isBinary: boolean) => void | Promise<void>;
40
+ /**
41
+ * Maximum amount of seconds that may pass without sending or getting a message. Connection is closed if this timeout passes.
42
+ * Resolution (granularity) for timeouts are typically 4 seconds, rounded to closest.
43
+ *
44
+ * Disable by using 0. Defaults to 120.
45
+ */
46
+ idleTimeout?: number;
47
+ /**
48
+ * Maximum length of allowed backpressure per socket when publishing or sending messages.
49
+ * Slow receivers with too high backpressure will be skipped until they catch up or timeout.
50
+ *
51
+ * Defaults to 64 * 1024.
52
+ */
53
+ maxBackpressure?: number;
54
+ /**
55
+ * Maximum number of minutes a WebSocket may be connected before being closed by the server.
56
+ *
57
+ * 0 disables the feature. Valid values are 0 and 1-239.
58
+ */
59
+ maxLifetime?: number;
60
+ /**
61
+ * Maximum length of received message.
62
+ * If a client tries to send you a message larger than this, the connection is immediately closed.
63
+ *
64
+ * Defaults to 16 * 1024.
65
+ */
66
+ maxPayloadLength?: number;
67
+ /**
68
+ * Handler for a WebSocket message.
69
+ * Messages are given as ArrayBuffer no matter if they are binary or not.
70
+ *
71
+ * Given ArrayBuffer is valid during the lifetime of this callback (until first await or return) and will be neutered.
72
+ */
73
+ message?: (ws: WebSocket<UserData>, message: ArrayBuffer, isBinary: boolean) => void | Promise<void>;
74
+ /**
75
+ * Handler for new WebSocket connection.
76
+ * WebSocket is valid from open to close, no errors.
77
+ */
78
+ open?: (ws: WebSocket<UserData>) => void | Promise<void>;
79
+ /**
80
+ * Handler for received ping control message.
81
+ * You do not need to handle this, pong messages are automatically sent as per the standard.
82
+ */
83
+ ping?: (ws: WebSocket<UserData>, message: ArrayBuffer) => void;
84
+ /**
85
+ * Handler for received pong control message.
86
+ */
87
+ pong?: (ws: WebSocket<UserData>, message: ArrayBuffer) => void;
88
+ /**
89
+ * Whether or not we should automatically send pings to uphold a stable connection given whatever `idleTimeout`.
90
+ */
91
+ sendPingsAutomatically?: boolean;
92
+ /**
93
+ * Handler for subscription changes.
94
+ */
95
+ subscription?: (ws: WebSocket<UserData>, topic: ArrayBuffer, newCount: number, oldCount: number) => void;
96
+ /**
97
+ * Upgrade handler used to intercept HTTP upgrade requests and potentially upgrade to WebSocket.
98
+ */
99
+ upgrade?: (res: HttpResponse, req: HttpRequest, context: us_socket_context_t) => void | Promise<void>;
100
+ }
101
+ //# sourceMappingURL=WebSocketBehavior.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WebSocketBehavior.d.ts","sourceRoot":"","sources":["../../../../src/types/WebSocketBehavior.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,eAAe,EACf,MAAM,4BAA4B,CAAA;AAEnC,OAAO,KAAK,EACX,WAAW,EACX,MAAM,eAAe,CAAA;AAEtB,OAAO,KAAK,EACX,YAAY,EACZ,MAAM,gBAAgB,CAAA;AAEvB,OAAO,KAAK,EACX,SAAS,EACT,MAAM,aAAa,CAAA;AAEpB,OAAO,KAAK,EACX,mBAAmB,EACnB,MAAM,uBAAuB,CAAA;AAE9B;;GAEG;AACH,MAAM,WAAW,iBAAiB,CAAC,QAAQ;IAC1C;;;;OAIG;IACH,KAAK,CAAC,EAAE,CACP,EAAE,EAAE,SAAS,CAAC,QAAQ,CAAC,EACvB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,WAAW,KAChB,IAAI,CAAC;IAEV;;OAEG;IACH,wBAAwB,CAAC,EAAE,OAAO,CAAC;IAEnC;;;;OAIG;IACH,WAAW,CAAC,EAAE,eAAe,CAAC;IAE9B;;;;OAIG;IACH,KAAK,CAAC,EAAE,CACP,EAAE,EAAE,SAAS,CAAC,QAAQ,CAAC,KACnB,IAAI,CAAC;IAEV;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,CACT,EAAE,EAAE,SAAS,CAAC,QAAQ,CAAC,EACvB,OAAO,EAAE,WAAW,EACpB,QAAQ,E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