Skip to content

Commit ef8986a

Browse files
authored
docs: update references to old fastify-* modules (#196)
1 parent 7becc2c commit ef8986a

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# fastify-websocket
1+
# @fastify/websocket
22

33
![CI](https://github.com/fastify/fastify-websocket/workflows/CI/badge.svg)
4-
[![NPM version](https://img.shields.io/npm/v/fastify-websocket.svg?style=flat)](https://www.npmjs.com/package/fastify-websocket)
4+
[![NPM version](https://img.shields.io/npm/v/@fastify/websocket.svg?style=flat)](https://www.npmjs.com/package/@fastify/websocket)
55
[![Known Vulnerabilities](https://snyk.io/test/github/fastify/fastify-websocket/badge.svg)](https://snyk.io/test/github/fastify/fastify-websocket)
66
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/)
77

@@ -11,9 +11,9 @@ Built upon [ws@8](https://www.npmjs.com/package/ws).
1111
## Install
1212

1313
```shell
14-
npm install fastify-websocket --save
14+
npm install @fastify/websocket --save
1515
# or
16-
yarn add fastify-websocket
16+
yarn add @fastify/websocket
1717
```
1818

1919
If you're a TypeScript user, this package has its own TypeScript types built in, but you will also need to install the types for the `ws` package:
@@ -32,7 +32,7 @@ After registering this plugin, you can choose on which routes the WS server will
3232
'use strict'
3333

3434
const fastify = require('fastify')()
35-
fastify.register(require('fastify-websocket'))
35+
fastify.register(require('@fastify/websocket'))
3636

3737
fastify.get('/', { websocket: true }, (connection /* SocketStream */, req /* FastifyRequest */) => {
3838
connection.socket.on('message', message => {
@@ -58,7 +58,7 @@ However, you can still define a wildcard route, that will be used as default han
5858

5959
const fastify = require('fastify')()
6060

61-
fastify.register(require('fastify-websocket'), {
61+
fastify.register(require('@fastify/websocket'), {
6262
options: { maxPayload: 1048576 }
6363
})
6464

@@ -103,7 +103,7 @@ fastify.get('/*', { websocket: true }, (connection, request) => {
103103
```
104104
### Using hooks
105105

106-
Routes registered with `fastify-websocket` respect the Fastify plugin encapsulation contexts, and so will run any hooks that have been registered. This means the same route hooks you might use for authentication or error handling of plain old HTTP handlers will apply to websocket handlers as well.
106+
Routes registered with `@fastify/websocket` respect the Fastify plugin encapsulation contexts, and so will run any hooks that have been registered. This means the same route hooks you might use for authentication or error handling of plain old HTTP handlers will apply to websocket handlers as well.
107107

108108
```js
109109
fastify.addHook('preValidation', async (request, reply) => {
@@ -124,14 +124,14 @@ fastify.get('/', { websocket: true }, (connection, req) => {
124124
This plugin uses the same router as the `fastify` instance, this has a few implications to take into account:
125125
- Websocket route handlers follow the usual `fastify` request lifecycle, which means hooks, error handlers, and decorators all work the same way as other route handlers.
126126
- You can access the fastify server via `this` in your handlers
127-
- When using `fastify-websocket`, it needs to be registered before all routes in order to be able to intercept websocket connections to existing routes and close the connection on non-websocket routes.
127+
- When using `@fastify/websocket`, it needs to be registered before all routes in order to be able to intercept websocket connections to existing routes and close the connection on non-websocket routes.
128128

129129
```js
130130
'use strict'
131131

132132
const fastify = require('fastify')()
133133

134-
fastify.register(require('fastify-websocket'))
134+
fastify.register(require('@fastify/websocket'))
135135

136136
fastify.get('/', { websocket: true }, function wsHandler (connection, req) {
137137
// bound to fastify server
@@ -162,7 +162,7 @@ function handle (conn, req) {
162162
conn.pipe(conn) // creates an echo server
163163
}
164164

165-
fastify.register(require('fastify-websocket'), {
165+
fastify.register(require('@fastify/websocket'), {
166166
handle,
167167
options: { maxPayload: 1048576 }
168168
})
@@ -202,7 +202,7 @@ You can optionally provide a custom errorHandler that will be used to handle any
202202

203203
const fastify = require('fastify')()
204204

205-
fastify.register(require('fastify-websocket'), {
205+
fastify.register(require('@fastify/websocket'), {
206206
errorHandler: function (error, conn /* SocketStream */, req /* FastifyRequest */, reply /* FastifyReply */) {
207207
// Do stuff
208208
// destroy/close connection
@@ -236,7 +236,7 @@ fastify.listen(3000, err => {
236236

237237
## Options
238238

239-
`fastify-websocket` accept these options for [`ws`](https://github.com/websockets/ws/blob/master/doc/ws.md#new-websocketserveroptions-callback) :
239+
`@fastify/websocket` accept these options for [`ws`](https://github.com/websockets/ws/blob/master/doc/ws.md#new-websocketserveroptions-callback) :
240240

241241
- `host` - The hostname where to bind the server.
242242
- `port` - The port where to bind the server.
@@ -250,11 +250,11 @@ fastify.listen(3000, err => {
250250

251251
For more information, you can check [`ws` options documentation](https://github.com/websockets/ws/blob/master/doc/ws.md#new-websocketserveroptions-callback).
252252

253-
_**NB** By default if you do not provide a `server` option `fastify-websocket` will bind your websocket server instance to the scoped `fastify` instance._
253+
_**NB** By default if you do not provide a `server` option `@fastify/websocket` will bind your websocket server instance to the scoped `fastify` instance._
254254

255255
_**NB** The `path` option from `ws` should not be provided since the routing is handled by fastify itself_
256256

257-
_**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_
257+
_**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_
258258

259259
You can also pass the following as `connectionOptions` for [createWebSocketStream](https://github.com/websockets/ws/blob/master/doc/ws.md#createwebsocketstreamwebsocket-options).
260260

0 commit comments

Comments
 (0)