Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

socket.io

Package Overview
Dependencies
Maintainers
2
Versions
159
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

socket.io - npm Package Compare versions

Comparing version 3.0.0-rc1 to 3.0.0-rc2

wrapper.mjs

25

CHANGELOG.md

@@ -0,1 +1,26 @@

# [3.0.0-rc2](https://github.com/socketio/socket.io/compare/3.0.0-rc1...3.0.0-rc2) (2020-10-15)
### Bug Fixes
* close clients with no namespace ([91cd255](https://github.com/socketio/socket.io/commit/91cd255ba76ff6a780c62740f9f5cd3a76f5d7c7))
### Code Refactoring
* remove duplicate _sockets map ([8a5db7f](https://github.com/socketio/socket.io/commit/8a5db7fa36a075da75cde43cd4fb6382b7659953))
### Features
* move binary detection back to the parser ([669592d](https://github.com/socketio/socket.io/commit/669592d120409a5cf00f128070dee6d22259ba4f))
### BREAKING CHANGES
* the "connected" map is renamed to "sockets"
* the Socket#binary() method is removed, as this use case is now covered by the ability to provide your own parser.
# [3.0.0-rc1](https://github.com/socketio/socket.io/compare/2.3.0...3.0.0-rc1) (2020-10-13)

@@ -2,0 +27,0 @@

35

dist/client.d.ts

@@ -7,4 +7,3 @@ /// <reference types="node" />

readonly conn: any;
/** @package */
readonly id: string;
private readonly id;
private readonly server;

@@ -15,2 +14,3 @@ private readonly encoder;

private nsps;
private connectTimeout;
/**

@@ -26,2 +26,4 @@ * Client constructor.

* @return the reference to the request that originated the Engine.IO connection
*
* @public
*/

@@ -31,2 +33,4 @@ get request(): IncomingMessage;

* Sets up event listeners.
*
* @private
*/

@@ -39,5 +43,5 @@ private setup;

* @param {Object} auth - the auth parameters
* @package
* @private
*/
connect(name: string, auth?: object): void;
private connect;
/**

@@ -48,2 +52,4 @@ * Connects a client to a namespace.

* @param {Object} auth - the auth parameters
*
* @private
*/

@@ -54,13 +60,15 @@ private doConnect;

*
* @package
* @private
*/
disconnect(): void;
_disconnect(): void;
/**
* Removes a socket. Called by each `Socket`.
*
* @package
* @private
*/
remove(socket: Socket): void;
_remove(socket: Socket): void;
/**
* Closes the underlying connection.
*
* @private
*/

@@ -73,7 +81,9 @@ private close;

* @param {Object} opts
* @package
* @private
*/
packet(packet: any, opts?: any): void;
_packet(packet: any, opts?: any): void;
/**
* Called with incoming transport data.
*
* @private
*/

@@ -83,2 +93,4 @@ private ondata;

* Called when parser fully decodes a packet.
*
* @private
*/

@@ -90,2 +102,3 @@ private ondecoded;

* @param {Object} err object
* @private
*/

@@ -97,2 +110,3 @@ private onerror;

* @param reason
* @private
*/

@@ -102,4 +116,5 @@ private onclose;

* Cleans up event listeners.
* @private
*/
private destroy;
}

@@ -21,3 +21,3 @@ "use strict";

this.encoder = server.encoder;
this.decoder = new server.parser.Decoder();
this.decoder = new server._parser.Decoder();
this.id = conn.id;

@@ -28,2 +28,4 @@ this.setup();

* @return the reference to the request that originated the Engine.IO connection
*
* @public
*/

@@ -35,2 +37,4 @@ get request() {

* Sets up event listeners.
*
* @private
*/

@@ -47,2 +51,11 @@ setup() {

this.conn.on("close", this.onclose);
this.connectTimeout = setTimeout(() => {
if (this.nsps.size === 0) {
debug("no namespace joined yet, close the client");
this.close();
}
else {
debug("the client has already joined a namespace, nothing to do");
}
}, this.server._connectTimeout);
}

@@ -54,10 +67,10 @@ /**

* @param {Object} auth - the auth parameters
* @package
* @private
*/
connect(name, auth = {}) {
if (this.server.nsps.has(name)) {
if (this.server._nsps.has(name)) {
debug("connecting to namespace %s", name);
return this.doConnect(name, auth);
}
this.server.checkNamespace(name, auth, dynamicNsp => {
this.server._checkNamespace(name, auth, (dynamicNsp) => {
if (dynamicNsp) {

@@ -69,3 +82,3 @@ debug("dynamic namespace %s was created", dynamicNsp.name);

debug("creation of namespace %s was denied", name);
this.packet({
this._packet({
type: socket_io_parser_1.PacketType.ERROR,

@@ -83,6 +96,12 @@ nsp: name,

* @param {Object} auth - the auth parameters
*
* @private
*/
doConnect(name, auth) {
if (this.connectTimeout) {
clearTimeout(this.connectTimeout);
this.connectTimeout = null;
}
const nsp = this.server.of(name);
const socket = nsp.add(this, auth, () => {
const socket = nsp._add(this, auth, () => {
this.sockets.set(socket.id, socket);

@@ -95,5 +114,5 @@ this.nsps.set(nsp.name, socket);

*
* @package
* @private
*/
disconnect() {
_disconnect() {
for (const socket of this.sockets.values()) {

@@ -108,5 +127,5 @@ socket.disconnect();

*
* @package
* @private
*/
remove(socket) {
_remove(socket) {
if (this.sockets.has(socket.id)) {

@@ -123,2 +142,4 @@ const nsp = this.sockets.get(socket.id).nsp.name;

* Closes the underlying connection.
*
* @private
*/

@@ -137,5 +158,5 @@ close() {

* @param {Object} opts
* @package
* @private
*/
packet(packet, opts) {
_packet(packet, opts) {
opts = opts || {};

@@ -168,2 +189,4 @@ const self = this;

* Called with incoming transport data.
*
* @private
*/

@@ -181,2 +204,4 @@ ondata(data) {

* Called when parser fully decodes a packet.
*
* @private
*/

@@ -191,3 +216,3 @@ ondecoded(packet) {

process.nextTick(function () {
socket.onpacket(packet);
socket._onpacket(packet);
});

@@ -204,6 +229,7 @@ }

* @param {Object} err object
* @private
*/
onerror(err) {
for (const socket of this.sockets.values()) {
socket.onerror(err);
socket._onerror(err);
}

@@ -216,2 +242,3 @@ this.conn.close();

* @param reason
* @private
*/

@@ -224,3 +251,3 @@ onclose(reason) {

for (const socket of this.sockets.values()) {
socket.onclose(reason);
socket._onclose(reason);
}

@@ -232,2 +259,3 @@ this.sockets.clear();

* Cleans up event listeners.
* @private
*/

@@ -234,0 +262,0 @@ destroy() {

@@ -13,15 +13,19 @@ /// <reference types="node" />

/**
* how many ms without a pong packet to consider the connection closed (5000)
* how many ms without a pong packet to consider the connection closed
* @default 5000
*/
pingTimeout: number;
/**
* how many ms before sending a new ping packet (25000)
* how many ms before sending a new ping packet
* @default 25000
*/
pingInterval: number;
/**
* how many ms before an uncompleted transport upgrade is cancelled (10000)
* how many ms before an uncompleted transport upgrade is cancelled
* @default 10000
*/
upgradeTimeout: number;
/**
* how many bytes or characters a message can be, before closing the session (to avoid DoS). Default value is 1E5.
* how many bytes or characters a message can be, before closing the session (to avoid DoS).
* @default 1e5 (100 KB)
*/

@@ -37,15 +41,19 @@ maxHttpBufferSize: number;

/**
* to allow connections to (['polling', 'websocket'])
* the low-level transports that are enabled
* @default ["polling", "websocket"]
*/
transports: Transport[];
/**
* whether to allow transport upgrades (true)
* whether to allow transport upgrades
* @default true
*/
allowUpgrades: boolean;
/**
* parameters of the WebSocket permessage-deflate extension (see ws module api docs). Set to false to disable. (false)
* parameters of the WebSocket permessage-deflate extension (see ws module api docs). Set to false to disable.
* @default false
*/
perMessageDeflate: boolean | object;
/**
* parameters of the http compression for the polling transports (see zlib api docs). Set to false to disable. (true)
* parameters of the http compression for the polling transports (see zlib api docs). Set to false to disable.
* @default true
*/

@@ -65,3 +73,4 @@ httpCompression: boolean | object;

* configuration of the cookie that contains the client sid to send as part of handshake response headers. This cookie
* might be used for sticky-session. Defaults to not sending any cookie (false)
* might be used for sticky-session. Defaults to not sending any cookie.
* @default false
*/

@@ -76,11 +85,14 @@ cookie: CookieSerializeOptions | boolean;

/**
* name of the path to capture (/engine.io).
* name of the path to capture
* @default "/engine.io"
*/
path: string;
/**
* destroy unhandled upgrade requests (true)
* destroy unhandled upgrade requests
* @default true
*/
destroyUpgrade: boolean;
/**
* milliseconds after which unhandled requests are ended (1000)
* milliseconds after which unhandled requests are ended
* @default 1000
*/

@@ -93,25 +105,37 @@ destroyUpgradeTimeout: number;

/**
* name of the path to capture (/socket.io)
* name of the path to capture
* @default "/socket.io"
*/
path: string;
/**
* whether to serve the client files (true)
* whether to serve the client files
* @default true
*/
serveClient: boolean;
/**
* the adapter to use. Defaults to an instance of the Adapter that ships with socket.io which is memory based.
* the adapter to use
* @default the in-memory adapter (https://github.com/socketio/socket.io-adapter)
*/
adapter: any;
/**
* the parser to use. Defaults to an instance of the Parser that ships with socket.io.
* the parser to use
* @default the default parser (https://github.com/socketio/socket.io-parser)
*/
parser: any;
/**
* how many ms before a client without namespace is closed
* @default 45000
*/
connectTimeout: number;
}
export declare class Server extends EventEmitter {
readonly sockets: Namespace;
/** @package */
readonly parser: any;
/** @package */
/** @private */
readonly _parser: any;
/** @private */
readonly encoder: Encoder;
nsps: Map<string, Namespace>;
/**
* @private
*/
_nsps: Map<string, Namespace>;
private parentNsps;

@@ -123,2 +147,6 @@ private _adapter;

private _path;
/**
* @private
*/
_connectTimeout: number;
private httpServer;

@@ -130,2 +158,3 @@ /**

* @param {Object} [opts]
* @public
*/

@@ -140,4 +169,6 @@ constructor(opts?: Partial<ServerOptions>);

* @return {Server|Boolean} self when setting or value when getting
* @public
*/
serveClient(v?: boolean): boolean | this;
serveClient(v: boolean): Server;
serveClient(): boolean;
/**

@@ -150,5 +181,5 @@ * Executes the middleware for an incoming namespace not already created on the server.

*
* @package
* @private
*/
checkNamespace(name: string, auth: object, fn: (nsp: Namespace | boolean) => void): void;
_checkNamespace(name: string, auth: object, fn: (nsp: Namespace | boolean) => void): void;
/**

@@ -159,5 +190,14 @@ * Sets the client serving path.

* @return {Server|String} self when setting or value when getting
* @public
*/
path(v?: string): string | this;
path(v: string): Server;
path(): string;
/**
* Set the delay after which a client without namespace is closed
* @param v
* @public
*/
connectTimeout(v: number): Server;
connectTimeout(): number;
/**
* Sets the adapter for rooms.

@@ -167,3 +207,5 @@ *

* @return {Server|Adapter} self when setting or value when getting
* @public
*/
adapter(): any;
adapter(v: any): any;

@@ -176,2 +218,3 @@ /**

* @return {Server} self
* @public
*/

@@ -186,2 +229,3 @@ listen(srv: http.Server, opts?: Partial<ServerOptions>): Server;

* @return {Server} self
* @public
*/

@@ -195,2 +239,3 @@ attach(srv: http.Server, opts?: Partial<ServerOptions>): Server;

* @param opts - options passed to engine.io
* @private
*/

@@ -202,2 +247,3 @@ private initEngine;

* @param {Function|http.Server} srv http server
* @private
*/

@@ -210,2 +256,3 @@ private attachServe;

* @param {http.ServerResponse} res
* @private
*/

@@ -218,2 +265,3 @@ private serve;

* @param {http.ServerResponse} res
* @private
*/

@@ -226,2 +274,3 @@ private serveMap;

* @return {Server} self
* @public
*/

@@ -234,2 +283,3 @@ bind(engine: any): Server;

* @return {Server} self
* @private
*/

@@ -242,2 +292,3 @@ private onconnection;

* @param {Function} [fn] optional, nsp `connection` ev handler
* @public
*/

@@ -249,2 +300,3 @@ of(name: string | RegExp | ((name: string, query: object, fn: (err: Error, success: boolean) => void) => void), fn?: (socket: Socket) => void): Namespace;

* @param {Function} [fn] optional, called as `fn([err])` on error OR all conns closed
* @public
*/

@@ -278,3 +330,4 @@ close(fn?: (err?: Error) => void): void;

*
* @return {Namespace} self
* @return {Server} self
* @public
*/

@@ -285,3 +338,4 @@ send(...args: any[]): Server;

*
* @return {Namespace} self
* @return {Server} self
* @public
*/

@@ -291,2 +345,4 @@ write(...args: any[]): Server;

* Gets a list of socket ids.
*
* @public
*/

@@ -299,12 +355,6 @@ allSockets(): Promise<Set<SocketId>>;

* @return {Server} self
* @public
*/
compress(compress: boolean): Server;
/**
* Sets the binary flag
*
* @param {Boolean} binary - encode as if it has binary data if `true`, Encode as if it doesnt have binary data if `false`
* @return {Server} self
*/
binary(binary: boolean): Server;
/**
* Sets a modifier for a subsequent event emission that the event data may be lost if the client is not ready to

@@ -315,2 +365,3 @@ * receive messages (because of network slowness or other issues, or because they’re connected through long polling

* @return {Server} self
* @public
*/

@@ -322,2 +373,3 @@ get volatile(): Server;

* @return {Server} self
* @public
*/

@@ -324,0 +376,0 @@ get local(): Server;

@@ -47,3 +47,6 @@ "use strict";

super();
this.nsps = new Map();
/**
* @private
*/
this._nsps = new Map();
this.parentNsps = new Map();

@@ -55,5 +58,6 @@ if ("object" == typeof srv && srv instanceof Object && !srv.listen) {

this.path(opts.path || "/socket.io");
this.connectTimeout(opts.connectTimeout || 45000);
this.serveClient(false !== opts.serveClient);
this.parser = opts.parser || parser;
this.encoder = new this.parser.Encoder();
this._parser = opts.parser || parser;
this.encoder = new this._parser.Encoder();
this.adapter(opts.adapter || socket_io_adapter_1.Adapter);

@@ -64,8 +68,2 @@ this.sockets = this.of("/");

}
/**
* Sets/gets whether client code is being served.
*
* @param {Boolean} v - whether to serve client code
* @return {Server|Boolean} self when setting or value when getting
*/
serveClient(v) {

@@ -100,5 +98,5 @@ if (!arguments.length)

*
* @package
* @private
*/
checkNamespace(name, auth, fn) {
_checkNamespace(name, auth, fn) {
if (this.parentNsps.size === 0)

@@ -123,8 +121,2 @@ return fn(false);

}
/**
* Sets the client serving path.
*
* @param {String} v pathname
* @return {Server|String} self when setting or value when getting
*/
path(v) {

@@ -136,8 +128,8 @@ if (!arguments.length)

}
/**
* Sets the adapter for rooms.
*
* @param {Adapter} v pathname
* @return {Server|Adapter} self when setting or value when getting
*/
connectTimeout(v) {
if (v === undefined)
return this._connectTimeout;
this._connectTimeout = v;
return this;
}
adapter(v) {

@@ -147,4 +139,4 @@ if (!arguments.length)

this._adapter = v;
for (const nsp of this.nsps.values()) {
nsp.initAdapter();
for (const nsp of this._nsps.values()) {
nsp._initAdapter();
}

@@ -185,2 +177,3 @@ return this;

* @param opts - options passed to engine.io
* @private
*/

@@ -203,2 +196,3 @@ initEngine(srv, opts) {

* @param {Function|http.Server} srv http server
* @private
*/

@@ -231,2 +225,3 @@ attachServe(srv) {

* @param {http.ServerResponse} res
* @private
*/

@@ -258,2 +253,3 @@ serve(req, res) {

* @param {http.ServerResponse} res
* @private
*/

@@ -284,2 +280,3 @@ serveMap(req, res) {

* @return {Server} self
* @public
*/

@@ -296,2 +293,3 @@ bind(engine) {

* @return {Server} self
* @private
*/

@@ -308,2 +306,3 @@ onconnection(conn) {

* @param {Function} [fn] optional, nsp `connection` ev handler
* @public
*/

@@ -328,7 +327,7 @@ of(name, fn) {

name = "/" + name;
let nsp = this.nsps.get(name);
let nsp = this._nsps.get(name);
if (!nsp) {
debug("initializing namespace %s", name);
nsp = new namespace_1.Namespace(this, name);
this.nsps.set(name, nsp);
this._nsps.set(name, nsp);
}

@@ -343,6 +342,7 @@ if (fn)

* @param {Function} [fn] optional, called as `fn([err])` on error OR all conns closed
* @public
*/
close(fn) {
for (const socket of this.sockets.sockets.values()) {
socket.onclose("server shutting down");
socket._onclose("server shutting down");
}

@@ -392,3 +392,4 @@ this.engine.close();

*
* @return {Namespace} self
* @return {Server} self
* @public
*/

@@ -403,3 +404,4 @@ send(...args) {

*
* @return {Namespace} self
* @return {Server} self
* @public
*/

@@ -413,2 +415,4 @@ write(...args) {

* Gets a list of socket ids.
*
* @public
*/

@@ -423,2 +427,3 @@ allSockets() {

* @return {Server} self
* @public
*/

@@ -430,12 +435,2 @@ compress(compress) {

/**
* Sets the binary flag
*
* @param {Boolean} binary - encode as if it has binary data if `true`, Encode as if it doesnt have binary data if `false`
* @return {Server} self
*/
binary(binary) {
this.sockets.binary(binary);
return this;
}
/**
* Sets a modifier for a subsequent event emission that the event data may be lost if the client is not ready to

@@ -446,2 +441,3 @@ * receive messages (because of network slowness or other issues, or because they’re connected through long polling

* @return {Server} self
* @public
*/

@@ -456,2 +452,3 @@ get volatile() {

* @return {Server} self
* @public
*/

@@ -458,0 +455,0 @@ get local() {

/// <reference types="node" />
import { Socket } from "./socket";
import { Server } from "./index";
import { Client } from "./client";
import { EventEmitter } from "events";

@@ -8,16 +9,14 @@ import { Adapter, Room, SocketId } from "socket.io-adapter";

readonly name: string;
readonly connected: Map<SocketId, Socket>;
readonly sockets: Map<SocketId, Socket>;
adapter: Adapter;
/** @package */
readonly server: any;
/** @package */
fns: Array<(socket: Socket, next: (err: Error) => void) => void>;
/** @package */
rooms: Set<Room>;
/** @package */
flags: any;
/** @package */
ids: number;
/** @package */
sockets: Map<SocketId, Socket>;
/** @private */
readonly server: Server;
/** @private */
_fns: Array<(socket: Socket, next: (err: Error) => void) => void>;
/** @private */
_rooms: Set<Room>;
/** @private */
_flags: any;
/** @private */
_ids: number;
/**

@@ -35,5 +34,5 @@ * Namespace constructor.

*
* @package
* @private
*/
initAdapter(): void;
_initAdapter(): void;
/**

@@ -43,2 +42,3 @@ * Sets up namespace middleware.

* @return {Namespace} self
* @public
*/

@@ -51,2 +51,3 @@ use(fn: (socket: Socket, next: (err?: Error) => void) => void): Namespace;

* @param {Function} fn - last fn call in the middleware
* @private
*/

@@ -59,2 +60,3 @@ private run;

* @return {Namespace} self
* @public
*/

@@ -67,2 +69,3 @@ to(name: Room): Namespace;

* @return {Namespace} self
* @public
*/

@@ -74,10 +77,11 @@ in(name: Room): Namespace;

* @return {Socket}
* @private
*/
private add;
_add(client: Client, query: any, fn?: () => void): Socket;
/**
* Removes a client. Called by each `Socket`.
*
* @package
* @private
*/
remove(socket: Socket): void;
_remove(socket: Socket): void;
/**

@@ -87,2 +91,3 @@ * Emits to all clients.

* @return {Namespace} self
* @public
*/

@@ -94,2 +99,3 @@ emit(ev: string, ...args: any[]): Namespace;

* @return {Namespace} self
* @public
*/

@@ -101,2 +107,3 @@ send(...args: any[]): Namespace;

* @return {Namespace} self
* @public
*/

@@ -108,2 +115,3 @@ write(...args: any[]): Namespace;

* @return {Namespace} self
* @public
*/

@@ -116,12 +124,6 @@ allSockets(): Promise<Set<SocketId>>;

* @return {Namespace} self
* @public
*/
compress(compress: boolean): Namespace;
/**
* Sets the binary flag
*
* @param {Boolean} binary - encode as if it has binary data if `true`, Encode as if it doesnt have binary data if `false`
* @return {Namespace} self
*/
binary(binary: boolean): Namespace;
/**
* Sets a modifier for a subsequent event emission that the event data may be lost if the client is not ready to

@@ -132,2 +134,3 @@ * receive messages (because of network slowness or other issues, or because they’re connected through long polling

* @return {Namespace} self
* @public
*/

@@ -139,4 +142,5 @@ get volatile(): Namespace;

* @return {Namespace} self
* @public
*/
get local(): Namespace;
}

@@ -10,3 +10,2 @@ "use strict";

const socket_io_parser_1 = require("socket.io-parser");
const has_binary2_1 = __importDefault(require("has-binary2"));
const debug_1 = __importDefault(require("debug"));

@@ -23,16 +22,14 @@ const debug = debug_1.default("socket.io:namespace");

super();
this.connected = new Map();
/** @package */
this.fns = [];
/** @package */
this.rooms = new Set();
/** @package */
this.flags = {};
/** @package */
this.ids = 0;
/** @package */
this.sockets = new Map();
/** @private */
this._fns = [];
/** @private */
this._rooms = new Set();
/** @private */
this._flags = {};
/** @private */
this._ids = 0;
this.server = server;
this.name = name;
this.initAdapter();
this._initAdapter();
}

@@ -44,5 +41,5 @@ /**

*
* @package
* @private
*/
initAdapter() {
_initAdapter() {
this.adapter = new (this.server.adapter())(this);

@@ -54,5 +51,6 @@ }

* @return {Namespace} self
* @public
*/
use(fn) {
this.fns.push(fn);
this._fns.push(fn);
return this;

@@ -65,5 +63,6 @@ }

* @param {Function} fn - last fn call in the middleware
* @private
*/
run(socket, fn) {
const fns = this.fns.slice(0);
const fns = this._fns.slice(0);
if (!fns.length)

@@ -90,5 +89,6 @@ return fn(null);

* @return {Namespace} self
* @public
*/
to(name) {
this.rooms.add(name);
this._rooms.add(name);
return this;

@@ -101,5 +101,6 @@ }

* @return {Namespace} self
* @public
*/
in(name) {
this.rooms.add(name);
this._rooms.add(name);
return this;

@@ -111,4 +112,5 @@ }

* @return {Socket}
* @private
*/
add(client, query, fn) {
_add(client, query, fn) {
debug("adding socket to nsp %s", this.name);

@@ -120,3 +122,3 @@ const socket = new socket_1.Socket(this, client, query);

if (err)
return socket.error(err.message);
return socket._error(err.message);
// track socket

@@ -128,3 +130,3 @@ this.sockets.set(socket.id, socket);

// logic is complete)
socket.onconnect();
socket._onconnect();
if (fn)

@@ -146,5 +148,5 @@ fn();

*
* @package
* @private
*/
remove(socket) {
_remove(socket) {
if (this.sockets.has(socket.id)) {

@@ -161,2 +163,3 @@ this.sockets.delete(socket.id);

* @return {Namespace} self
* @public
*/

@@ -171,7 +174,3 @@ // @ts-ignore

const packet = {
type: (this.flags.binary !== undefined
? this.flags.binary
: has_binary2_1.default(args))
? socket_io_parser_1.PacketType.BINARY_EVENT
: socket_io_parser_1.PacketType.EVENT,
type: socket_io_parser_1.PacketType.EVENT,
data: args

@@ -182,7 +181,7 @@ };

}
const rooms = new Set(this.rooms);
const flags = Object.assign({}, this.flags);
const rooms = new Set(this._rooms);
const flags = Object.assign({}, this._flags);
// reset flags
this.rooms.clear();
this.flags = {};
this._rooms.clear();
this._flags = {};
this.adapter.broadcast(packet, {

@@ -198,2 +197,3 @@ rooms: rooms,

* @return {Namespace} self
* @public
*/

@@ -209,2 +209,3 @@ send(...args) {

* @return {Namespace} self
* @public
*/

@@ -220,2 +221,3 @@ write(...args) {

* @return {Namespace} self
* @public
*/

@@ -226,4 +228,4 @@ allSockets() {

}
const rooms = new Set(this.rooms);
this.rooms.clear();
const rooms = new Set(this._rooms);
this._rooms.clear();
return this.adapter.sockets(rooms);

@@ -236,18 +238,9 @@ }

* @return {Namespace} self
* @public
*/
compress(compress) {
this.flags.compress = compress;
this._flags.compress = compress;
return this;
}
/**
* Sets the binary flag
*
* @param {Boolean} binary - encode as if it has binary data if `true`, Encode as if it doesnt have binary data if `false`
* @return {Namespace} self
*/
binary(binary) {
this.flags.binary = binary;
return this;
}
/**
* Sets a modifier for a subsequent event emission that the event data may be lost if the client is not ready to

@@ -258,5 +251,6 @@ * receive messages (because of network slowness or other issues, or because they’re connected through long polling

* @return {Namespace} self
* @public
*/
get volatile() {
this.flags.volatile = true;
this._flags.volatile = true;
return this;

@@ -268,5 +262,6 @@ }

* @return {Namespace} self
* @public
*/
get local() {
this.flags.local = true;
this._flags.local = true;
return this;

@@ -273,0 +268,0 @@ }

@@ -6,5 +6,5 @@ import { Namespace } from "./namespace";

constructor(server: any);
initAdapter(): void;
_initAdapter(): void;
emit(...args: any[]): Namespace;
createChild(name: any): Namespace;
}

@@ -10,11 +10,11 @@ "use strict";

}
initAdapter() { }
_initAdapter() { }
emit(...args) {
this.children.forEach(nsp => {
nsp.rooms = this.rooms;
nsp.flags = this.flags;
nsp._rooms = this._rooms;
nsp._flags = this._flags;
nsp.emit.apply(nsp, args);
});
this.rooms.clear();
this.flags = {};
this._rooms.clear();
this._flags = {};
return this;

@@ -24,3 +24,3 @@ }

const namespace = new namespace_1.Namespace(this.server, name);
namespace.fns = this.fns.slice(0);
namespace._fns = this._fns.slice(0);
this.listeners("connect").forEach(listener =>

@@ -33,3 +33,3 @@ // @ts-ignore

this.children.add(namespace);
this.server.nsps.set(name, namespace);
this.server._nsps.set(name, namespace);
return namespace;

@@ -36,0 +36,0 @@ }

@@ -73,2 +73,4 @@ /// <reference types="node" />

* Builds the `handshake` BC object
*
* @private
*/

@@ -80,2 +82,3 @@ private buildHandshake;

* @return {Socket} self
* @public
*/

@@ -88,2 +91,3 @@ emit(ev: string, ...args: any[]): this;

* @return {Socket} self
* @public
*/

@@ -96,2 +100,3 @@ to(name: Room): this;

* @return {Socket} self
* @public
*/

@@ -103,2 +108,3 @@ in(name: Room): Socket;

* @return {Socket} self
* @public
*/

@@ -110,2 +116,3 @@ send(...args: any[]): Socket;

* @return {Socket} self
* @public
*/

@@ -118,2 +125,3 @@ write(...args: any[]): Socket;

* @param {Object} opts - options
* @private
*/

@@ -127,2 +135,3 @@ private packet;

* @return {Socket} self
* @public
*/

@@ -136,2 +145,3 @@ join(rooms: Room | Array<Room>, fn?: (err: Error) => void): Socket;

* @return {Socket} self
* @public
*/

@@ -141,2 +151,4 @@ leave(room: string, fn?: (err: Error) => void): Socket;

* Leave all rooms.
*
* @private
*/

@@ -150,5 +162,5 @@ private leaveAll;

*
* @package
* @private
*/
onconnect(): void;
_onconnect(): void;
/**

@@ -158,5 +170,5 @@ * Called with each packet. Called by `Client`.

* @param {Object} packet
* @package
* @private
*/
onpacket(packet: any): void;
_onpacket(packet: any): void;
/**

@@ -166,2 +178,3 @@ * Called upon event packet.

* @param {Object} packet - packet object
* @private
*/

@@ -173,2 +186,3 @@ private onevent;

* @param {Number} id - packet id
* @private
*/

@@ -178,2 +192,4 @@ private ack;

* Called upon ack packet.
*
* @private
*/

@@ -183,2 +199,4 @@ private onack;

* Called upon client disconnect packet.
*
* @private
*/

@@ -189,5 +207,5 @@ private ondisconnect;

*
* @package
* @private
*/
onerror(err: any): void;
_onerror(err: any): void;
/**

@@ -199,5 +217,5 @@ * Called upon closing. Called by `Client`.

*
* @package
* @private
*/
onclose(reason: string): this;
_onclose(reason: string): this;
/**

@@ -208,5 +226,5 @@ * Produces an `error` packet.

*
* @package
* @private
*/
error(err: any): void;
_error(err: any): void;
/**

@@ -217,2 +235,4 @@ * Disconnects this client.

* @return {Socket} self
*
* @public
*/

@@ -225,12 +245,6 @@ disconnect(close?: boolean): Socket;

* @return {Socket} self
* @public
*/
compress(compress: boolean): Socket;
/**
* Sets the binary flag
*
* @param {Boolean} binary - encode as if it has binary data if `true`, Encode as if it doesnt have binary data if `false`
* @return {Socket} self
*/
binary(binary: boolean): Socket;
/**
* Sets a modifier for a subsequent event emission that the event data may be lost if the client is not ready to

@@ -241,2 +255,3 @@ * receive messages (because of network slowness or other issues, or because they’re connected through long polling

* @return {Socket} self
* @public
*/

@@ -249,2 +264,3 @@ get volatile(): Socket;

* @return {Socket} self
* @public
*/

@@ -256,2 +272,3 @@ get broadcast(): Socket;

* @return {Socket} self
* @public
*/

@@ -263,2 +280,3 @@ get local(): Socket;

* @param {Array} event - event that will get emitted
* @private
*/

@@ -271,2 +289,3 @@ private dispatch;

* @return {Socket} self
* @public
*/

@@ -279,7 +298,21 @@ use(fn: (event: Array<any>, next: (err: Error) => void) => void): Socket;

* @param {Function} fn - last fn call in the middleware
* @private
*/
private run;
/**
* A reference to the request that originated the underlying Engine.IO Socket.
*
* @public
*/
get request(): IncomingMessage;
/**
* A reference to the underlying Client transport connection (Engine.IO Socket object).
*
* @public
*/
get conn(): any;
/**
* @public
*/
get rooms(): Set<Room>;
}

@@ -9,3 +9,2 @@ "use strict";

const socket_io_parser_1 = require("socket.io-parser");
const has_binary2_1 = __importDefault(require("has-binary2"));
const url_1 = __importDefault(require("url"));

@@ -50,2 +49,4 @@ const debug_1 = __importDefault(require("debug"));

* Builds the `handshake` BC object
*
* @private
*/

@@ -70,2 +71,3 @@ buildHandshake(auth) {

* @return {Socket} self
* @public
*/

@@ -79,7 +81,3 @@ // @ts-ignore

const packet = {
type: (this.flags.binary !== undefined
? this.flags.binary
: has_binary2_1.default(args))
? socket_io_parser_1.PacketType.BINARY_EVENT
: socket_io_parser_1.PacketType.EVENT,
type: socket_io_parser_1.PacketType.EVENT,
data: args

@@ -92,5 +90,5 @@ };

}
debug("emitting packet with ack id %d", this.nsp.ids);
this.acks.set(this.nsp.ids, args.pop());
packet.id = this.nsp.ids++;
debug("emitting packet with ack id %d", this.nsp._ids);
this.acks.set(this.nsp._ids, args.pop());
packet.id = this.nsp._ids++;
}

@@ -120,2 +118,3 @@ const rooms = new Set(this._rooms);

* @return {Socket} self
* @public
*/

@@ -131,2 +130,3 @@ to(name) {

* @return {Socket} self
* @public
*/

@@ -141,2 +141,3 @@ in(name) {

* @return {Socket} self
* @public
*/

@@ -152,2 +153,3 @@ send(...args) {

* @return {Socket} self
* @public
*/

@@ -164,2 +166,3 @@ write(...args) {

* @param {Object} opts - options
* @private
*/

@@ -169,3 +172,3 @@ packet(packet, opts = {}) {

opts.compress = false !== opts.compress;
this.client.packet(packet, opts);
this.client._packet(packet, opts);
}

@@ -178,2 +181,3 @@ /**

* @return {Socket} self
* @public
*/

@@ -193,2 +197,3 @@ join(rooms, fn) {

* @return {Socket} self
* @public
*/

@@ -204,2 +209,4 @@ leave(room, fn) {

* Leave all rooms.
*
* @private
*/

@@ -215,7 +222,6 @@ leaveAll() {

*
* @package
* @private
*/
onconnect() {
_onconnect() {
debug("socket connected - writing packet");
this.nsp.connected.set(this.id, this);
this.join(this.id);

@@ -228,5 +234,5 @@ this.packet({ type: socket_io_parser_1.PacketType.CONNECT, data: { sid: this.id } });

* @param {Object} packet
* @package
* @private
*/
onpacket(packet) {
_onpacket(packet) {
debug("got packet %j", packet);

@@ -250,3 +256,3 @@ switch (packet.type) {

case socket_io_parser_1.PacketType.ERROR:
this.onerror(new Error(packet.data));
this._onerror(new Error(packet.data));
}

@@ -258,2 +264,3 @@ }

* @param {Object} packet - packet object
* @private
*/

@@ -273,2 +280,3 @@ onevent(packet) {

* @param {Number} id - packet id
* @private
*/

@@ -286,3 +294,3 @@ ack(id) {

id: id,
type: has_binary2_1.default(args) ? socket_io_parser_1.PacketType.BINARY_ACK : socket_io_parser_1.PacketType.ACK,
type: socket_io_parser_1.PacketType.ACK,
data: args

@@ -295,2 +303,4 @@ });

* Called upon ack packet.
*
* @private
*/

@@ -310,6 +320,8 @@ onack(packet) {

* Called upon client disconnect packet.
*
* @private
*/
ondisconnect() {
debug("got disconnect packet");
this.onclose("client namespace disconnect");
this._onclose("client namespace disconnect");
}

@@ -319,5 +331,5 @@ /**

*
* @package
* @private
*/
onerror(err) {
_onerror(err) {
if (this.listeners("error").length) {

@@ -337,5 +349,5 @@ super.emit("error", err);

*
* @package
* @private
*/
onclose(reason) {
_onclose(reason) {
if (!this.connected)

@@ -346,7 +358,6 @@ return this;

this.leaveAll();
this.nsp.remove(this);
this.client.remove(this);
this.nsp._remove(this);
this.client._remove(this);
this.connected = false;
this.disconnected = true;
this.nsp.connected.delete(this.id);
super.emit("disconnect", reason);

@@ -359,5 +370,5 @@ }

*
* @package
* @private
*/
error(err) {
_error(err) {
this.packet({ type: socket_io_parser_1.PacketType.ERROR, data: err });

@@ -370,2 +381,4 @@ }

* @return {Socket} self
*
* @public
*/

@@ -376,7 +389,7 @@ disconnect(close = false) {

if (close) {
this.client.disconnect();
this.client._disconnect();
}
else {
this.packet({ type: socket_io_parser_1.PacketType.DISCONNECT });
this.onclose("server namespace disconnect");
this._onclose("server namespace disconnect");
}

@@ -390,2 +403,3 @@ return this;

* @return {Socket} self
* @public
*/

@@ -397,12 +411,2 @@ compress(compress) {

/**
* Sets the binary flag
*
* @param {Boolean} binary - encode as if it has binary data if `true`, Encode as if it doesnt have binary data if `false`
* @return {Socket} self
*/
binary(binary) {
this.flags.binary = binary;
return this;
}
/**
* Sets a modifier for a subsequent event emission that the event data may be lost if the client is not ready to

@@ -413,2 +417,3 @@ * receive messages (because of network slowness or other issues, or because they’re connected through long polling

* @return {Socket} self
* @public
*/

@@ -424,2 +429,3 @@ get volatile() {

* @return {Socket} self
* @public
*/

@@ -434,2 +440,3 @@ get broadcast() {

* @return {Socket} self
* @public
*/

@@ -444,2 +451,3 @@ get local() {

* @param {Array} event - event that will get emitted
* @private
*/

@@ -451,3 +459,3 @@ dispatch(event) {

if (err) {
return this.error(err.message);
return this._error(err.message);
}

@@ -463,2 +471,3 @@ super.emit.apply(this, event);

* @return {Socket} self
* @public
*/

@@ -474,2 +483,3 @@ use(fn) {

* @param {Function} fn - last fn call in the middleware
* @private
*/

@@ -494,8 +504,21 @@ run(event, fn) {

}
/**
* A reference to the request that originated the underlying Engine.IO Socket.
*
* @public
*/
get request() {
return this.client.request;
}
/**
* A reference to the underlying Client transport connection (Engine.IO Socket object).
*
* @public
*/
get conn() {
return this.client.conn;
}
/**
* @public
*/
get rooms() {

@@ -502,0 +525,0 @@ return this.adapter.socketRooms(this.id) || new Set();

{
"name": "socket.io",
"version": "3.0.0-rc1",
"version": "3.0.0-rc2",
"description": "node.js realtime framework server",

@@ -15,3 +15,4 @@ "keywords": [

"files": [
"dist/"
"dist/",
"wrapper.mjs"
],

@@ -40,6 +41,5 @@ "type": "commonjs",

"engine.io": "~4.0.0",
"has-binary2": "~1.0.2",
"socket.io-adapter": "~2.0.1",
"socket.io-client": "3.0.0-rc1",
"socket.io-parser": "4.0.1-rc1"
"socket.io-adapter": "2.0.3-rc1",
"socket.io-client": "3.0.0-rc2",
"socket.io-parser": "4.0.1-rc2"
},

@@ -46,0 +46,0 @@ "devDependencies": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc