socket.io
Advanced tools
Comparing version 4.0.2 to 4.1.0
@@ -0,1 +1,17 @@ | ||
# [4.1.0](https://github.com/socketio/socket.io/compare/4.0.2...4.1.0) (2021-05-11) | ||
### Features | ||
* add support for inter-server communication ([93cce05](https://github.com/socketio/socket.io/commit/93cce05fb3faf91f21fa71212275c776aa161107)) | ||
* notify upon namespace creation ([499c892](https://github.com/socketio/socket.io/commit/499c89250d2db1ab7725ab2b74840e188c267c46)) | ||
* add a "connection_error" event ([7096e98](https://github.com/socketio/engine.io/commit/7096e98a02295a62c8ea2aa56461d4875887092d), from `engine.io`) | ||
* add the "initial_headers" and "headers" events ([2527543](https://github.com/socketio/engine.io/commit/252754353a0e88eb036ebb3082e9d6a9a5f497db), from `engine.io`) | ||
### Performance Improvements | ||
* add support for the "wsPreEncoded" writing option ([dc381b7](https://github.com/socketio/socket.io/commit/dc381b72c6b2f8172001dedd84116122e4cc95b3)) | ||
## [4.0.2](https://github.com/socketio/socket.io/compare/4.0.1...4.0.2) (2021-05-06) | ||
@@ -2,0 +18,0 @@ |
@@ -7,3 +7,8 @@ /// <reference types="node" /> | ||
import type { Socket } from "./socket"; | ||
export declare class Client<ListenEvents extends EventsMap, EmitEvents extends EventsMap> { | ||
interface WriteOptions { | ||
compress?: boolean; | ||
volatile?: boolean; | ||
wsPreEncoded?: string; | ||
} | ||
export declare class Client<ListenEvents extends EventsMap, EmitEvents extends EventsMap, ServerSideEvents extends EventsMap> { | ||
readonly conn: any; | ||
@@ -24,3 +29,3 @@ private readonly id; | ||
*/ | ||
constructor(server: Server<ListenEvents, EmitEvents>, conn: any); | ||
constructor(server: Server<ListenEvents, EmitEvents, ServerSideEvents>, conn: any); | ||
/** | ||
@@ -66,3 +71,3 @@ * @return the reference to the request that originated the Engine.IO connection | ||
*/ | ||
_remove(socket: Socket<ListenEvents, EmitEvents>): void; | ||
_remove(socket: Socket<ListenEvents, EmitEvents, ServerSideEvents>): void; | ||
/** | ||
@@ -81,3 +86,4 @@ * Closes the underlying connection. | ||
*/ | ||
_packet(packet: Packet, opts?: any): void; | ||
_packet(packet: Packet, opts?: WriteOptions): void; | ||
private writeToEngine; | ||
/** | ||
@@ -115,1 +121,2 @@ * Called with incoming transport data. | ||
} | ||
export {}; |
@@ -153,28 +153,18 @@ "use strict"; | ||
*/ | ||
_packet(packet, opts) { | ||
opts = opts || {}; | ||
const self = this; | ||
// this writes to the actual connection | ||
function writeToEngine(encodedPackets) { | ||
// TODO clarify this. | ||
if (opts.volatile && !self.conn.transport.writable) | ||
return; | ||
for (let i = 0; i < encodedPackets.length; i++) { | ||
self.conn.write(encodedPackets[i], { compress: opts.compress }); | ||
} | ||
_packet(packet, opts = {}) { | ||
if (this.conn.readyState !== "open") { | ||
debug("ignoring packet write %j", packet); | ||
return; | ||
} | ||
if ("open" === this.conn.readyState) { | ||
debug("writing packet %j", packet); | ||
if (!opts.preEncoded) { | ||
// not broadcasting, need to encode | ||
writeToEngine(this.encoder.encode(packet)); // encode, then write results to engine | ||
} | ||
else { | ||
// a broadcast pre-encodes a packet | ||
writeToEngine(packet); | ||
} | ||
const encodedPackets = this.encoder.encode(packet); | ||
for (const encodedPacket of encodedPackets) { | ||
this.writeToEngine(encodedPacket, opts); | ||
} | ||
else { | ||
debug("ignoring packet write %j", packet); | ||
} | ||
writeToEngine(encodedPacket, opts) { | ||
if (opts.volatile && !this.conn.transport.writable) { | ||
debug("volatile packet is discarded since the transport is not currently writable"); | ||
return; | ||
} | ||
this.conn.write(encodedPacket, opts); | ||
} | ||
@@ -181,0 +171,0 @@ /** |
/// <reference types="node" /> | ||
import http = require("http"); | ||
import { ExtendedError, Namespace, NamespaceReservedEventsMap } from "./namespace"; | ||
import { ExtendedError, Namespace, ServerReservedEventsMap } from "./namespace"; | ||
import { Adapter, Room, SocketId } from "socket.io-adapter"; | ||
@@ -11,3 +11,3 @@ import * as parser from "socket.io-parser"; | ||
import type { BroadcastOperator, RemoteSocket } from "./broadcast-operator"; | ||
import { EventsMap, DefaultEventsMap, EventParams, StrictEventEmitter } from "./typed-events"; | ||
import { EventsMap, DefaultEventsMap, EventParams, StrictEventEmitter, EventNames } from "./typed-events"; | ||
declare type Transport = "polling" | "websocket"; | ||
@@ -139,4 +139,4 @@ declare type ParentNspNameMatchFn = (name: string, auth: { | ||
} | ||
export declare class Server<ListenEvents extends EventsMap = DefaultEventsMap, EmitEvents extends EventsMap = ListenEvents> extends StrictEventEmitter<{}, EmitEvents, NamespaceReservedEventsMap<ListenEvents, EmitEvents>> { | ||
readonly sockets: Namespace<ListenEvents, EmitEvents>; | ||
export declare class Server<ListenEvents extends EventsMap = DefaultEventsMap, EmitEvents extends EventsMap = ListenEvents, ServerSideEvents extends EventsMap = {}> extends StrictEventEmitter<ServerSideEvents, EmitEvents, ServerReservedEventsMap<ListenEvents, EmitEvents, ServerSideEvents>> { | ||
readonly sockets: Namespace<ListenEvents, EmitEvents, ServerSideEvents>; | ||
/** | ||
@@ -160,3 +160,3 @@ * A reference to the underlying Engine.IO server. | ||
*/ | ||
_nsps: Map<string, Namespace<ListenEvents, EmitEvents>>; | ||
_nsps: Map<string, Namespace<ListenEvents, EmitEvents, ServerSideEvents>>; | ||
private parentNsps; | ||
@@ -205,3 +205,3 @@ private _adapter?; | ||
[key: string]: any; | ||
}, fn: (nsp: Namespace<ListenEvents, EmitEvents> | false) => void): void; | ||
}, fn: (nsp: Namespace<ListenEvents, EmitEvents, ServerSideEvents> | false) => void): void; | ||
/** | ||
@@ -306,3 +306,3 @@ * Sets the client serving path. | ||
*/ | ||
of(name: string | RegExp | ParentNspNameMatchFn, fn?: (socket: Socket<ListenEvents, EmitEvents>) => void): Namespace<ListenEvents, EmitEvents>; | ||
of(name: string | RegExp | ParentNspNameMatchFn, fn?: (socket: Socket<ListenEvents, EmitEvents, ServerSideEvents>) => void): Namespace<ListenEvents, EmitEvents, ServerSideEvents>; | ||
/** | ||
@@ -321,3 +321,3 @@ * Closes server connection | ||
*/ | ||
use(fn: (socket: Socket<ListenEvents, EmitEvents>, next: (err?: ExtendedError) => void) => void): this; | ||
use(fn: (socket: Socket<ListenEvents, EmitEvents, ServerSideEvents>, next: (err?: ExtendedError) => void) => void): this; | ||
/** | ||
@@ -346,3 +346,3 @@ * Targets a room when emitting. | ||
*/ | ||
except(name: Room | Room[]): Server<ListenEvents, EmitEvents>; | ||
except(name: Room | Room[]): Server<ListenEvents, EmitEvents, ServerSideEvents>; | ||
/** | ||
@@ -363,2 +363,10 @@ * Sends a `message` event to all clients. | ||
/** | ||
* Emit a packet to other Socket.IO servers | ||
* | ||
* @param ev - the event name | ||
* @param args - an array of arguments, which may include an acknowledgement callback at the end | ||
* @public | ||
*/ | ||
serverSideEmit<Ev extends EventNames<ServerSideEvents>>(ev: Ev, ...args: EventParams<ServerSideEvents, Ev>): boolean; | ||
/** | ||
* Gets a list of socket ids. | ||
@@ -365,0 +373,0 @@ * |
@@ -101,3 +101,8 @@ "use strict"; | ||
else { | ||
fn(this.parentNsps.get(nextFn.value).createChild(name)); | ||
const namespace = this.parentNsps | ||
.get(nextFn.value) | ||
.createChild(name); | ||
// @ts-ignore | ||
this.sockets.emitReserved("new_namespace", namespace); | ||
fn(namespace); | ||
} | ||
@@ -342,2 +347,6 @@ }); | ||
this._nsps.set(name, nsp); | ||
if (name !== "/") { | ||
// @ts-ignore | ||
this.sockets.emitReserved("new_namespace", nsp); | ||
} | ||
} | ||
@@ -428,2 +437,12 @@ if (fn) | ||
/** | ||
* Emit a packet to other Socket.IO servers | ||
* | ||
* @param ev - the event name | ||
* @param args - an array of arguments, which may include an acknowledgement callback at the end | ||
* @public | ||
*/ | ||
serverSideEmit(ev, ...args) { | ||
return this.sockets.serverSideEmit(ev, ...args); | ||
} | ||
/** | ||
* Gets a list of socket ids. | ||
@@ -430,0 +449,0 @@ * |
@@ -10,14 +10,18 @@ import { Socket } from "./socket"; | ||
} | ||
export interface NamespaceReservedEventsMap<ListenEvents extends EventsMap, EmitEvents extends EventsMap> { | ||
connect: (socket: Socket<ListenEvents, EmitEvents>) => void; | ||
connection: (socket: Socket<ListenEvents, EmitEvents>) => void; | ||
export interface NamespaceReservedEventsMap<ListenEvents extends EventsMap, EmitEvents extends EventsMap, ServerSideEvents extends EventsMap> { | ||
connect: (socket: Socket<ListenEvents, EmitEvents, ServerSideEvents>) => void; | ||
connection: (socket: Socket<ListenEvents, EmitEvents, ServerSideEvents>) => void; | ||
} | ||
export declare class Namespace<ListenEvents extends EventsMap = DefaultEventsMap, EmitEvents extends EventsMap = ListenEvents> extends StrictEventEmitter<{}, EmitEvents, NamespaceReservedEventsMap<ListenEvents, EmitEvents>> { | ||
export interface ServerReservedEventsMap<ListenEvents, EmitEvents, ServerSideEvents> extends NamespaceReservedEventsMap<ListenEvents, EmitEvents, ServerSideEvents> { | ||
new_namespace: (namespace: Namespace<ListenEvents, EmitEvents, ServerSideEvents>) => void; | ||
} | ||
export declare const RESERVED_EVENTS: ReadonlySet<string | Symbol>; | ||
export declare class Namespace<ListenEvents extends EventsMap = DefaultEventsMap, EmitEvents extends EventsMap = ListenEvents, ServerSideEvents extends EventsMap = {}> extends StrictEventEmitter<ServerSideEvents, EmitEvents, NamespaceReservedEventsMap<ListenEvents, EmitEvents, ServerSideEvents>> { | ||
readonly name: string; | ||
readonly sockets: Map<SocketId, Socket<ListenEvents, EmitEvents>>; | ||
readonly sockets: Map<SocketId, Socket<ListenEvents, EmitEvents, ServerSideEvents>>; | ||
adapter: Adapter; | ||
/** @private */ | ||
readonly server: Server<ListenEvents, EmitEvents>; | ||
readonly server: Server<ListenEvents, EmitEvents, ServerSideEvents>; | ||
/** @private */ | ||
_fns: Array<(socket: Socket<ListenEvents, EmitEvents>, next: (err?: ExtendedError) => void) => void>; | ||
_fns: Array<(socket: Socket<ListenEvents, EmitEvents, ServerSideEvents>, next: (err?: ExtendedError) => void) => void>; | ||
/** @private */ | ||
@@ -31,3 +35,3 @@ _ids: number; | ||
*/ | ||
constructor(server: Server<ListenEvents, EmitEvents>, name: string); | ||
constructor(server: Server<ListenEvents, EmitEvents, ServerSideEvents>, name: string); | ||
/** | ||
@@ -47,3 +51,3 @@ * Initializes the `Adapter` for this nsp. | ||
*/ | ||
use(fn: (socket: Socket<ListenEvents, EmitEvents>, next: (err?: ExtendedError) => void) => void): this; | ||
use(fn: (socket: Socket<ListenEvents, EmitEvents, ServerSideEvents>, next: (err?: ExtendedError) => void) => void): this; | ||
/** | ||
@@ -87,3 +91,3 @@ * Executes the middleware for an incoming client. | ||
*/ | ||
_add(client: Client<ListenEvents, EmitEvents>, query: any, fn?: () => void): Socket<ListenEvents, EmitEvents>; | ||
_add(client: Client<ListenEvents, EmitEvents, ServerSideEvents>, query: any, fn?: () => void): Socket<ListenEvents, EmitEvents, ServerSideEvents>; | ||
/** | ||
@@ -94,3 +98,3 @@ * Removes a client. Called by each `Socket`. | ||
*/ | ||
_remove(socket: Socket<ListenEvents, EmitEvents>): void; | ||
_remove(socket: Socket<ListenEvents, EmitEvents, ServerSideEvents>): void; | ||
/** | ||
@@ -118,2 +122,18 @@ * Emits to all clients. | ||
/** | ||
* Emit a packet to other Socket.IO servers | ||
* | ||
* @param ev - the event name | ||
* @param args - an array of arguments, which may include an acknowledgement callback at the end | ||
* @public | ||
*/ | ||
serverSideEmit<Ev extends EventNames<ServerSideEvents>>(ev: Ev, ...args: EventParams<ServerSideEvents, Ev>): boolean; | ||
/** | ||
* Called when a packet is received from another Socket.IO server | ||
* | ||
* @param args - an array of arguments, which may include an acknowledgement callback at the end | ||
* | ||
* @private | ||
*/ | ||
_onServerSideEmit(args: any[]): void; | ||
/** | ||
* Gets a list of clients. | ||
@@ -120,0 +140,0 @@ * |
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Namespace = void 0; | ||
exports.Namespace = exports.RESERVED_EVENTS = void 0; | ||
const socket_1 = require("./socket"); | ||
@@ -13,2 +13,3 @@ const typed_events_1 = require("./typed-events"); | ||
const debug = debug_1.default("socket.io:namespace"); | ||
exports.RESERVED_EVENTS = new Set(["connect", "connection", "new_namespace"]); | ||
class Namespace extends typed_events_1.StrictEventEmitter { | ||
@@ -193,2 +194,28 @@ /** | ||
/** | ||
* Emit a packet to other Socket.IO servers | ||
* | ||
* @param ev - the event name | ||
* @param args - an array of arguments, which may include an acknowledgement callback at the end | ||
* @public | ||
*/ | ||
serverSideEmit(ev, ...args) { | ||
if (exports.RESERVED_EVENTS.has(ev)) { | ||
throw new Error(`"${ev}" is a reserved event name`); | ||
} | ||
args.unshift(ev); | ||
this.adapter.serverSideEmit(args); | ||
return true; | ||
} | ||
/** | ||
* Called when a packet is received from another Socket.IO server | ||
* | ||
* @param args - an array of arguments, which may include an acknowledgement callback at the end | ||
* | ||
* @private | ||
*/ | ||
_onServerSideEmit(args) { | ||
const event = args.shift(); | ||
this.emitUntyped(event, args); | ||
} | ||
/** | ||
* Gets a list of clients. | ||
@@ -195,0 +222,0 @@ * |
import { Namespace } from "./namespace"; | ||
import type { Server } from "./index"; | ||
import type { EventParams, EventNames, EventsMap, DefaultEventsMap } from "./typed-events"; | ||
export declare class ParentNamespace<ListenEvents extends EventsMap = DefaultEventsMap, EmitEvents extends EventsMap = ListenEvents> extends Namespace<ListenEvents, EmitEvents> { | ||
export declare class ParentNamespace<ListenEvents extends EventsMap = DefaultEventsMap, EmitEvents extends EventsMap = ListenEvents, ServerSideEvents extends EventsMap = {}> extends Namespace<ListenEvents, EmitEvents, ServerSideEvents> { | ||
private static count; | ||
private children; | ||
constructor(server: Server<ListenEvents, EmitEvents>); | ||
constructor(server: Server<ListenEvents, EmitEvents, ServerSideEvents>); | ||
/** | ||
@@ -13,3 +13,3 @@ * @private | ||
emit<Ev extends EventNames<EmitEvents>>(ev: Ev, ...args: EventParams<EmitEvents, Ev>): boolean; | ||
createChild(name: string): Namespace<ListenEvents, EmitEvents>; | ||
createChild(name: string): Namespace<ListenEvents, EmitEvents, ServerSideEvents>; | ||
} |
@@ -63,5 +63,5 @@ /// <reference types="node" /> | ||
} | ||
export declare class Socket<ListenEvents extends EventsMap = DefaultEventsMap, EmitEvents extends EventsMap = ListenEvents> extends StrictEventEmitter<ListenEvents, EmitEvents, SocketReservedEventsMap> { | ||
readonly nsp: Namespace<ListenEvents, EmitEvents>; | ||
readonly client: Client<ListenEvents, EmitEvents>; | ||
export declare class Socket<ListenEvents extends EventsMap = DefaultEventsMap, EmitEvents extends EventsMap = ListenEvents, ServerSideEvents extends EventsMap = {}> extends StrictEventEmitter<ListenEvents, EmitEvents, SocketReservedEventsMap> { | ||
readonly nsp: Namespace<ListenEvents, EmitEvents, ServerSideEvents>; | ||
readonly client: Client<ListenEvents, EmitEvents, ServerSideEvents>; | ||
readonly id: SocketId; | ||
@@ -89,3 +89,3 @@ readonly handshake: Handshake; | ||
*/ | ||
constructor(nsp: Namespace<ListenEvents, EmitEvents>, client: Client<ListenEvents, EmitEvents>, auth: object); | ||
constructor(nsp: Namespace<ListenEvents, EmitEvents, ServerSideEvents>, client: Client<ListenEvents, EmitEvents, ServerSideEvents>, auth: object); | ||
/** | ||
@@ -92,0 +92,0 @@ * Builds the `handshake` BC object |
{ | ||
"name": "socket.io", | ||
"version": "4.0.2", | ||
"version": "4.1.0", | ||
"description": "node.js realtime framework server", | ||
@@ -54,4 +54,4 @@ "keywords": [ | ||
"debug": "~4.3.1", | ||
"engine.io": "~5.0.0", | ||
"socket.io-adapter": "~2.2.0", | ||
"engine.io": "~5.1.0", | ||
"socket.io-adapter": "~2.3.0", | ||
"socket.io-parser": "~4.0.3" | ||
@@ -69,3 +69,3 @@ }, | ||
"rimraf": "^3.0.2", | ||
"socket.io-client": "4.0.2", | ||
"socket.io-client": "4.1.0", | ||
"socket.io-client-v2": "npm:socket.io-client@^2.4.0", | ||
@@ -72,0 +72,0 @@ "superagent": "^6.1.0", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
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
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
1024138
8770
+ Addedengine.io@5.1.1(transitive)
+ Addedsocket.io-adapter@2.3.3(transitive)
- Removedengine.io@5.0.0(transitive)
- Removedsocket.io-adapter@2.2.0(transitive)
Updatedengine.io@~5.1.0
Updatedsocket.io-adapter@~2.3.0