Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

engine.io

Package Overview
Dependencies
Maintainers
2
Versions
158
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.6.4
to
6.6.5
+12
-11
build/engine.io.d.ts

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

import { Server as HttpServer } from "http";
import { Server, AttachOptions, ServerOptions } from "./server";

@@ -5,3 +6,3 @@ import transports from "./transports/index";

export { Server, transports, listen, attach, parser };
export type { AttachOptions, ServerOptions, BaseServer } from "./server";
export type { AttachOptions, ServerOptions, BaseServer, ErrorCallback, } from "./server";
export { uServer } from "./userver";

@@ -12,17 +13,17 @@ export { Socket } from "./socket";

/**
* Creates an http.Server exclusively used for WS upgrades.
* Creates an http.Server exclusively used for WS upgrades, and starts listening.
*
* @param {Number} port
* @param {Function} callback
* @param {Object} options
* @return {Server} websocket.io server
* @param port
* @param options
* @param listenCallback - callback for http.Server.listen()
* @return engine.io server
*/
declare function listen(port: any, options: AttachOptions & ServerOptions, fn: any): Server;
declare function listen(port: number, options?: AttachOptions & ServerOptions, listenCallback?: () => void): Server;
/**
* Captures upgrade requests for a http.Server.
*
* @param {http.Server} server
* @param {Object} options
* @return {Server} engine server
* @param server
* @param options
* @return engine.io server
*/
declare function attach(server: any, options: AttachOptions & ServerOptions): Server;
declare function attach(server: HttpServer, options: AttachOptions & ServerOptions): Server;

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

/**
* Creates an http.Server exclusively used for WS upgrades.
* Creates an http.Server exclusively used for WS upgrades, and starts listening.
*
* @param {Number} port
* @param {Function} callback
* @param {Object} options
* @return {Server} websocket.io server
* @param port
* @param options
* @param listenCallback - callback for http.Server.listen()
* @return engine.io server
*/
function listen(port, options, fn) {
function listen(port, options, listenCallback) {
if ("function" === typeof options) {
fn = options;
listenCallback = options;
options = {};

@@ -41,3 +41,3 @@ }

engine.httpServer = server;
server.listen(port, fn);
server.listen(port, listenCallback);
return engine;

@@ -48,5 +48,5 @@ }

*
* @param {http.Server} server
* @param {Object} options
* @return {Server} engine server
* @param server
* @param options
* @return engine.io server
*/

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

@@ -32,3 +32,3 @@ /**

*/
export declare function encodePacket(packet: any, supportsBinary: any, utf8encode: any, callback: any): any;
export declare function encodePacket(packet: any, supportsBinary?: any, utf8encode?: any, callback?: any): any;
/**

@@ -44,12 +44,6 @@ * Encodes a packet with binary data in a base64 string

*
* @return {Object} with `type` and `data` (if any)
* @return {import('engine.io-parser').Packet} with `type` and `data` (if any)
* @api private
*/
export declare function decodePacket(data: any, binaryType: any, utf8decode: any): {
type: string;
data: any;
} | {
type: string;
data?: undefined;
};
export declare function decodePacket(data: any, binaryType?: any, utf8decode?: any): any;
/**

@@ -81,3 +75,3 @@ * Decodes a packet encoded in a base64 string.

export declare function encodePayload(packets: any, supportsBinary: any, callback: any): any;
export declare function decodePayload(data: any, binaryType: any, callback: any): any;
export declare function decodePayload(data: any, binaryType?: any, callback?: any): any;
/**

@@ -84,0 +78,0 @@ * Encodes multiple messages (payload) as binary.

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

}
;
/**

@@ -117,3 +116,3 @@ * Encode Buffer data

*
* @return {Object} with `type` and `data` (if any)
* @return {import('engine.io-parser').Packet} with `type` and `data` (if any)
* @api private

@@ -125,3 +124,3 @@ */

}
var type;
let type;
// String data

