Skip to content

Commit 0fada40

Browse files
committed
docs(websockets): update for extend socket.io
1 parent 71bb3bf commit 0fada40

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

content/websockets/adapter.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,21 @@ The WebSockets module is platform-agnostic, hence, you can bring your own librar
3030
The [socket.io](https://github.com/socketio/socket.io) package is wrapped in an `IoAdapter` class. What if you would like to enhance the basic functionality of the adapter? For instance, your technical requirements require a capability to broadcast events across multiple load-balanced instances of your web service. For this, you can extend `IoAdapter` and override a single method which responsibility is to instantiate new socket.io servers. But first of all, let's install the required package.
3131

3232
```bash
33-
$ npm i --save socket.io-redis
33+
$ npm i --save @socket.io/redis-adapter
3434
```
3535

3636
Once the package is installed, we can create a `RedisIoAdapter` class.
3737

3838
```typescript
3939
import { IoAdapter } from '@nestjs/platform-socket.io';
40-
import { RedisClient } from 'redis';
41-
import { ServerOptions } from 'socket.io';
42-
import { createAdapter } from 'socket.io-redis';
40+
import { Server, ServerOptions } from 'socket.io';
41+
import { createAdapter } from '@socket.io/redis-adapter';
42+
import { createClient } from 'redis';
4343

44-
const pubClient = new RedisClient({ host: 'localhost', port: 6379 });
44+
const io = new Server();
45+
const pubClient = createClient({ url: `redis://localhost:6379` });
4546
const subClient = pubClient.duplicate();
46-
const redisAdapter = createAdapter({ pubClient, subClient });
47-
47+
const redisAdapter = io.adapter(createAdapter(pubClient, subClient));
4848
export class RedisIoAdapter extends IoAdapter {
4949
createIOServer(port: number, options?: ServerOptions): any {
5050
const server = super.createIOServer(port, options);

0 commit comments

Comments
 (0)