@stonyx/sockets 0.1.1-alpha.37 → 0.1.1-alpha.39
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/README.md +20 -19
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -15,6 +15,17 @@ WebSocket server and client module for the [Stonyx framework](https://github.com
|
|
|
15
15
|
* **Encryption by default:** AES-256-GCM with per-session keys, zero external dependencies.
|
|
16
16
|
* **Singleton pattern:** Matches the conventions of `@stonyx/rest-server` and `stonyx-orm`.
|
|
17
17
|
|
|
18
|
+
## Usage reference
|
|
19
|
+
|
|
20
|
+
The handlers in [`test/sample/`](https://github.com/abofs/stonyx-sockets/tree/dev/test/sample) are the canonical usage reference for this module; the integration tests run against them. They are not included in the npm package.
|
|
21
|
+
|
|
22
|
+
Exports:
|
|
23
|
+
|
|
24
|
+
* `@stonyx/sockets`: named `SocketServer`, `SocketClient` and `Handler`; the default export is the `Sockets` class Stonyx uses for auto-init
|
|
25
|
+
* `@stonyx/sockets/server`: `SocketServer`
|
|
26
|
+
* `@stonyx/sockets/client`: `SocketClient`
|
|
27
|
+
* `@stonyx/sockets/handler`: `Handler`
|
|
28
|
+
|
|
18
29
|
## Installation
|
|
19
30
|
|
|
20
31
|
```bash
|
|
@@ -205,28 +216,15 @@ Configuration is read from `stonyx/config` under `sockets`:
|
|
|
205
216
|
| Option | Env Var | Default | Description |
|
|
206
217
|
|--------|---------|---------|-------------|
|
|
207
218
|
| `port` | `SOCKET_PORT` | `2667` | WebSocket server port |
|
|
208
|
-
| `address` | `SOCKET_ADDRESS` | `ws://localhost:
|
|
219
|
+
| `address` | `SOCKET_ADDRESS` | `ws://localhost:2667` | Client connection address |
|
|
209
220
|
| `authKey` | `SOCKET_AUTH_KEY` | `'AUTH_KEY'` | Shared authentication key |
|
|
210
221
|
| `heartBeatInterval` | `SOCKET_HEARTBEAT_INTERVAL` | `30000` | Heartbeat interval in ms |
|
|
211
222
|
| `handlerDir` | `SOCKET_HANDLER_DIR` | `'./socket-handlers'` | Handler directory path |
|
|
212
|
-
| `log` | `SOCKET_LOG` | `false` | Enable verbose logging |
|
|
213
223
|
| `encryption` | `SOCKET_ENCRYPTION` | `'true'` | Enable AES-256-GCM encryption |
|
|
214
|
-
| `
|
|
215
|
-
| `
|
|
216
|
-
| `
|
|
217
|
-
|
|
218
|
-
That is every variable `config/environment.js` reads -- all ten. `authData`
|
|
219
|
-
(`{}`), `logColor` (`'white'`) and `logMethod` (`'socket'`) are also part of the
|
|
220
|
-
resolved config but are not settable from the environment. No environment value
|
|
221
|
-
is coerced: each resolves as the string the shell supplied.
|
|
222
|
-
|
|
223
|
-
> **If your app consumes this package and runs its own test suite:** pin all ten
|
|
224
|
-
> of these in your own `test/config/environment.js`, and keep `port` and
|
|
225
|
-
> `address` coupled -- `address` is computed from `port` at module-eval time, so
|
|
226
|
-
> pinning `port` alone does not move it. This package reads these variables
|
|
227
|
-
> unconditionally, so a `NODE_ENV=test` run in a shell that exports
|
|
228
|
-
> `SOCKET_ADDRESS` will dial whatever it names and send `authKey` to it. See
|
|
229
|
-
> [docs/configuration.md](docs/configuration.md#why-all-ten-keys-are-pinned).
|
|
224
|
+
| `authData` | — | `{}` | Extra fields sent with `authKey` in the auth request |
|
|
225
|
+
| `reconnectBaseDelay` | `SOCKET_RECONNECT_BASE_DELAY` | `1000` | First reconnect delay in ms (doubles per attempt) |
|
|
226
|
+
| `reconnectMaxDelay` | `SOCKET_RECONNECT_MAX_DELAY` | `60000` | Reconnect delay cap in ms |
|
|
227
|
+
| `maxReconnectAttempts` | `SOCKET_MAX_RECONNECT_ATTEMPTS` | `Infinity` | Attempts before `onReconnectFailed` |
|
|
230
228
|
|
|
231
229
|
## API Reference
|
|
232
230
|
|
|
@@ -237,7 +235,9 @@ is coerced: each resolves as the string the shell supplied.
|
|
|
237
235
|
| `new SocketServer()` | Singleton constructor |
|
|
238
236
|
| `async init()` | Discover handlers, validate auth, start WebSocket server |
|
|
239
237
|
| `sendTo(clientId, request, data)` | Send to one client by ID |
|
|
238
|
+
| `sendToByMeta(key, value, request, data)` | Send to the first authenticated client whose `meta[key] === value`; returns `true`/`false` |
|
|
240
239
|
| `broadcast(request, data)` | Send to all authenticated clients |
|
|
240
|
+
| `onClientDisconnect` | Optional `(client, code, reason)` callback |
|
|
241
241
|
| `clientMap` | `Map<id, client>` of connected clients |
|
|
242
242
|
| `close()` | Terminate all connections and stop the server |
|
|
243
243
|
| `reset()` | Close + clear all state (for testing) |
|
|
@@ -250,7 +250,8 @@ is coerced: each resolves as the string the shell supplied.
|
|
|
250
250
|
| `async init()` | Discover handlers, connect, authenticate |
|
|
251
251
|
| `send(payload)` | Send a message to the server |
|
|
252
252
|
| `close()` | Forcefully tear down the socket (remove listeners, terminate, null) |
|
|
253
|
-
| `reconnect()` | Reconnect (
|
|
253
|
+
| `reconnect()` | Reconnect with exponential backoff, up to `maxReconnectAttempts` (unlimited by default) |
|
|
254
|
+
| `onDisconnect`, `onReconnecting`, `onReconnected`, `onReconnectFailed` | Optional lifecycle callbacks |
|
|
254
255
|
| `reset()` | Close + clear all state (for testing) |
|
|
255
256
|
|
|
256
257
|
### Handler
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"stonyx-async",
|
|
5
5
|
"stonyx-module"
|
|
6
6
|
],
|
|
7
|
-
"version": "0.1.1-alpha.
|
|
7
|
+
"version": "0.1.1-alpha.39",
|
|
8
8
|
"description": "WebSocket server and client module for the Stonyx framework",
|
|
9
9
|
"main": "dist/main.js",
|
|
10
10
|
"types": "dist/main.d.ts",
|
|
@@ -51,11 +51,11 @@
|
|
|
51
51
|
},
|
|
52
52
|
"homepage": "https://github.com/abofs/stonyx-sockets#readme",
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"stonyx": "0.2.3-beta.
|
|
54
|
+
"stonyx": "0.2.3-beta.98",
|
|
55
55
|
"ws": "^8.18.1"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@stonyx/utils": "0.2.3-beta.
|
|
58
|
+
"@stonyx/utils": "0.2.3-beta.27",
|
|
59
59
|
"@types/node": "^25.5.2",
|
|
60
60
|
"@types/ws": "^8.18.1",
|
|
61
61
|
"qunit": "^2.24.1",
|