@socket.io/redis-emitter
Advanced tools
Comparing version 4.0.0 to 4.1.0
@@ -0,3 +1,12 @@ | ||
# [4.1.0](https://github.com/socketio/socket.io-redis-emitter/compare/4.0.0...4.1.0) (2021-05-11) | ||
### Features | ||
* implement the serverSideEmit functionality ([5feabda](https://github.com/socketio/socket.io-redis-emitter/commit/5feabdac98f0ae44f30dcf36a29a8be328be139e)) | ||
# [4.0.0](https://github.com/socketio/socket.io-emitter/compare/3.2.0...4.0.0) (2021-03-17) | ||
**Important note**: the name of the package was updated from `socket.io-emitter` to `@socket.io/redis-emitter` in order to better reflect the relationship with Redis. | ||
@@ -24,3 +33,3 @@ ### Features | ||
```js | ||
const { Emitter } = require("socket.io-emitter"); | ||
const { Emitter } = require("@socket.io/redis-emitter"); | ||
const { createClient } = require("redis"); | ||
@@ -27,0 +36,0 @@ |
@@ -99,2 +99,8 @@ import type { DefaultEventsMap, EventNames, EventParams, EventsMap, TypedEventBroadcaster } from "./typed-events"; | ||
disconnectSockets(close?: boolean): void; | ||
/** | ||
* Send a packet to the Socket.IO servers in the cluster | ||
* | ||
* @param args - any number of serializable arguments | ||
*/ | ||
serverSideEmit(...args: any[]): void; | ||
} | ||
@@ -101,0 +107,0 @@ export declare const RESERVED_EVENTS: ReadonlySet<string | Symbol>; |
@@ -20,2 +20,3 @@ "use strict"; | ||
RequestType[RequestType["REMOTE_FETCH"] = 5] = "REMOTE_FETCH"; | ||
RequestType[RequestType["SERVER_SIDE_EMIT"] = 6] = "SERVER_SIDE_EMIT"; | ||
})(RequestType || (RequestType = {})); | ||
@@ -132,2 +133,19 @@ class Emitter { | ||
} | ||
/** | ||
* Send a packet to the Socket.IO servers in the cluster | ||
* | ||
* @param args - any number of serializable arguments | ||
*/ | ||
serverSideEmit(...args) { | ||
const withAck = typeof args[args.length - 1] === "function"; | ||
if (withAck) { | ||
throw new Error("Acknowledgements are not supported"); | ||
} | ||
const request = JSON.stringify({ | ||
uid: UID, | ||
type: RequestType.SERVER_SIDE_EMIT, | ||
data: args, | ||
}); | ||
this.redisClient.publish(this.broadcastOptions.requestChannel, request); | ||
} | ||
} | ||
@@ -134,0 +152,0 @@ exports.Emitter = Emitter; |
{ | ||
"name": "@socket.io/redis-emitter", | ||
"version": "4.0.0", | ||
"version": "4.1.0", | ||
"description": "The Socket.IO Redis emitter, allowing to communicate with a group of Socket.IO servers from another Node.js process", | ||
@@ -8,3 +8,3 @@ "license": "MIT", | ||
"type": "git", | ||
"url": "https://github.com/socketio/socket.io-emitter.git" | ||
"url": "https://github.com/socketio/socket.io-redis-emitter.git" | ||
}, | ||
@@ -28,2 +28,3 @@ "files": [ | ||
"devDependencies": { | ||
"@socket.io/redis-adapter": "^7.0.0", | ||
"@types/mocha": "^8.2.1", | ||
@@ -37,5 +38,4 @@ "@types/node": "^14.14.35", | ||
"redis": "^3.0.2", | ||
"socket.io": "^4.0.0", | ||
"socket.io-client": "^4.0.0", | ||
"socket.io-redis": "^6.1.0", | ||
"socket.io": "^4.1.1", | ||
"socket.io-client": "^4.1.1", | ||
"ts-node": "^9.1.1", | ||
@@ -42,0 +42,0 @@ "typescript": "^4.2.3" |
# The Socket.IO Redis emitter | ||
[](https://github.com/socketio/socket.io-emitter/actions) | ||
[](http://badge.fury.io/js/socket.io-emitter) | ||
[](https://github.com/socketio/socket.io-redis-emitter/actions) | ||
[](https://www.npmjs.com/package/@socket.io/redis-emitter) | ||
@@ -20,3 +20,3 @@ The `@socket.io/redis-emitter` package allows you to easily communicate with a group of Socket.IO servers from another Node.js process (server-side). | ||
It must be used in conjunction with [socket.io-redis](https://github.com/socketio/socket.io-redis/). | ||
It must be used in conjunction with [`@socket.io/redis-adapter`](https://github.com/socketio/socket.io-redis-adapter/). | ||
@@ -52,3 +52,3 @@ The current version is compatible with both: | ||
```js | ||
const { Emitter } = require("socket.io-emitter"); | ||
const { Emitter } = require("@socket.io/redis-emitter"); | ||
const { createClient } = require("redis"); // not included, needs to be explicitly installed | ||
@@ -69,3 +69,3 @@ | ||
```ts | ||
import { Emitter } from "socket.io-emitter"; | ||
import { Emitter } from "@socket.io/redis-emitter"; | ||
import { createClient } from "redis"; | ||
@@ -100,3 +100,3 @@ | ||
```js | ||
const { Emitter } = require("socket.io-emitter"); | ||
const { Emitter } = require("@socket.io/redis-emitter"); | ||
const { createClient } = require("redis"); // not included, needs to be explicitly installed | ||
@@ -103,0 +103,0 @@ |
28544
530