socket.io-adapter
Advanced tools
Comparing version 2.3.3 to 2.4.0
@@ -11,2 +11,3 @@ /// <reference types="node" /> | ||
binary?: boolean; | ||
timeout?: number; | ||
} | ||
@@ -38,2 +39,8 @@ export interface BroadcastOptions { | ||
/** | ||
* Returns the number of Socket.IO servers in the cluster | ||
* | ||
* @public | ||
*/ | ||
serverCount(): Promise<number>; | ||
/** | ||
* Adds a socket to a list of room. | ||
@@ -74,2 +81,18 @@ * | ||
/** | ||
* Broadcasts a packet and expects multiple acknowledgements. | ||
* | ||
* Options: | ||
* - `flags` {Object} flags for this packet | ||
* - `except` {Array} sids that should be excluded | ||
* - `rooms` {Array} list of rooms to broadcast to | ||
* | ||
* @param {Object} packet the packet object | ||
* @param {Object} opts the options | ||
* @param clientCountCallback - the number of clients that received the packet | ||
* @param ack - the callback that will be called for each client response | ||
* | ||
* @public | ||
*/ | ||
broadcastWithAck(packet: any, opts: BroadcastOptions, clientCountCallback: (clientCount: number) => void, ack: (...args: any[]) => void): void; | ||
/** | ||
* Gets a list of sockets by sid. | ||
@@ -76,0 +99,0 @@ * |
@@ -27,2 +27,10 @@ "use strict"; | ||
/** | ||
* Returns the number of Socket.IO servers in the cluster | ||
* | ||
* @public | ||
*/ | ||
serverCount() { | ||
return Promise.resolve(1); | ||
} | ||
/** | ||
* Adds a socket to a list of room. | ||
@@ -110,2 +118,5 @@ * | ||
this.apply(opts, socket => { | ||
if (typeof socket.notifyOutgoingListeners === "function") { | ||
socket.notifyOutgoingListeners(packet); | ||
} | ||
socket.client.writeToEngine(encodedPackets, packetOpts); | ||
@@ -115,2 +126,41 @@ }); | ||
/** | ||
* Broadcasts a packet and expects multiple acknowledgements. | ||
* | ||
* Options: | ||
* - `flags` {Object} flags for this packet | ||
* - `except` {Array} sids that should be excluded | ||
* - `rooms` {Array} list of rooms to broadcast to | ||
* | ||
* @param {Object} packet the packet object | ||
* @param {Object} opts the options | ||
* @param clientCountCallback - the number of clients that received the packet | ||
* @param ack - the callback that will be called for each client response | ||
* | ||
* @public | ||
*/ | ||
broadcastWithAck(packet, opts, clientCountCallback, ack) { | ||
const flags = opts.flags || {}; | ||
const packetOpts = { | ||
preEncoded: true, | ||
volatile: flags.volatile, | ||
compress: flags.compress | ||
}; | ||
packet.nsp = this.nsp.name; | ||
// we can use the same id for each packet, since the _ids counter is common (no duplicate) | ||
packet.id = this.nsp._ids++; | ||
const encodedPackets = this.encoder.encode(packet); | ||
let clientCount = 0; | ||
this.apply(opts, socket => { | ||
// track the total number of acknowledgements that are expected | ||
clientCount++; | ||
// call the ack callback for each client response | ||
socket.acks.set(packet.id, ack); | ||
if (typeof socket.notifyOutgoingListeners === "function") { | ||
socket.notifyOutgoingListeners(packet); | ||
} | ||
socket.client.writeToEngine(encodedPackets, packetOpts); | ||
}); | ||
clientCountCallback(clientCount); | ||
} | ||
/** | ||
* Gets a list of sockets by sid. | ||
@@ -225,5 +275,5 @@ * | ||
serverSideEmit(packet) { | ||
throw new Error("this adapter does not support the serverSideEmit() functionality"); | ||
console.warn("this adapter does not support the serverSideEmit() functionality"); | ||
} | ||
} | ||
exports.Adapter = Adapter; |
{ | ||
"name": "socket.io-adapter", | ||
"version": "2.3.3", | ||
"version": "2.4.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "repository": { |
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
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
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
15078
5
415