Skip to content

Commit

Permalink
chore: bump engine.io to version 6.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
darrachequesne committed Oct 11, 2021
1 parent 4974e90 commit eb5fdbd
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 120 deletions.
3 changes: 2 additions & 1 deletion lib/client.ts
Expand Up @@ -7,6 +7,7 @@ import type { Namespace } from "./namespace";
import type { EventsMap } from "./typed-events";
import type { Socket } from "./socket";
import type { SocketId } from "socket.io-adapter";
import type { Socket as RawSocket } from "engine.io";

const debug = debugModule("socket.io:client");

Expand All @@ -22,7 +23,7 @@ export class Client<
EmitEvents extends EventsMap,
ServerSideEvents extends EventsMap
> {
public readonly conn;
public readonly conn: RawSocket;

private readonly id: string;
private readonly server: Server<ListenEvents, EmitEvents, ServerSideEvents>;
Expand Down
118 changes: 10 additions & 108 deletions lib/index.ts
Expand Up @@ -4,7 +4,12 @@ import { createDeflate, createGzip, createBrotliCompress } from "zlib";
import accepts = require("accepts");
import { pipeline } from "stream";
import path = require("path");
import engine = require("engine.io");
import {
attach,
Server as Engine,
ServerOptions as EngineOptions,
AttachOptions,
} from "engine.io";
import { Client } from "./client";
import { EventEmitter } from "events";
import { ExtendedError, Namespace, ServerReservedEventsMap } from "./namespace";
Expand All @@ -14,8 +19,6 @@ import * as parser from "socket.io-parser";
import type { Encoder } from "socket.io-parser";
import debugModule from "debug";
import { Socket } from "./socket";
import type { CookieSerializeOptions } from "cookie";
import type { CorsOptions } from "cors";
import type { BroadcastOperator, RemoteSocket } from "./broadcast-operator";
import {
EventsMap,
Expand All @@ -30,7 +33,6 @@ const debug = debugModule("socket.io:server");
const clientVersion = require("../package.json").version;
const dotMapRegex = /\.map/;

type Transport = "polling" | "websocket";
type ParentNspNameMatchFn = (
name: string,
auth: { [key: string]: any },
Expand All @@ -39,107 +41,7 @@ type ParentNspNameMatchFn = (

type AdapterConstructor = typeof Adapter | ((nsp: Namespace) => Adapter);

interface EngineOptions {
/**
* how many ms without a pong packet to consider the connection closed
* @default 20000
*/
pingTimeout: number;
/**
* how many ms before sending a new ping packet
* @default 25000
*/
pingInterval: number;
/**
* 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 1e5 (100 KB)
*/
maxHttpBufferSize: number;
/**
* A function that receives a given handshake or upgrade request as its first parameter,
* and can decide whether to continue or not. The second argument is a function that needs
* to be called with the decided information: fn(err, success), where success is a boolean
* value where false means that the request is rejected, and err is an error code.
*/
allowRequest: (
req: http.IncomingMessage,
fn: (err: string | null | undefined, success: boolean) => void
) => void;
/**
* the low-level transports that are enabled
* @default ["polling", "websocket"]
*/
transports: Transport[];
/**
* 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.
* @default false
*/
perMessageDeflate: boolean | object;
/**
* parameters of the http compression for the polling transports (see zlib api docs). Set to false to disable.
* @default true
*/
httpCompression: boolean | object;
/**
* what WebSocket server implementation to use. Specified module must
* conform to the ws interface (see ws module api docs).
* An alternative c++ addon is also available by installing eiows module.
*
* @default `require("ws").Server`
*/
wsEngine: Function;
/**
* an optional packet which will be concatenated to the handshake packet emitted by Engine.IO.
*/
initialPacket: any;
/**
* 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.
* @default false
*/
cookie: (CookieSerializeOptions & { name: string }) | boolean;
/**
* the options that will be forwarded to the cors module
*/
cors: CorsOptions;
/**
* whether to enable compatibility with Socket.IO v2 clients
* @default false
*/
allowEIO3: boolean;
}

interface AttachOptions {
/**
* name of the path to capture
* @default "/engine.io"
*/
path: string;
/**
* destroy unhandled upgrade requests
* @default true
*/
destroyUpgrade: boolean;
/**
* milliseconds after which unhandled requests are ended
* @default 1000
*/
destroyUpgradeTimeout: number;
}

interface EngineAttachOptions extends EngineOptions, AttachOptions {}

interface ServerOptions extends EngineAttachOptions {
interface ServerOptions extends EngineOptions, AttachOptions {
/**
* name of the path to capture
* @default "/socket.io"
Expand Down Expand Up @@ -210,7 +112,7 @@ export class Server<
private _adapter?: AdapterConstructor;
private _serveClient: boolean;
private opts: Partial<EngineOptions>;
private eio;
private eio: Engine;
private _path: string;
private clientPathRegex: RegExp;

Expand Down Expand Up @@ -443,11 +345,11 @@ export class Server<
*/
private initEngine(
srv: http.Server,
opts: Partial<EngineAttachOptions>
opts: EngineOptions & AttachOptions
): void {
// initialize engine
debug("creating engine.io instance with opts %j", opts);
this.eio = engine.attach(srv, opts);
this.eio = attach(srv, opts);

// attach static file serving
if (this._serveClient) this.attachServe(srv);
Expand Down
39 changes: 32 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions package.json
Expand Up @@ -45,13 +45,10 @@
"prepack": "npm run compile"
},
"dependencies": {
"@types/cookie": "^0.4.1",
"@types/cors": "^2.8.12",
"@types/node": ">=10.0.0",
"accepts": "~1.3.4",
"base64id": "~2.0.0",
"debug": "~4.3.2",
"engine.io": "~5.2.0",
"engine.io": "~6.0.0",
"socket.io-adapter": "~2.3.2",
"socket.io-parser": "~4.0.4"
},
Expand Down

0 comments on commit eb5fdbd

Please sign in to comment.