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
maxPayload:1048576, // we set the maximum allowed messages size to 1 MiB (1024 bytes * 1024 bytes)
26
+
path:'/fastify', // we accept only connections matching this path e.g.: ws://localhost:3000/fastify
27
+
verifyClient:function (info, next) {
28
+
if (info.req.headers['x-fastify-header'] !=='fastify is awesome !') {
29
+
returnnext(false) // the connection is not allowed
30
+
}
31
+
32
+
next(true) // the connection is allowed
33
+
}
34
+
}
35
+
36
+
fastify.register(require('fastify-websocket'), {
37
+
handle,
38
+
options: wssOptions
39
+
})
16
40
17
41
functionhandle (conn) {
18
-
conn.pipe(conn) // creates a echo server
42
+
conn.pipe(conn) // creates an echo server
19
43
}
20
44
21
-
fastify.listen(0)
45
+
fastify.listen(3000, (err) => {
46
+
if (err) {
47
+
fastify.log.error(err);
48
+
process.exit(1);
49
+
}
50
+
})
22
51
```
23
52
53
+
## Options :
54
+
`fastify-websocket` accept the same options as [`websocket-stream`](https://github.com/maxogden/websocket-stream#options) and as [`ws`](https://github.com/websockets/ws/blob/master/doc/ws.md#new-websocketserveroptions-callback) :
55
+
56
+
-`objectMode` - Send each chunk on its own, and do not try to pack them in a single websocket frame.
57
+
-`host` - The hostname where to bind the server.
58
+
-`port` - The port where to bind the server.
59
+
-`backlog` - The maximum length of the queue of pending connections.
60
+
-`server` - A pre-created Node.js HTTP/S server.
61
+
-`verifyClient` - A function which can be used to validate incoming connections.
62
+
-`handleProtocols` - A function which can be used to handle the WebSocket subprotocols.
63
+
-`path` - Accept only connections matching this path.
64
+
-`noServer` - Enable no server mode.
65
+
-`clientTracking` - Specifies whether or not to track clients.
-`maxPayload` - The maximum allowed message size in bytes.
68
+
69
+
For more informations you can check [`ws` options documentation](https://github.com/websockets/ws/blob/master/doc/ws.md#new-websocketserveroptions-callback) and [`websocket-stream` options documentation](https://github.com/maxogden/websocket-stream#options).
70
+
71
+
_**NB:** By default if you do not provide a `server` option `fastify-websocket` will bind your websocket server instance to the scoped `fastify` instance._
0 commit comments