socket.io-redis
Advanced tools
Comparing version 5.4.0 to 6.0.0
@@ -0,1 +1,41 @@ | ||
# [6.0.0](https://github.com/socketio/socket.io-redis/compare/5.4.0...6.0.0) (2020-11-12) | ||
### Features | ||
* add support for Socket.IO v3 ([d9bcb19](https://github.com/socketio/socket.io-redis/commit/d9bcb1935940d7ad414ba7154de51cdc4a7d45b1)) | ||
### BREAKING CHANGES: | ||
- all the requests (for inter-node communication) now return a Promise instead of accepting a callback | ||
Before: | ||
```js | ||
io.of('/').adapter.allRooms((err, rooms) => { | ||
console.log(rooms); // an array containing all rooms (accross every node) | ||
}); | ||
``` | ||
After: | ||
```js | ||
const rooms = await io.of('/').adapter.allRooms(); | ||
console.log(rooms); // a Set containing all rooms (across every node) | ||
``` | ||
- RedisAdapter.clients() is renamed to RedisAdapter.sockets() | ||
See https://github.com/socketio/socket.io-adapter/commit/130f28a43c5aca924aa2c1a318422d21ba03cdac | ||
- RedisAdapter.customHook() and RedisAdapter.customRequest() are removed | ||
Those methods will be replaced by a more intuitive API in a future iteration. | ||
- support for Node.js 8 is dropped | ||
See https://github.com/nodejs/Release | ||
# [5.4.0](https://github.com/socketio/socket.io-redis/compare/5.3.0...5.4.0) (2020-09-02) | ||
@@ -2,0 +42,0 @@ |
{ | ||
"name": "socket.io-redis", | ||
"version": "5.4.0", | ||
"version": "6.0.0", | ||
"description": "", | ||
@@ -11,6 +11,11 @@ "license": "MIT", | ||
"files": [ | ||
"index.js" | ||
"dist/" | ||
], | ||
"main": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"scripts": { | ||
"test": "mocha" | ||
"test": "npm run format:check && tsc && nyc mocha test/index.js", | ||
"format:check": "prettier --parser typescript --check 'lib/**/*.ts' 'test/**/*.js'", | ||
"format:fix": "prettier --parser typescript --write 'lib/**/*.ts' 'test/**/*.js'", | ||
"prepack": "tsc" | ||
}, | ||
@@ -21,12 +26,19 @@ "dependencies": { | ||
"redis": "^3.0.0", | ||
"socket.io-adapter": "~1.1.0", | ||
"socket.io-adapter": "~2.0.0", | ||
"uid2": "0.0.3" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^14.14.7", | ||
"expect.js": "0.3.1", | ||
"ioredis": "^4.0.0", | ||
"mocha": "^3.4.2", | ||
"socket.io": "latest", | ||
"socket.io-client": "latest" | ||
"nyc": "^15.1.0", | ||
"prettier": "^2.1.2", | ||
"socket.io": "^3.0.1", | ||
"socket.io-client": "^3.0.1", | ||
"typescript": "^4.0.5" | ||
}, | ||
"engines": { | ||
"node": ">=10.0.0" | ||
} | ||
} |
124
README.md
@@ -6,2 +6,23 @@ # socket.io-redis | ||
## Table of contents | ||
- [How to use](#how-to-use) | ||
- [Compatibility table](#compatibility-table) | ||
- [API](#api) | ||
- [adapter(uri[, opts])](#adapteruri-opts) | ||
- [adapter(opts)](#adapteropts) | ||
- [RedisAdapter](#redisadapter) | ||
- [RedisAdapter#sockets(rooms: Set<String>)](#redisadaptersocketsrooms-setstring) | ||
- [RedisAdapter#allRooms()](#redisadapterallrooms) | ||
- [RedisAdapter#remoteJoin(id:String, room:String)](#redisadapterremotejoinidstring-roomstring) | ||
- [RedisAdapter#remoteLeave(id:String, room:String)](#redisadapterremoteleaveidstring-roomstring) | ||
- [RedisAdapter#remoteDisconnect(id:String, close:Boolean)](#redisadapterremotedisconnectidstring-closeboolean) | ||
- [Client error handling](#client-error-handling) | ||
- [Custom client (eg: with authentication)](#custom-client-eg-with-authentication) | ||
- [With ioredis client](#with-ioredishttpsgithubcomluinioredis-client) | ||
- [Cluster example](#cluster-example) | ||
- [Sentinel Example](#sentinel-example) | ||
- [Protocol](#protocol) | ||
- [License](#license) | ||
## How to use | ||
@@ -36,2 +57,10 @@ | ||
## Compatibility table | ||
| Redis Adapter version | Socket.IO server version | | ||
|-----------------------| ------------------------ | | ||
| 4.x | 1.x | | ||
| 5.x | 2.x | | ||
| 6.x | 3.x | | ||
## API | ||
@@ -70,90 +99,61 @@ | ||
### RedisAdapter#clients(rooms:Array, fn:Function) | ||
### RedisAdapter#sockets(rooms: Set<String>) | ||
Returns the list of client IDs connected to `rooms` across all nodes. See [Namespace#clients(fn:Function)](https://github.com/socketio/socket.io#namespaceclientsfnfunction) | ||
Returns the list of socket IDs connected to `rooms` across all nodes. See [Namespace#allSockets()](https://socket.io/docs/v3/server-api/#namespace-allSockets) | ||
```js | ||
io.of('/').adapter.clients((err, clients) => { | ||
console.log(clients); // an array containing all connected socket ids | ||
}); | ||
const sockets = await io.of('/').adapter.sockets(); | ||
console.log(sockets); // a Set containing all the connected socket ids | ||
io.of('/').adapter.clients(['room1', 'room2'], (err, clients) => { | ||
console.log(clients); // an array containing socket ids in 'room1' and/or 'room2' | ||
}); | ||
const sockets = await io.of('/').adapter.sockets(new Set(['room1', 'room2'])); | ||
console.log(sockets); // a Set containing the socket ids in 'room1' or in 'room2' | ||
// you can also use | ||
io.in('room3').clients((err, clients) => { | ||
console.log(clients); // an array containing socket ids in 'room3' | ||
}); | ||
// this method is also exposed by the Server instance | ||
const sockets = io.in('room3').allSockets(); | ||
console.log(sockets); // a Set containing the socket ids in 'room3' | ||
``` | ||
### RedisAdapter#clientRooms(id:String, fn:Function) | ||
### RedisAdapter#allRooms() | ||
Returns the list of rooms the client with the given ID has joined (even on another node). | ||
```js | ||
io.of('/').adapter.clientRooms('<my-id>', (err, rooms) => { | ||
if (err) { /* unknown id */ } | ||
console.log(rooms); // an array containing every room a given id has joined. | ||
}); | ||
``` | ||
### RedisAdapter#allRooms(fn:Function) | ||
Returns the list of all rooms. | ||
```js | ||
io.of('/').adapter.allRooms((err, rooms) => { | ||
console.log(rooms); // an array containing all rooms (accross every node) | ||
}); | ||
const rooms = await io.of('/').adapter.allRooms(); | ||
console.log(rooms); // a Set containing all rooms (across every node) | ||
``` | ||
### RedisAdapter#remoteJoin(id:String, room:String, fn:Function) | ||
### RedisAdapter#remoteJoin(id:String, room:String) | ||
Makes the socket with the given id join the room. The callback will be called once the socket has joined the room, or with an `err` argument if the socket was not found. | ||
Makes the socket with the given id join the room. | ||
```js | ||
io.of('/').adapter.remoteJoin('<my-id>', 'room1', (err) => { | ||
if (err) { /* unknown id */ } | ||
// success | ||
}); | ||
try { | ||
await io.of('/').adapter.remoteJoin('<my-id>', 'room1'); | ||
} catch (e) { | ||
// the socket was not found | ||
} | ||
``` | ||
### RedisAdapter#remoteLeave(id:String, room:String, fn:Function) | ||
### RedisAdapter#remoteLeave(id:String, room:String) | ||
Makes the socket with the given id leave the room. The callback will be called once the socket has left the room, or with an `err` argument if the socket was not found. | ||
Makes the socket with the given id leave the room. | ||
```js | ||
io.of('/').adapter.remoteLeave('<my-id>', 'room1', (err) => { | ||
if (err) { /* unknown id */ } | ||
// success | ||
}); | ||
try { | ||
await io.of('/').adapter.remoteLeave('<my-id>', 'room1'); | ||
} catch (e) { | ||
// the socket was not found | ||
} | ||
``` | ||
### RedisAdapter#remoteDisconnect(id:String, close:Boolean, fn:Function) | ||
### RedisAdapter#remoteDisconnect(id:String, close:Boolean) | ||
Makes the socket with the given id to get disconnected. If `close` is set to true, it also closes the underlying socket. The callback will be called once the socket was disconnected, or with an `err` argument if the socket was not found. | ||
Makes the socket with the given id to get disconnected. If `close` is set to true, it also closes the underlying socket. | ||
```js | ||
io.of('/').adapter.remoteDisconnect('<my-id>', true, (err) => { | ||
if (err) { /* unknown id */ } | ||
// success | ||
}); | ||
``` | ||
### RedisAdapter#customRequest(data:Object, fn:Function) | ||
Sends a request to every nodes, that will respond through the `customHook` method. | ||
```js | ||
// on every node | ||
io.of('/').adapter.customHook = (data, cb) => { | ||
cb('hello ' + data); | ||
try { | ||
await io.of('/').adapter.remoteDisconnect('<my-id>', true); | ||
} catch (e) { | ||
// the socket was not found | ||
} | ||
// then | ||
io.of('/').adapter.customRequest('john', function(err, replies){ | ||
console.log(replies); // an array ['hello john', ...] with one element per node | ||
}); | ||
``` | ||
@@ -196,3 +196,3 @@ | ||
## With [ioredis](https://github.com/luin/ioredis) client | ||
## With ioredis client | ||
@@ -199,0 +199,0 @@ ### Cluster example |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31422
6
9
572
1
1
+ Addedsocket.io-adapter@2.0.3(transitive)
- Removedsocket.io-adapter@1.1.2(transitive)
Updatedsocket.io-adapter@~2.0.0