@@ -139,2 +138,3 @@ if (typeof data === 'string') {

}
// @ts-expect-error
if (Number(type) != type || !packetslist[type]) {

@@ -141,0 +141,0 @@ return err;

import { EventEmitter } from "events";
import { Socket } from "./socket";
import { type PerMessageDeflateOptions } from "ws";
import type { IncomingMessage, Server as HttpServer, ServerResponse } from "http";
import type { CorsOptions, CorsOptionsDelegate } from "cors";
import type { Duplex } from "stream";
import type { EngineRequest } from "./transport";
import type { EngineRequest, Transport } from "./transport";
import type { CookieSerializeOptions } from "./contrib/types.cookie";
type Transport = "polling" | "websocket" | "webtransport";
type TransportName = "polling" | "websocket" | "webtransport";
export type ErrorCallback = (errorCode?: (typeof Server.errors)[keyof typeof Server.errors], errorContext?: Record<string, unknown> & {
name?: string;
message?: string;
}) => void;
export interface AttachOptions {

@@ -69,3 +74,3 @@ /**

*/
transports?: Transport[];
transports?: TransportName[];
/**

@@ -80,3 +85,3 @@ * whether to allow transport upgrades

*/
perMessageDeflate?: boolean | object;
perMessageDeflate?: boolean | PerMessageDeflateOptions;
/**

@@ -137,3 +142,3 @@ * parameters of the http compression for the polling transports (see zlib api docs). Set to false to disable.

constructor(opts?: ServerOptions);
protected abstract init(): any;
protected abstract init(): void;
/**

@@ -147,6 +152,4 @@ * Compute the pathname of the requests that are handled by the server

* Returns a list of available transports for upgrade given a certain transport.
*
* @return {Array}
*/
upgrades(transport: string): any;
upgrades(transport: TransportName): string[];
/**

@@ -159,4 +162,5 @@ * Verifies a request.

* @protected
* @return whether the request is valid
*/
protected verify(req: any, upgrade: boolean, fn: (errorCode?: number, errorContext?: any) => void): void;
protected verify(req: EngineRequest, upgrade: boolean, fn: ErrorCallback): void | boolean;
/**

@@ -193,3 +197,3 @@ * Adds a new middleware.

*/
generateId(req: IncomingMessage): any;
generateId(req: IncomingMessage): string | PromiseLike<string>;
/**

@@ -204,5 +208,5 @@ * Handshakes a new client.

*/
protected handshake(transportName: string, req: any, closeConnection: (errorCode?: number, errorContext?: any) => void): Promise<any>;
protected handshake(transportName: TransportName, req: EngineRequest, closeConnection: ErrorCallback): Promise<any>;
onWebTransportSession(session: any): Promise<any>;
protected abstract createTransport(transportName: any, req: any): any;
protected abstract createTransport(transportName: TransportName, req: EngineRequest): any;
/**

@@ -212,16 +216,16 @@ * Protocol errors mappings.

static errors: {
UNKNOWN_TRANSPORT: number;
UNKNOWN_SID: number;
BAD_HANDSHAKE_METHOD: number;
BAD_REQUEST: number;
FORBIDDEN: number;
UNSUPPORTED_PROTOCOL_VERSION: number;
readonly UNKNOWN_TRANSPORT: 0;
readonly UNKNOWN_SID: 1;
readonly BAD_HANDSHAKE_METHOD: 2;
readonly BAD_REQUEST: 3;
readonly FORBIDDEN: 4;
readonly UNSUPPORTED_PROTOCOL_VERSION: 5;
};
static errorMessages: {
0: string;
1: string;
2: string;
3: string;
4: string;
5: string;
readonly 0: "Transport unknown";
readonly 1: "Session ID unknown";
readonly 2: "Bad handshake method";
readonly 3: "Bad request";
readonly 4: "Forbidden";
readonly 5: "Unsupported protocol version";
};

@@ -248,3 +252,3 @@ }

private prepare;
protected createTransport(transportName: string, req: IncomingMessage): any;
protected createTransport(transportName: TransportName, req: IncomingMessage): Transport;
/**

@@ -263,4 +267,5 @@ * Handles an Engine.IO HTTP request.

* Called upon a ws.io connection.
*
* @param {ws.Socket} websocket
* @param req
* @param socket
* @param websocket
* @private

@@ -267,0 +272,0 @@ */

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Server = exports.BaseServer = void 0;
const qs = require("querystring");
const url_1 = require("url");
const base64id = require("base64id");

@@ -85,4 +83,2 @@ const transports_1 = require("./transports");

* Returns a list of available transports for upgrade given a certain transport.
*
* @return {Array}
*/

@@ -101,2 +97,3 @@ upgrades(transport) {

* @protected
* @return whether the request is valid
*/

@@ -490,6 +487,8 @@ verify(req, upgrade, fn) {

if (!req._query) {
req._query = (~req.url.indexOf("?") ? qs.parse((0, url_1.parse)(req.url).query) : {});
const url = new URL(req.url, "https://socket.io");
req._query = Object.fromEntries(url.searchParams.entries());
}
}
createTransport(transportName, req) {
// @ts-expect-error 'polling' is a plain function used as constructor
return new transports_1.default[transportName](req);

@@ -574,4 +573,5 @@ }

* Called upon a ws.io connection.
*
* @param {ws.Socket} websocket
* @param req
* @param socket
* @param websocket
* @private

@@ -610,2 +610,3 @@ */

const transport = this.createTransport(req._query.transport, req);
// @ts-expect-error this option is only for WebSocket impl
transport.perMessageDeflate = this.opts.perMessageDeflate;

@@ -612,0 +613,0 @@ client._maybeUpgrade(transport);

import { EventEmitter } from "events";
import * as parser_v4 from "engine.io-parser";
import * as parser_v3 from "./parser-v3/index";
import type { IncomingMessage, ServerResponse } from "http";
import { Packet, RawData } from "engine.io-parser";
import type { WebSocket } from "ws";
type ReadyState = "open" | "closing" | "closed";

@@ -9,3 +12,7 @@ export type EngineRequest = IncomingMessage & {

cleanup?: Function;
websocket?: any;
websocket?: WebSocket & {
_socket?: {
remoteAddress: string;
};
};
};

@@ -31,3 +38,3 @@ export declare abstract class Transport extends EventEmitter {

*/
protocol: number;
protocol: 3 | 4;
/**

@@ -47,3 +54,3 @@ * The current state of the transport.

*/
protected parser: any;
protected parser: typeof parser_v4 | typeof parser_v3;
/**

@@ -57,2 +64,6 @@ * Whether the transport supports binary payloads (else it will be base64-encoded)

/**
* The list of transports this transport can be upgraded to.
*/
static upgradesTo: string[];
/**
* Transport constructor.

@@ -102,3 +113,3 @@ *

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

@@ -105,0 +116,0 @@ */

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

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

@@ -119,1 +119,5 @@ */

exports.Transport = Transport;
/**
* The list of transports this transport can be upgraded to.
*/
Transport.upgradesTo = [];
import { Polling as XHR } from "./polling";
import { WebSocket } from "./websocket";
import { WebTransport } from "./webtransport";
import type { EngineRequest } from "../transport";
declare const _default: {

@@ -13,5 +14,5 @@ polling: typeof polling;

*/
declare function polling(req: any): XHR;
declare function polling(req: EngineRequest): XHR;
declare namespace polling {
var upgradesTo: string[];
}

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

exports.default = {
polling: polling,
polling,
websocket: websocket_1.WebSocket,

@@ -11,0 +11,0 @@ webtransport: webtransport_1.WebTransport,

import { EngineRequest, Transport } from "../transport";
import type { Packet } from "engine.io-parser";
import type { PerMessageDeflateOptions } from "ws";
export declare class WebSocket extends Transport {
protected perMessageDeflate: any;
perMessageDeflate?: boolean | PerMessageDeflateOptions;
private socket;

@@ -6,0 +7,0 @@ /**

@@ -67,5 +67,4 @@ "use strict";

// see https://github.com/websockets/ws/issues/617#issuecomment-283002469
this.socket._sender.sendFrame(
// @ts-ignore
packet.options.wsPreEncodedFrame, isLast ? this._onSentLast : this._onSent);
// @ts-expect-error use of untyped member
this.socket._sender.sendFrame(packet.options.wsPreEncodedFrame, isLast ? this._onSentLast : this._onSent);
}

@@ -85,4 +84,4 @@ else {

return (!this.perMessageDeflate &&
// @ts-expect-error use of untyped member
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);

@@ -89,0 +88,0 @@ }

import { AttachOptions, BaseServer } from "./server";
import { EngineRequest } from "./transport";
export interface uOptions {

@@ -31,3 +32,3 @@ /**

private prepare;
protected createTransport(transportName: any, req: any): any;
protected createTransport(transportName: string, req: EngineRequest): any;
/**

@@ -34,0 +35,0 @@ * Attach the engine to a µWebSockets.js server

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

});
// @ts-expect-error
req.connection = {

@@ -31,0 +32,0 @@ remoteAddress: Buffer.from(res.getRemoteAddressAsText()).toString(),

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

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

"cors": "~2.8.5",
"debug": "~4.3.1",
"debug": "~4.4.1",
"engine.io-parser": "~5.2.1",
"ws": "~8.17.1"
"ws": "~8.18.3"
},

@@ -45,0 +45,0 @@ "scripts": {