Skip to content

Commit 9a21efa

Browse files
authored
docs(readme): spelling and grammar fixes (#322)
Signed-off-by: Frazer Smith <[email protected]>
1 parent e1ad31b commit 9a21efa

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

README.md

+10-11
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ packageExtensions:
3434
3535
## Usage
3636
37-
After registering this plugin, you can choose on which routes the WS server will respond. This can be achieved by adding `websocket: true` property to `routeOptions` on a fastify's `.get` route. In this case two arguments will be passed to the handler, the socket connection, and the `fastify` request object:
37+
After registering this plugin, you can choose on which routes the WS server will respond. This can be achieved by adding `websocket: true` property to `routeOptions` on a fastify's `.get` route. In this case, two arguments will be passed to the handler, the socket connection, and the `fastify` request object:
3838

3939
```js
4040
'use strict'
@@ -60,7 +60,7 @@ fastify.listen({ port: 3000 }, err => {
6060

6161
In this case, it will respond with a 404 error on every unregistered route, closing the incoming upgrade connection requests.
6262

63-
However, you can still define a wildcard route, that will be used as default handler:
63+
However, you can still define a wildcard route, that will be used as the default handler:
6464

6565
```js
6666
'use strict'
@@ -96,8 +96,7 @@ fastify.listen({ port: 3000 }, err => {
9696
```
9797

9898
### Attaching event handlers
99-
100-
It is important that websocket route handlers attach event handlers synchronously during handler execution to avoid accidentally dropping messages. If you want to do any async work in your websocket handler, say to authenticate a user or load data from a datastore, ensure you attach any `on('message')` handlers *before* you trigger this async work. Otherwise, messages might arrive whilst this async work is underway, and if there is no handler listening for this data it will be silently dropped.
99+
Websocket route handlers must attach event handlers synchronously during handler execution to avoid accidentally dropping messages. If you want to do any async work in your websocket handler, say to authenticate a user or load data from a datastore, ensure you attach any `on('message')` handlers *before* you trigger this async work. Otherwise, messages might arrive whilst this async work is underway, and if there is no handler listening for this data it will be silently dropped.
101100

102101
Here is an example of how to attach message handlers synchronously while still accessing asynchronous resources. We store a promise for the async thing in a local variable, attach the message handler synchronously, and then make the message handler itself asynchronous to grab the async data and do some processing:
103102

@@ -266,8 +265,8 @@ fastify.register(require('@fastify/websocket'), {
266265

267266
### Testing
268267

269-
Testing the ws handler can be quite tricky, luckily `fastify-websocket` decorates fastify instance with `injectWS`.
270-
It allows to test easily a websocket endpoint.
268+
Testing the ws handler can be quite tricky, luckily `fastify-websocket` decorates fastify instance with `injectWS`,
269+
which allows easy testing of a websocket endpoint.
271270

272271
The signature of injectWS is the following: `([path], [upgradeContext])`.
273272

@@ -359,9 +358,9 @@ test('connect to /', async (t) => {
359358
```
360359

361360
#### Things to know
362-
- Websocket need to be closed manually at the end of each test.
361+
- Websocket needs to be closed manually at the end of each test.
363362
- `fastify.ready()` needs to be awaited to ensure that fastify has been decorated.
364-
- You need to register the event listener before sending the message if you need to process server response.
363+
- You need to register the event listener before sending the message if you need to process the server response.
365364

366365
## Options
367366

@@ -371,8 +370,8 @@ test('connect to /', async (t) => {
371370
- `port` - The port where to bind the server.
372371
- `backlog` - The maximum length of the queue of pending connections.
373372
- `server` - A pre-created Node.js HTTP/S server.
374-
- `verifyClient` - A function which can be used to validate incoming connections.
375-
- `handleProtocols` - A function which can be used to handle the WebSocket subprotocols.
373+
- `verifyClient` - A function that can be used to validate incoming connections.
374+
- `handleProtocols` - A function that can be used to handle the WebSocket subprotocols.
376375
- `clientTracking` - Specifies whether or not to track clients.
377376
- `perMessageDeflate` - Enable/disable permessage-deflate.
378377
- `maxPayload` - The maximum allowed message size in bytes.
@@ -386,7 +385,7 @@ _**NB** The `path` option from `ws` should not be provided since the routing is
386385
_**NB** The `noServer` option from `ws` should not be provided since the point of @fastify/websocket is to listen on the fastify server. If you want a custom server, you can use the `server` option, and if you want more control, you can use the `ws` library directly_
387386

388387
[ws](https://github.com/websockets/ws) does not allow you to set `objectMode` or `writableObjectMode` to true
389-
## Acknowledgements
388+
## Acknowledgments
390389

391390
This project is kindly sponsored by [nearForm](https://nearform.com).
392391

0 commit comments

Comments
 (0)