Socket
Socket
Sign inDemoInstall

engine.io

Package Overview
Dependencies
Maintainers
0
Versions
151
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

engine.io - npm Package Compare versions

Comparing version 6.5.5 to 6.6.0

2

build/engine.io.d.ts

@@ -17,3 +17,2 @@ import { Server, AttachOptions, ServerOptions } from "./server";

* @return {Server} websocket.io server
* @api public
*/

@@ -27,4 +26,3 @@ declare function listen(port: any, options: AttachOptions & ServerOptions, fn: any): Server;

* @return {Server} engine server
* @api public
*/
declare function attach(server: any, options: AttachOptions & ServerOptions): Server;

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

* @return {Server} websocket.io server
* @api public
*/

@@ -50,3 +49,2 @@ function listen(port, options, fn) {

* @return {Server} engine server
* @api public
*/

@@ -53,0 +51,0 @@ function attach(server, options) {

52

build/server.d.ts
/// <reference types="node" />
import { EventEmitter } from "events";
import { Socket } from "./socket";
import type { IncomingMessage, Server as HttpServer, ServerResponse } from "http";

@@ -7,3 +8,4 @@ import type { CookieSerializeOptions } from "cookie";

import type { Duplex } from "stream";
declare type Transport = "polling" | "websocket";
import type { EngineRequest } from "./transport";
declare type Transport = "polling" | "websocket" | "webtransport";
export interface AttachOptions {

@@ -126,3 +128,3 @@ /**

opts: ServerOptions;
protected clients: any;
protected clients: Record<string, Socket>;
clientsCount: number;

@@ -134,3 +136,2 @@ protected middlewares: Middleware[];

* @param {Object} opts - options
* @api public
*/

@@ -149,13 +150,13 @@ constructor(opts?: ServerOptions);

* @return {Array}
* @api public
*/
upgrades(transport: any): any;
upgrades(transport: string): any;
/**
* Verifies a request.
*
* @param {http.IncomingMessage}
* @return {Boolean} whether the request is valid
* @api private
* @param {EngineRequest} req
* @param upgrade - whether it's an upgrade request
* @param fn
* @protected
*/
protected verify(req: any, upgrade: any, fn: any): any;
protected verify(req: any, upgrade: boolean, fn: (errorCode?: number, errorContext?: any) => void): void;
/**

@@ -183,4 +184,2 @@ * Adds a new middleware.

* Closes all clients.
*
* @api public
*/

@@ -193,16 +192,15 @@ close(): this;

*
* @param {Object} request object
* @api public
* @param {IncomingMessage} req - the request object
*/
generateId(req: any): any;
generateId(req: IncomingMessage): any;
/**
* Handshakes a new client.
*
* @param {String} transport name
* @param {Object} request object
* @param {String} transportName
* @param {Object} req - the request object
* @param {Function} closeConnection
*
* @api protected
* @protected
*/
protected handshake(transportName: any, req: any, closeConnection: any): Promise<any>;
protected handshake(transportName: string, req: any, closeConnection: (errorCode?: number, errorContext?: any) => void): Promise<any>;
onWebTransportSession(session: any): Promise<any>;

@@ -236,3 +234,3 @@ protected abstract createTransport(transportName: any, req: any): any;

*
* @api protected
* @protected
*/

@@ -244,20 +242,17 @@ protected init(): void;

*
* @api private
* @private
*/
private prepare;
protected createTransport(transportName: any, req: any): any;
protected createTransport(transportName: string, req: IncomingMessage): any;
/**
* Handles an Engine.IO HTTP request.
*
* @param {IncomingMessage} req
* @param {EngineRequest} req
* @param {ServerResponse} res
* @api public
*/
handleRequest(req: IncomingMessage, res: ServerResponse): void;
handleRequest(req: EngineRequest, res: ServerResponse): void;
/**
* Handles an Engine.IO HTTP Upgrade.
*
* @api public
*/
handleUpgrade(req: IncomingMessage, socket: Duplex, upgradeHead: Buffer): void;
handleUpgrade(req: EngineRequest, socket: Duplex, upgradeHead: Buffer): void;
/**

@@ -267,3 +262,3 @@ * Called upon a ws.io connection.

* @param {ws.Socket} websocket
* @api private
* @private
*/

@@ -276,3 +271,2 @@ private onWebSocket;

* @param {Object} options
* @api public
*/

@@ -279,0 +273,0 @@ attach(server: HttpServer, options?: AttachOptions): void;

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

* @param {Object} opts - options
* @api public
*/

@@ -89,3 +88,2 @@ constructor(opts = {}) {

* @return {Array}
* @api public
*/

@@ -100,5 +98,6 @@ upgrades(transport) {

*
* @param {http.IncomingMessage}
* @return {Boolean} whether the request is valid
* @api private
* @param {EngineRequest} req
* @param upgrade - whether it's an upgrade request
* @param fn
* @protected
*/

@@ -214,4 +213,2 @@ verify(req, upgrade, fn) {

* Closes all clients.
*
* @api public
*/

@@ -232,4 +229,3 @@ close() {

*
* @param {Object} request object
* @api public
* @param {IncomingMessage} req - the request object
*/

@@ -242,7 +238,7 @@ generateId(req) {

*
* @param {String} transport name
* @param {Object} request object
* @param {String} transportName
* @param {Object} req - the request object
* @param {Function} closeConnection
*
* @api protected
* @protected
*/

@@ -392,3 +388,3 @@ async handshake(transportName, req, closeConnection) {

const transport = new webtransport_1.WebTransport(session, stream, reader);
client.maybeUpgrade(transport);
client._maybeUpgrade(transport);
}

@@ -450,3 +446,3 @@ }

*
* @api protected
* @protected
*/

@@ -492,3 +488,3 @@ init() {

*
* @api private
* @private
*/

@@ -498,3 +494,3 @@ prepare(req) {

if (!req._query) {
req._query = ~req.url.indexOf("?") ? qs.parse((0, url_1.parse)(req.url).query) : {};
req._query = (~req.url.indexOf("?") ? qs.parse((0, url_1.parse)(req.url).query) : {});
}

@@ -508,5 +504,4 @@ }

*
* @param {IncomingMessage} req
* @param {EngineRequest} req
* @param {ServerResponse} res
* @api public
*/

@@ -516,3 +511,2 @@ handleRequest(req, res) {

this.prepare(req);
// @ts-ignore
req.res = res;

@@ -530,6 +524,4 @@ const callback = (errorCode, errorContext) => {

}
// @ts-ignore
if (req._query.sid) {
debug("setting new request for existing client");
// @ts-ignore
this.clients[req._query.sid].transport.onRequest(req);

@@ -539,3 +531,2 @@ }

const closeConnection = (errorCode, errorContext) => abortRequest(res, errorCode, errorContext);
// @ts-ignore
this.handshake(req._query.transport, req, closeConnection);

@@ -555,4 +546,2 @@ }

* Handles an Engine.IO HTTP Upgrade.
*
* @api public
*/

@@ -596,3 +585,3 @@ handleUpgrade(req, socket, upgradeHead) {

* @param {ws.Socket} websocket
* @api private
* @private
*/

@@ -631,3 +620,3 @@ onWebSocket(req, socket, websocket) {

transport.perMessageDeflate = this.opts.perMessageDeflate;
client.maybeUpgrade(transport);
client._maybeUpgrade(transport);
}

@@ -649,3 +638,2 @@ }

* @param {Object} options
* @api public
*/

@@ -710,3 +698,3 @@ attach(server, options = {}) {

*
* @api private
* @private
*/

@@ -730,4 +718,2 @@ function abortRequest(res, errorCode, errorContext) {

* @param {object} errorContext - additional error context
*
* @api private
*/

@@ -734,0 +720,0 @@ function abortUpgrade(socket, errorCode, errorContext = {}) {

/// <reference types="node" />
import { EventEmitter } from "events";
import { IncomingMessage } from "http";
import { Transport } from "./transport";
import { RawData } from "engine.io-parser";
import type { IncomingMessage } from "http";
import type { EngineRequest, Transport } from "./transport";
import type { BaseServer } from "./server";
import type { RawData } from "engine.io-parser";
export interface SendOptions {

@@ -10,11 +11,36 @@ compress?: boolean;

declare type ReadyState = "opening" | "open" | "closing" | "closed";
declare type SendCallback = (transport: Transport) => void;
export declare class Socket extends EventEmitter {
/**
* The revision of the protocol:
*
* - 3rd is used in Engine.IO v3 / Socket.IO v2
* - 4th is used in Engine.IO v4 and above / Socket.IO v3 and above
*
* It is found in the `EIO` query parameters of the HTTP requests.
*
* @see https://github.com/socketio/engine.io-protocol
*/
readonly protocol: number;
/**
* A reference to the first HTTP request of the session
*
* TODO for the next major release: remove it
*/
request: IncomingMessage;
/**
* The IP address of the client.
*/
readonly remoteAddress: string;
/**
* The current state of the socket.
*/
_readyState: ReadyState;
/**
* The current low-level transport.
*/
transport: Transport;
private server;
private upgrading;
private upgraded;
upgrading: boolean;
upgraded: boolean;
private writeBuffer;

@@ -35,12 +61,7 @@ private packetsFn;

set readyState(state: ReadyState);
constructor(id: string, server: BaseServer, transport: Transport, req: EngineRequest, protocol: number);
/**
* Client class (abstract).
*
* @api private
*/
constructor(id: any, server: any, transport: any, req: any, protocol: any);
/**
* Called upon transport considered open.
*
* @api private
* @private
*/

@@ -52,3 +73,3 @@ private onOpen;

* @param {Object} packet
* @api private
* @private
*/

@@ -60,3 +81,3 @@ private onPacket;

* @param {Error} err - error object
* @api private
* @private
*/

@@ -68,3 +89,3 @@ private onError;

*
* @api private
* @private
*/

@@ -75,3 +96,3 @@ private schedulePing;

*
* @api private
* @private
*/

@@ -83,16 +104,22 @@ private resetPingTimeout;

* @param {Transport} transport
* @api private
* @private
*/
private setTransport;
/**
* Upon transport "drain" event
*
* @private
*/
private onDrain;
/**
* Upgrades socket to the given transport
*
* @param {Transport} transport
* @api private
* @private
*/
private maybeUpgrade;
_maybeUpgrade(transport: Transport): void;
/**
* Clears listeners and timers associated with current transport.
*
* @api private
* @private
*/

@@ -107,8 +134,2 @@ private clearTransport;

/**
* Setup and manage send callback
*
* @api private
*/
private setupSendCallback;
/**
* Sends a message packet.

@@ -120,5 +141,4 @@ *

* @return {Socket} for chaining
* @api public
*/
send(data: RawData, options?: SendOptions, callback?: () => void): this;
send(data: RawData, options?: SendOptions, callback?: SendCallback): this;
/**

@@ -131,3 +151,3 @@ * Alias of {@link send}.

*/
write(data: RawData, options?: SendOptions, callback?: () => void): this;
write(data: RawData, options?: SendOptions, callback?: SendCallback): this;
/**

@@ -141,3 +161,3 @@ * Sends a packet.

*
* @api private
* @private
*/

@@ -148,3 +168,3 @@ private sendPacket;

*
* @api private
* @private
*/

@@ -155,3 +175,3 @@ private flush;

*
* @api private
* @private
*/

@@ -164,3 +184,2 @@ private getAvailableUpgrades;

* @return {Socket} for chaining
* @api public
*/

@@ -172,3 +191,3 @@ close(discard?: boolean): void;

* @param {Boolean} discard
* @api private
* @private
*/

@@ -175,0 +194,0 @@ private closeTransport;

@@ -9,12 +9,10 @@ "use strict";

class Socket extends events_1.EventEmitter {
/**
* Client class (abstract).
*
* @api private
*/
constructor(id, server, transport, req, protocol) {
super();
/**
* The current state of the socket.
*/
this._readyState = "opening";
this.upgrading = false;
this.upgraded = false;
/* private */ this.upgrading = false;
/* private */ this.upgraded = false;
this.writeBuffer = [];

@@ -56,3 +54,3 @@ this.packetsFn = [];

*
* @api private
* @private
*/

@@ -76,3 +74,3 @@ onOpen() {

// in protocol v3, the client sends a ping, and the server answers with a pong
this.resetPingTimeout(this.server.opts.pingInterval + this.server.opts.pingTimeout);
this.resetPingTimeout();
}

@@ -88,3 +86,3 @@ else {

* @param {Object} packet
* @api private
* @private
*/

@@ -98,12 +96,10 @@ onPacket(packet) {

this.emit("packet", packet);
// Reset ping timeout on any packet, incoming data is a good sign of
// other side's liveness
this.resetPingTimeout(this.server.opts.pingInterval + this.server.opts.pingTimeout);
switch (packet.type) {
case "ping":
if (this.transport.protocol !== 3) {
this.onError("invalid heartbeat direction");
this.onError(new Error("invalid heartbeat direction"));
return;
}
debug("got ping");
this.pingTimeoutTimer.refresh();
this.sendPacket("pong");

@@ -114,6 +110,7 @@ this.emit("heartbeat");

if (this.transport.protocol === 3) {
this.onError("invalid heartbeat direction");
this.onError(new Error("invalid heartbeat direction"));
return;
}
debug("got pong");
(0, timers_1.clearTimeout)(this.pingTimeoutTimer);
this.pingIntervalTimer.refresh();

@@ -135,3 +132,3 @@ this.emit("heartbeat");

* @param {Error} err - error object
* @api private
* @private
*/

@@ -146,3 +143,3 @@ onError(err) {

*
* @api private
* @private
*/

@@ -153,3 +150,3 @@ schedulePing() {

this.sendPacket("ping");
this.resetPingTimeout(this.server.opts.pingTimeout);
this.resetPingTimeout();
}, this.server.opts.pingInterval);

@@ -160,5 +157,5 @@ }

*
* @api private
* @private
*/
resetPingTimeout(timeout) {
resetPingTimeout() {
(0, timers_1.clearTimeout)(this.pingTimeoutTimer);

@@ -169,3 +166,5 @@ this.pingTimeoutTimer = (0, timers_1.setTimeout)(() => {

this.onClose("ping timeout");
}, timeout);
}, this.protocol === 3
? this.server.opts.pingInterval + this.server.opts.pingTimeout
: this.server.opts.pingTimeout);
}

@@ -176,20 +175,21 @@ /**

* @param {Transport} transport
* @api private
* @private
*/
setTransport(transport) {
const onError = this.onError.bind(this);
const onReady = () => this.flush();
const onPacket = this.onPacket.bind(this);
const flush = this.flush.bind(this);
const onDrain = this.onDrain.bind(this);
const onClose = this.onClose.bind(this, "transport close");
this.transport = transport;
this.transport.once("error", onError);
this.transport.on("ready", onReady);
this.transport.on("packet", onPacket);
this.transport.on("drain", flush);
this.transport.on("drain", onDrain);
this.transport.once("close", onClose);
// this function will manage packet events (also message callbacks)
this.setupSendCallback();
this.cleanupFn.push(function () {
transport.removeListener("error", onError);
transport.removeListener("ready", onReady);
transport.removeListener("packet", onPacket);
transport.removeListener("drain", flush);
transport.removeListener("drain", onDrain);
transport.removeListener("close", onClose);

@@ -199,8 +199,24 @@ });

/**
* Upon transport "drain" event
*
* @private
*/
onDrain() {
if (this.sentCallbackFn.length > 0) {
debug("executing batch send callback");
const seqFn = this.sentCallbackFn.shift();
if (seqFn) {
for (let i = 0; i < seqFn.length; i++) {
seqFn[i](this.transport);
}
}
}
}
/**
* Upgrades socket to the given transport
*
* @param {Transport} transport
* @api private
* @private
*/
maybeUpgrade(transport) {
/* private */ _maybeUpgrade(transport) {
debug('might upgrade socket transport from "%s" to "%s"', this.transport.name, transport.name);

@@ -281,3 +297,3 @@ this.upgrading = true;

*
* @api private
* @private
*/

@@ -322,33 +338,2 @@ clearTransport() {

/**
* Setup and manage send callback
*
* @api private
*/
setupSendCallback() {
// the message was sent successfully, execute the callback
const onDrain = () => {
if (this.sentCallbackFn.length > 0) {
const seqFn = this.sentCallbackFn.splice(0, 1)[0];
if ("function" === typeof seqFn) {
debug("executing send callback");
seqFn(this.transport);
}
else if (Array.isArray(seqFn)) {
debug("executing batch send callback");
const l = seqFn.length;
let i = 0;
for (; i < l; i++) {
if ("function" === typeof seqFn[i]) {
seqFn[i](this.transport);
}
}
}
}
};
this.transport.on("drain", onDrain);
this.cleanupFn.push(() => {
this.transport.removeListener("drain", onDrain);
});
}
/**
* Sends a message packet.

@@ -360,3 +345,2 @@ *

* @return {Socket} for chaining
* @api public
*/

@@ -386,3 +370,3 @@ send(data, options, callback) {

*
* @api private
* @private
*/

@@ -408,3 +392,3 @@ sendPacket(type, data, options = {}, callback) {

// add send callback to object, if defined
if (callback)
if ("function" === typeof callback)
this.packetsFn.push(callback);

@@ -417,3 +401,3 @@ this.flush();

*
* @api private
* @private
*/

@@ -429,9 +413,9 @@ flush() {

this.writeBuffer = [];
if (!this.transport.supportsFraming) {
if (this.packetsFn.length) {
this.sentCallbackFn.push(this.packetsFn);
this.packetsFn = [];
}
else {
this.sentCallbackFn.push.apply(this.sentCallbackFn, this.packetsFn);
this.sentCallbackFn.push(null);
}
this.packetsFn = [];
this.transport.send(wbuf);

@@ -445,3 +429,3 @@ this.emit("drain");

*
* @api private
* @private
*/

@@ -451,5 +435,3 @@ getAvailableUpgrades() {

const allUpgrades = this.server.upgrades(this.transport.name);
let i = 0;
const l = allUpgrades.length;
for (; i < l; ++i) {
for (let i = 0; i < allUpgrades.length; ++i) {
const upg = allUpgrades[i];

@@ -467,3 +449,2 @@ if (this.server.opts.transports.indexOf(upg) !== -1) {

* @return {Socket} for chaining
* @api public
*/

@@ -489,3 +470,3 @@ close(discard) {

* @param {Boolean} discard
* @api private
* @private
*/

@@ -492,0 +473,0 @@ closeTransport(discard) {

/// <reference types="node" />
import { EventEmitter } from "events";
import { IncomingMessage } from "http";
import { Packet } from "engine.io-parser";
import type { IncomingMessage, ServerResponse } from "http";
import { Packet, RawData } from "engine.io-parser";
declare type ReadyState = "open" | "closing" | "closed";
export declare type EngineRequest = IncomingMessage & {
_query: Record<string, string>;
res?: ServerResponse;
cleanup?: Function;
websocket?: any;
};
export declare abstract class Transport extends EventEmitter {
/**
* The session ID.
*/
sid: string;
/**
* Whether the transport is currently ready to send packets.
*/
writable: boolean;
/**
* The revision of the protocol:
*
* - 3 is used in Engine.IO v3 / Socket.IO v2
* - 4 is used in Engine.IO v4 and above / Socket.IO v3 and above
*
* It is found in the `EIO` query parameters of the HTTP requests.
*
* @see https://github.com/socketio/engine.io-protocol
*/
protocol: number;
/**
* The current state of the transport.
* @protected
*/
protected _readyState: ReadyState;
/**
* Whether the transport is discarded and can be safely closed (used during upgrade).
* @protected
*/
protected discarded: boolean;
/**
* The parser to use (depends on the revision of the {@link Transport#protocol}.
* @protected
*/
protected parser: any;
protected req: IncomingMessage & {
cleanup: Function;
};
/**
* Whether the transport supports binary payloads (else it will be base64-encoded)
* @protected
*/
protected supportsBinary: boolean;

@@ -22,10 +57,11 @@ get readyState(): ReadyState;

*
* @param {http.IncomingMessage} req
* @api public
* @param {EngineRequest} req
*/
constructor(req: any);
constructor(req: {
_query: Record<string, string>;
});
/**
* Flags the transport as discarded.
*
* @api private
* @package
*/

@@ -36,12 +72,12 @@ discard(): void;

*
* @param {http.IncomingMessage} req
* @api protected
* @param req
* @package
*/
protected onRequest(req: any): void;
onRequest(req: any): void;
/**
* Closes the transport.
*
* @api private
* @package
*/
close(fn?: any): void;
close(fn?: () => void): void;
/**

@@ -52,3 +88,3 @@ * Called with a transport error.

* @param {Object} desc - error description
* @api protected
* @protected
*/

@@ -60,3 +96,3 @@ protected onError(msg: string, desc?: any): void;

* @param {Object} packet
* @api protected
* @protected
*/

@@ -68,19 +104,15 @@ protected onPacket(packet: Packet): void;

* @param {String} data
* @api protected
* @protected
*/
protected onData(data: any): void;
protected onData(data: RawData): void;
/**
* Called upon transport close.
*
* @api protected
* @protected
*/
protected onClose(): void;
/**
* Advertise framing support.
*/
abstract get supportsFraming(): any;
/**
* The name of the transport.
*/
abstract get name(): any;
abstract get name(): string;
/**

@@ -92,8 +124,8 @@ * Sends an array of packets.

*/
abstract send(packets: any): any;
abstract send(packets: Packet[]): void;
/**
* Closes the transport.
*/
abstract doClose(fn?: any): any;
abstract doClose(fn?: () => void): void;
}
export {};

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

const debug = (0, debug_1.default)("engine:transport");
/**
* Noop function.
*
* @api private
*/
function noop() { }

@@ -20,9 +15,19 @@ class Transport extends events_1.EventEmitter {

*
* @param {http.IncomingMessage} req
* @api public
* @param {EngineRequest} req
*/
constructor(req) {
super();
/**
* Whether the transport is currently ready to send packets.
*/
this.writable = false;
/**
* The current state of the transport.
* @protected
*/
this._readyState = "open";
/**
* Whether the transport is discarded and can be safely closed (used during upgrade).
* @protected
*/
this.discarded = false;

@@ -43,3 +48,3 @@ this.protocol = req._query.EIO === "4" ? 4 : 3; // 3rd revision by default

*
* @api private
* @package
*/

@@ -52,13 +57,10 @@ discard() {

*
* @param {http.IncomingMessage} req
* @api protected
* @param req
* @package
*/
onRequest(req) {
debug("setting request");
this.req = req;
}
onRequest(req) { }
/**
* Closes the transport.
*
* @api private
* @package
*/

@@ -76,3 +78,3 @@ close(fn) {

* @param {Object} desc - error description
* @api protected
* @protected
*/

@@ -96,3 +98,3 @@ onError(msg, desc) {

* @param {Object} packet
* @api protected
* @protected
*/

@@ -106,3 +108,3 @@ onPacket(packet) {

* @param {String} data
* @api protected
* @protected
*/

@@ -115,3 +117,3 @@ onData(data) {

*
* @api protected
* @protected
*/

@@ -118,0 +120,0 @@ onClose() {

@@ -5,2 +5,3 @@ import { Transport } from "../transport";

httpCompression: any;
private req;
private res;

@@ -13,4 +14,2 @@ private dataReq;

* HTTP polling constructor.
*
* @api public.
*/

@@ -20,7 +19,4 @@ constructor(req: any);

* Transport name
*
* @api public
*/
get name(): string;
get supportsFraming(): boolean;
/**

@@ -31,3 +27,3 @@ * Overrides onRequest.

*
* @api private
* @private
*/

@@ -38,3 +34,3 @@ onRequest(req: any): void;

*
* @api private
* @private
*/

@@ -45,3 +41,3 @@ onPollRequest(req: any, res: any): void;

*
* @api private
* @private
*/

@@ -52,3 +48,3 @@ onDataRequest(req: any, res: any): void;

*
* @api private
* @private
*/

@@ -60,3 +56,3 @@ private onDataRequestCleanup;

* @param {String} encoded payload
* @api private
* @private
*/

@@ -67,3 +63,3 @@ onData(data: any): void;

*
* @api private
* @private
*/

@@ -75,3 +71,3 @@ onClose(): void;

* @param {Object} packet
* @api private
* @private
*/

@@ -84,3 +80,3 @@ send(packets: any): void;

* @param {Object} options
* @api private
* @private
*/

@@ -91,3 +87,3 @@ write(data: any, options: any): void;

*
* @api private
* @private
*/

@@ -98,3 +94,3 @@ doWrite(data: any, options: any, callback: any): void;

*
* @api private
* @private
*/

@@ -105,3 +101,3 @@ compress(data: any, encoding: any, callback: any): void;

*
* @api private
* @private
*/

@@ -114,5 +110,5 @@ doClose(fn: any): void;

* @param {Object} extra headers
* @api private
* @private
*/
headers(req: any, headers: any): any;
}

@@ -16,4 +16,2 @@ "use strict";

* HTTP polling constructor.
*
* @api public.
*/

@@ -26,4 +24,2 @@ constructor(req) {

* Transport name
*
* @api public
*/

@@ -33,5 +29,2 @@ get name() {

}
get supportsFraming() {
return false;
}
/**

@@ -42,3 +35,3 @@ * Overrides onRequest.

*
* @api private
* @private
*/

@@ -63,3 +56,3 @@ onRequest(req) {

*
* @api private
* @private
*/

@@ -88,3 +81,3 @@ onPollRequest(req, res) {

this.writable = true;
this.emit("drain");
this.emit("ready");
// if we're still writable but had a pending close, trigger an empty send

@@ -99,3 +92,3 @@ if (this.writable && this.shouldClose) {

*
* @api private
* @private
*/

@@ -180,3 +173,3 @@ onDataRequest(req, res) {

*
* @api private
* @private
*/

@@ -190,3 +183,3 @@ onDataRequestCleanup() {

* @param {String} encoded payload
* @api private
* @private
*/

@@ -213,3 +206,3 @@ onData(data) {

*
* @api private
* @private
*/

@@ -227,3 +220,3 @@ onClose() {

* @param {Object} packet
* @api private
* @private
*/

@@ -256,3 +249,3 @@ send(packets) {

* @param {Object} options
* @api private
* @private
*/

@@ -263,2 +256,3 @@ write(data, options) {

this.req.cleanup();
this.emit("drain");
});

@@ -269,3 +263,3 @@ }

*
* @api private
* @private
*/

@@ -319,3 +313,3 @@ doWrite(data, options, callback) {

*
* @api private
* @private
*/

@@ -340,3 +334,3 @@ compress(data, encoding, callback) {

*
* @api private
* @private
*/

@@ -371,3 +365,3 @@ doClose(fn) {

* @param {Object} extra headers
* @api private
* @private
*/

@@ -374,0 +368,0 @@ headers(req, headers) {

@@ -9,3 +9,2 @@ import { Transport } from "../transport";

* @param req
* @api public
*/

@@ -15,4 +14,2 @@ constructor(req: any);

* Transport name
*
* @api public
*/

@@ -22,17 +19,9 @@ get name(): string;

* Advertise upgrade support.
*
* @api public
*/
get handlesUpgrades(): boolean;
/**
* Advertise framing support.
*
* @api public
*/
get supportsFraming(): boolean;
/**
* Writes a packet payload.
*
* @param {Array} packets
* @api private
* @private
*/

@@ -43,5 +32,5 @@ send(packets: any): void;

*
* @api private
* @private
*/
doClose(fn: any): void;
}

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

* @param req
* @api public
*/

@@ -22,4 +21,2 @@ constructor(req) {

* Transport name
*
* @api public
*/

@@ -31,4 +28,2 @@ get name() {

* Advertise upgrade support.
*
* @api public
*/

@@ -39,14 +34,6 @@ get handlesUpgrades() {

/**
* Advertise framing support.
*
* @api public
*/
get supportsFraming() {
return true;
}
/**
* Writes a packet payload.
*
* @param {Array} packets
* @api private
* @private
*/

@@ -65,4 +52,5 @@ send(packets) {

if (isLast) {
this.emit("drain");
this.writable = true;
this.emit("drain");
this.emit("ready");
}

@@ -81,3 +69,3 @@ };

*
* @api private
* @private
*/

@@ -84,0 +72,0 @@ doClose(fn) {

@@ -12,4 +12,2 @@ import { Polling as XHR } from "./polling";

* Polling polymorphic constructor.
*
* @api private
*/

@@ -16,0 +14,0 @@ declare function polling(req: any): XHR;

@@ -14,4 +14,2 @@ "use strict";

* Polling polymorphic constructor.
*
* @api private
*/

@@ -18,0 +16,0 @@ function polling(req) {

import { Polling } from "./polling";
import type { RawData } from "engine.io-parser";
export declare class JSONP extends Polling {

@@ -7,19 +8,6 @@ private readonly head;

* JSON-P polling transport.
*
* @api public
*/
constructor(req: any);
/**
* Handles incoming data.
* Due to a bug in \n handling by browsers, we expect a escaped string.
*
* @api private
*/
onData(data: any): void;
/**
* Performs the write.
*
* @api private
*/
onData(data: RawData): void;
doWrite(data: any, options: any, callback: any): void;
}

@@ -11,4 +11,2 @@ "use strict";

* JSON-P polling transport.
*
* @api public
*/

@@ -20,8 +18,2 @@ constructor(req) {

}
/**
* Handles incoming data.
* Due to a bug in \n handling by browsers, we expect a escaped string.
*
* @api private
*/
onData(data) {

@@ -40,7 +32,2 @@ // we leverage the qs module so that we get built-in DoS protection

}
/**
* Performs the write.
*
* @api private
*/
doWrite(data, options, callback) {

@@ -47,0 +34,0 @@ // we must output valid javascript, not valid json

@@ -1,7 +0,7 @@

/// <reference types="node" />
import { Transport } from "../transport";
import { IncomingMessage, ServerResponse } from "http";
import { EngineRequest, Transport } from "../transport";
import type { Packet, RawData } from "engine.io-parser";
export declare class Polling extends Transport {
maxHttpBufferSize: number;
httpCompression: any;
private req;
private res;

@@ -14,4 +14,2 @@ private dataReq;

* HTTP polling constructor.
*
* @api public.
*/

@@ -21,49 +19,38 @@ constructor(req: any);

* Transport name
*
* @api public
*/
get name(): string;
get supportsFraming(): boolean;
/**
* Overrides onRequest.
*
* @param {http.IncomingMessage}
* @api private
* @param {EngineRequest} req
* @package
*/
onRequest(req: IncomingMessage & {
res: ServerResponse;
}): void;
onRequest(req: EngineRequest): void;
/**
* The client sends a request awaiting for us to send data.
*
* @api private
* @private
*/
onPollRequest(req: any, res: any): void;
private onPollRequest;
/**
* The client sends a request with data.
*
* @api private
* @private
*/
onDataRequest(req: IncomingMessage, res: ServerResponse): void;
private onDataRequest;
/**
* Processes the incoming data payload.
*
* @param {String} encoded payload
* @api private
* @param data - encoded payload
* @protected
*/
onData(data: any): void;
onData(data: RawData): void;
/**
* Overrides onClose.
*
* @api private
* @private
*/
onClose(): void;
send(packets: Packet[]): void;
/**
* Writes a packet payload.
*
* @param {Object} packet
* @api private
*/
send(packets: any): void;
/**
* Writes data as response to poll request.

@@ -73,31 +60,31 @@ *

* @param {Object} options
* @api private
* @private
*/
write(data: any, options: any): void;
private write;
/**
* Performs the write.
*
* @api private
* @protected
*/
doWrite(data: any, options: any, callback: any): void;
protected doWrite(data: any, options: any, callback: any): void;
/**
* Compresses data.
*
* @api private
* @private
*/
compress(data: any, encoding: any, callback: any): void;
private compress;
/**
* Closes the transport.
*
* @api private
* @private
*/
doClose(fn: any): void;
doClose(fn: () => void): void;
/**
* Returns headers for a response.
*
* @param {http.IncomingMessage} request
* @param {Object} extra headers
* @api private
* @param {http.IncomingMessage} req
* @param {Object} headers - extra headers
* @private
*/
headers(req: any, headers: any): any;
private headers;
}

@@ -16,4 +16,2 @@ "use strict";

* HTTP polling constructor.
*
* @api public.
*/

@@ -26,4 +24,2 @@ constructor(req) {

* Transport name
*
* @api public
*/

@@ -33,10 +29,7 @@ get name() {

}
get supportsFraming() {
return false;
}
/**
* Overrides onRequest.
*
* @param {http.IncomingMessage}
* @api private
* @param {EngineRequest} req
* @package
*/

@@ -61,3 +54,3 @@ onRequest(req) {

*
* @api private
* @private
*/

@@ -86,3 +79,3 @@ onPollRequest(req, res) {

this.writable = true;
this.emit("drain");
this.emit("ready");
// if we're still writable but had a pending close, trigger an empty send

@@ -97,3 +90,3 @@ if (this.writable && this.shouldClose) {

*
* @api private
* @private
*/

@@ -146,3 +139,3 @@ onDataRequest(req, res) {

"Content-Type": "text/html",
"Content-Length": 2,
"Content-Length": "2",
};

@@ -162,4 +155,4 @@ res.writeHead(200, this.headers(req, headers));

*
* @param {String} encoded payload
* @api private
* @param data - encoded payload
* @protected
*/

@@ -186,3 +179,3 @@ onData(data) {

*
* @api private
* @private
*/

@@ -196,8 +189,2 @@ onClose() {

}
/**
* Writes a packet payload.
*
* @param {Object} packet
* @api private
*/
send(packets) {

@@ -229,3 +216,3 @@ this.writable = false;

* @param {Object} options
* @api private
* @private
*/

@@ -236,2 +223,3 @@ write(data, options) {

this.req.cleanup();
this.emit("drain");
});

@@ -242,3 +230,3 @@ }

*
* @api private
* @protected
*/

@@ -289,3 +277,3 @@ doWrite(data, options, callback) {

*
* @api private
* @private
*/

@@ -310,3 +298,3 @@ compress(data, encoding, callback) {

*
* @api private
* @private
*/

@@ -343,8 +331,7 @@ doClose(fn) {

*
* @param {http.IncomingMessage} request
* @param {Object} extra headers
* @api private
* @param {http.IncomingMessage} req
* @param {Object} headers - extra headers
* @private
*/
headers(req, headers) {
headers = headers || {};
headers(req, headers = {}) {
// prevent XSS warnings on IE

@@ -351,0 +338,0 @@ // https://github.com/LearnBoost/socket.io/pull/1333

@@ -1,2 +0,3 @@

import { Transport } from "../transport";
import { EngineRequest, Transport } from "../transport";
import type { Packet } from "engine.io-parser";
export declare class WebSocket extends Transport {

@@ -8,10 +9,7 @@ protected perMessageDeflate: any;

*
* @param {http.IncomingMessage}
* @api public
* @param {EngineRequest} req
*/
constructor(req: any);
constructor(req: EngineRequest);
/**
* Transport name
*
* @api public
*/

@@ -21,20 +19,6 @@ get name(): string;

* Advertise upgrade support.
*
* @api public
*/
get handlesUpgrades(): boolean;
send(packets: Packet[]): void;
/**
* Advertise framing support.
*
* @api public
*/
get supportsFraming(): boolean;
/**
* Writes a packet payload.
*
* @param {Array} packets
* @api private
*/
send(packets: any): void;
/**
* Whether the encoding of the WebSocket frame can be skipped.

@@ -45,8 +29,7 @@ * @param packet

private _canSendPreEncodedFrame;
/**
* Closes the transport.
*
* @api private
*/
doClose(fn: any): void;
private _doSend;
private _doSendLast;
private _onSent;
private _onSentLast;
doClose(fn?: () => void): void;
}

@@ -11,7 +11,27 @@ "use strict";

*
* @param {http.IncomingMessage}
* @api public
* @param {EngineRequest} req
*/
constructor(req) {
super(req);
this._doSend = (data) => {
this.socket.send(data, this._onSent);
};
this._doSendLast = (data) => {
this.socket.send(data, this._onSentLast);
};
this._onSent = (err) => {
if (err) {
this.onError("write error", err.stack);
}
};
this._onSentLast = (err) => {
if (err) {
this.onError("write error", err.stack);
}
else {
this.emit("drain");
this.writable = true;
this.emit("ready");
}
};
this.socket = req.websocket;

@@ -30,4 +50,2 @@ this.socket.on("message", (data, isBinary) => {

* Transport name
*
* @api public
*/

@@ -39,4 +57,2 @@ get name() {

* Advertise upgrade support.
*
* @api public
*/

@@ -46,16 +62,2 @@ get handlesUpgrades() {

}
/**
* Advertise framing support.
*
* @api public
*/
get supportsFraming() {
return true;
}
/**
* Writes a packet payload.
*
* @param {Array} packets
* @api private
*/
send(packets) {

@@ -66,36 +68,11 @@ this.writable = false;

const isLast = i + 1 === packets.length;
// always creates a new object since ws modifies it
const opts = {};
if (packet.options) {
opts.compress = packet.options.compress;
}
const onSent = (err) => {
if (err) {
return this.onError("write error", err.stack);
}
else if (isLast) {
this.writable = true;
this.emit("drain");
}
};
const send = (data) => {
if (this.perMessageDeflate) {
const len = "string" === typeof data ? Buffer.byteLength(data) : data.length;
if (len < this.perMessageDeflate.threshold) {
opts.compress = false;
}
}
debug('writing "%s"', data);
this.socket.send(data, opts, onSent);
};
if (packet.options && typeof packet.options.wsPreEncoded === "string") {
send(packet.options.wsPreEncoded);
}
else if (this._canSendPreEncodedFrame(packet)) {
if (this._canSendPreEncodedFrame(packet)) {
// the WebSocket frame was computed with WebSocket.Sender.frame()
// see https://github.com/websockets/ws/issues/617#issuecomment-283002469
this.socket._sender.sendFrame(packet.options.wsPreEncodedFrame, onSent);
this.socket._sender.sendFrame(
// @ts-ignore
packet.options.wsPreEncodedFrame, isLast ? this._onSentLast : this._onSent);
}
else {
this.parser.encodePacket(packet, this.supportsBinary, send);
this.parser.encodePacket(packet, this.supportsBinary, isLast ? this._doSendLast : this._doSend);
}

@@ -113,9 +90,5 @@ }

typeof ((_b = (_a = this.socket) === null || _a === void 0 ? void 0 : _a._sender) === null || _b === void 0 ? void 0 : _b.sendFrame) === "function" &&
// @ts-ignore
((_c = packet.options) === null || _c === void 0 ? void 0 : _c.wsPreEncodedFrame) !== undefined);
}
/**
* Closes the transport.
*
* @api private
*/
doClose(fn) {

@@ -122,0 +95,0 @@ debug("closing");

@@ -10,5 +10,4 @@ import { Transport } from "../transport";

get name(): string;
get supportsFraming(): boolean;
send(packets: any): Promise<void>;
doClose(fn: any): void;
}

@@ -42,5 +42,2 @@ "use strict";

}
get supportsFraming() {
return true;
}
async send(packets) {

@@ -57,4 +54,5 @@ this.writable = false;

}
this.emit("drain");
this.writable = true;
this.emit("drain");
this.emit("ready");
}

@@ -61,0 +59,0 @@ doClose(fn) {

@@ -25,3 +25,3 @@ import { AttachOptions, BaseServer } from "./server";

*
* @api private
* @private
*/

@@ -28,0 +28,0 @@ private prepare;

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

*
* @api private
* @private
*/

@@ -56,3 +56,3 @@ prepare(req, res) {

transport.writable = true;
transport.emit("drain");
transport.emit("ready");
},

@@ -97,2 +97,3 @@ message: (ws, message, isBinary) => {

debug("setting new request for existing client");
// @ts-ignore
this.clients[req._query.sid].transport.onRequest(req);

@@ -148,3 +149,3 @@ }

transport = this.createTransport(req._query.transport, req);
client.maybeUpgrade(transport);
client._maybeUpgrade(transport);
}

@@ -151,0 +152,0 @@ }

{
"name": "engine.io",
"version": "6.5.5",
"version": "6.6.0",
"description": "The realtime engine behind Socket.IO. Provides the foundation of a bidirectional connection between client and server",

@@ -5,0 +5,0 @@ "type": "commonjs",

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