You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Squashed commit of the following:
commit 42abfb5
Author: Plague Fox <[email protected]>
Date: Sat Feb 24 02:16:35 2024 +0400
Update lints
* Add first message after connection/reconnection
* Add interceptors
* Fix after connect
* Test interceptors
* 1.0.0
* Reformat
* Remove nodoc
* Add missing comments
* Add information about options to readme
Copy file name to clipboardExpand all lines: README.md
+45-3
Original file line number
Diff line number
Diff line change
@@ -35,6 +35,41 @@ dependencies:
35
35
- `add(Object data)`: Sends data on the WebSocket connection. The data can be either a String or a List of integers holding bytes.
36
36
- `close([int? code = 1000, String? reason = 'NORMAL_CLOSURE'])`: Permanently stops the WebSocket connection and frees all resources. After calling this method, the WebSocket client is no longer usable.
37
37
38
+
## Options
39
+
40
+
The `WebSocketOptions` class provides a configurable set of options for setting up a WebSocket connection on both VM (Virtual Machine) and JS (JavaScript) platforms. This class supports a variety of settings including connection retry strategies, subprotocols, timeouts, message interceptors, and platform-specific configurations.
41
+
42
+
To use `WebSocketOptions`, instantiate it directly with the desired configuration for your platform. Use the `.vm()` factory for VM platform settings and `.js()` factory for JS platform settings. The `.selector()` factory can be used to construct options depending on the current platform, allowing for flexible configuration across different environments.
43
+
44
+
### Common Options
45
+
46
+
Common configuration options applicable across VM and JS platforms:
| `connectionRetryInterval` | Specifies the [Backoff full jitter strategy](https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/) for reconnecting. Allows tweaks for the reconnect backoff algorithm (min delay, max delay). If not specified, reconnecting is disabled. |
51
+
| `protocols` | Specifies the subprotocols the client is willing to speak. |
52
+
| `timeout` | Specifies the maximum time to wait for the connection to be established. Defaults to 30 seconds if not specified. |
53
+
| `afterConnect` | Specifies the callback function to be called after the connection is established, but before the client is allowed to send user messages. |
54
+
| `interceptors` | Specifies the interceptors for WebSocket messages. |
55
+
56
+
### VM Platform Options
57
+
58
+
Specific to VM (Mobile, Desktop, Server, Console) platform. Not to be used on the web platform.
59
+
60
+
- Includes all common options.
61
+
- `headers`: Specifies additional HTTP headers for setting up the connection. Certain headers are controlled by the WebSocket connection process and will be ignored if passed.
62
+
- `compression`: If provided, configures the WebSocket to negotiate with the specified `CompressionOptions`.
63
+
- `customClient`: Allows specifying a custom `HttpClient`.
64
+
- `userAgent`: Allows specifying a custom `UserAgent`.
65
+
66
+
### JS Platform Options
67
+
68
+
Specific to JS (Browser) platform. Not to be used on the VM platform.
69
+
70
+
- Includes all common options.
71
+
- `useBlobForBinary`: Specifies if `Uint8List` should be sent as `Blob` or as typed data. Defaults to sending as typed data.
72
+
38
73
## Example
39
74
40
75

@@ -69,11 +104,14 @@ The `ws` package provides a cross-platform WebSocket client that supports JSON.
69
104
- ✅ Fake client for testing
70
105
- ✅ Custom exceptions
71
106
- ✅ 90% test coverage
72
-
- ❌ First message after connection/reconnection
73
-
- ❌ Automatic ping/pong for keep-alive & connection health check
107
+
- ✅ First message after connection/reconnection
108
+
- ✅ Interceptors (middlewares)
109
+
110
+
<!--
74
111
- ❌ Reusing client between isolates
75
-
- ❌ Interceptors (middlewares)
112
+
- ❌ Automatic ping/pong for keep-alive & connection health check
76
113
- ❌ RPC support
114
+
-->
77
115
78
116
## More resources
79
117
@@ -111,3 +149,7 @@ We appreciate any form of support, whether it's a financial donation or just a s
0 commit comments