Ignore:
Timestamp:
11/25/21 22:08:24 (3 years ago)
Author:
Ema <ema_spirova@…>
Branches:
master
Children:
8d391a1
Parents:
59329aa
Message:

primeNG components

Location:
trip-planner-front/node_modules/socket.io/dist
Files:
6 added
10 edited

Legend:

Unmodified
Added
Removed
  • trip-planner-front/node_modules/socket.io/dist/client.d.ts

    r59329aa re29cc2e  
    33import type { IncomingMessage } from "http";
    44import type { Server } from "./index";
     5import type { EventsMap } from "./typed-events";
    56import type { Socket } from "./socket";
    6 export declare class Client {
    7     readonly conn: any;
     7import type { Socket as RawSocket } from "engine.io";
     8interface WriteOptions {
     9    compress?: boolean;
     10    volatile?: boolean;
     11    preEncoded?: boolean;
     12    wsPreEncoded?: string;
     13}
     14export declare class Client<ListenEvents extends EventsMap, EmitEvents extends EventsMap, ServerSideEvents extends EventsMap, SocketData = any> {
     15    readonly conn: RawSocket;
    816    private readonly id;
    917    private readonly server;
     
    2028     * @package
    2129     */
    22     constructor(server: Server, conn: Socket);
     30    constructor(server: Server<ListenEvents, EmitEvents, ServerSideEvents, SocketData>, conn: any);
    2331    /**
    2432     * @return the reference to the request that originated the Engine.IO connection
     
    6169     * @private
    6270     */
    63     _remove(socket: Socket): void;
     71    _remove(socket: Socket<ListenEvents, EmitEvents, ServerSideEvents, SocketData>): void;
    6472    /**
    6573     * Closes the underlying connection.
     
    7583     * @private
    7684     */
    77     _packet(packet: Packet, opts?: any): void;
     85    _packet(packet: Packet | any[], opts?: WriteOptions): void;
     86    private writeToEngine;
    7887    /**
    7988     * Called with incoming transport data.
     
    108117    private destroy;
    109118}
     119export {};
  • trip-planner-front/node_modules/socket.io/dist/client.js

    r59329aa re29cc2e  
    7171        this.server._checkNamespace(name, auth, (dynamicNspName) => {
    7272            if (dynamicNspName) {
    73                 debug("dynamic namespace %s was created", dynamicNspName);
    7473                this.doConnect(name, auth);
    7574            }
     
    151150     * @private
    152151     */
    153     _packet(packet, opts) {
    154         opts = opts || {};
    155         const self = this;
    156         // this writes to the actual connection
    157         function writeToEngine(encodedPackets) {
    158             // TODO clarify this.
    159             if (opts.volatile && !self.conn.transport.writable)
    160                 return;
    161             for (let i = 0; i < encodedPackets.length; i++) {
    162                 self.conn.write(encodedPackets[i], { compress: opts.compress });
    163             }
    164         }
    165         if ("open" === this.conn.readyState) {
    166             debug("writing packet %j", packet);
    167             if (!opts.preEncoded) {
    168                 // not broadcasting, need to encode
    169                 writeToEngine(this.encoder.encode(packet)); // encode, then write results to engine
    170             }
    171             else {
    172                 // a broadcast pre-encodes a packet
    173                 writeToEngine(packet);
    174             }
    175         }
    176         else {
     152    _packet(packet, opts = {}) {
     153        if (this.conn.readyState !== "open") {
    177154            debug("ignoring packet write %j", packet);
     155            return;
     156        }
     157        const encodedPackets = opts.preEncoded
     158            ? packet // previous versions of the adapter incorrectly used socket.packet() instead of writeToEngine()
     159            : this.encoder.encode(packet);
     160        this.writeToEngine(encodedPackets, opts);
     161    }
     162    writeToEngine(encodedPackets, opts) {
     163        if (opts.volatile && !this.conn.transport.writable) {
     164            debug("volatile packet is discarded since the transport is not currently writable");
     165            return;
     166        }
     167        const packets = Array.isArray(encodedPackets)
     168            ? encodedPackets
     169            : [encodedPackets];
     170        for (const encodedPacket of packets) {
     171            this.conn.write(encodedPacket, opts);
    178172        }
    179173    }
  • trip-planner-front/node_modules/socket.io/dist/index.d.ts

    r59329aa re29cc2e  
    11/// <reference types="node" />
    22import http = require("http");
    3 import { EventEmitter } from "events";
    4 import { ExtendedError, Namespace } from "./namespace";
     3import { ServerOptions as EngineOptions, AttachOptions } from "engine.io";
     4import { ExtendedError, Namespace, ServerReservedEventsMap } from "./namespace";
    55import { Adapter, Room, SocketId } from "socket.io-adapter";
    66import * as parser from "socket.io-parser";
    77import type { Encoder } from "socket.io-parser";
    88import { Socket } from "./socket";
    9 import type { CookieSerializeOptions } from "cookie";
    10 import type { CorsOptions } from "cors";
    11 declare type Transport = "polling" | "websocket";
     9import type { BroadcastOperator, RemoteSocket } from "./broadcast-operator";
     10import { EventsMap, DefaultEventsMap, EventParams, StrictEventEmitter, EventNames } from "./typed-events";
    1211declare type ParentNspNameMatchFn = (name: string, auth: {
    1312    [key: string]: any;
    1413}, fn: (err: Error | null, success: boolean) => void) => void;
    15 interface EngineOptions {
    16     /**
    17      * how many ms without a pong packet to consider the connection closed
    18      * @default 5000
    19      */
    20     pingTimeout: number;
    21     /**
    22      * how many ms before sending a new ping packet
    23      * @default 25000
    24      */
    25     pingInterval: number;
    26     /**
    27      * how many ms before an uncompleted transport upgrade is cancelled
    28      * @default 10000
    29      */
    30     upgradeTimeout: number;
    31     /**
    32      * how many bytes or characters a message can be, before closing the session (to avoid DoS).
    33      * @default 1e5 (100 KB)
    34      */
    35     maxHttpBufferSize: number;
    36     /**
    37      * A function that receives a given handshake or upgrade request as its first parameter,
    38      * and can decide whether to continue or not. The second argument is a function that needs
    39      * to be called with the decided information: fn(err, success), where success is a boolean
    40      * value where false means that the request is rejected, and err is an error code.
    41      */
    42     allowRequest: (req: http.IncomingMessage, fn: (err: string | null | undefined, success: boolean) => void) => void;
    43     /**
    44      * the low-level transports that are enabled
    45      * @default ["polling", "websocket"]
    46      */
    47     transports: Transport[];
    48     /**
    49      * whether to allow transport upgrades
    50      * @default true
    51      */
    52     allowUpgrades: boolean;
    53     /**
    54      * parameters of the WebSocket permessage-deflate extension (see ws module api docs). Set to false to disable.
    55      * @default false
    56      */
    57     perMessageDeflate: boolean | object;
    58     /**
    59      * parameters of the http compression for the polling transports (see zlib api docs). Set to false to disable.
    60      * @default true
    61      */
    62     httpCompression: boolean | object;
    63     /**
    64      * what WebSocket server implementation to use. Specified module must
    65      * conform to the ws interface (see ws module api docs). Default value is ws.
    66      * An alternative c++ addon is also available by installing uws module.
    67      */
    68     wsEngine: string;
    69     /**
    70      * an optional packet which will be concatenated to the handshake packet emitted by Engine.IO.
    71      */
    72     initialPacket: any;
    73     /**
    74      * configuration of the cookie that contains the client sid to send as part of handshake response headers. This cookie
    75      * might be used for sticky-session. Defaults to not sending any cookie.
    76      * @default false
    77      */
    78     cookie: CookieSerializeOptions | boolean;
    79     /**
    80      * the options that will be forwarded to the cors module
    81      */
    82     cors: CorsOptions;
    83     /**
    84      * whether to enable compatibility with Socket.IO v2 clients
    85      * @default false
    86      */
    87     allowEIO3: boolean;
    88 }
    89 interface AttachOptions {
    90     /**
    91      * name of the path to capture
    92      * @default "/engine.io"
    93      */
    94     path: string;
    95     /**
    96      * destroy unhandled upgrade requests
    97      * @default true
    98      */
    99     destroyUpgrade: boolean;
    100     /**
    101      * milliseconds after which unhandled requests are ended
    102      * @default 1000
    103      */
    104     destroyUpgradeTimeout: number;
    105 }
    106 interface EngineAttachOptions extends EngineOptions, AttachOptions {
    107 }
    108 interface ServerOptions extends EngineAttachOptions {
     14declare type AdapterConstructor = typeof Adapter | ((nsp: Namespace) => Adapter);
     15interface ServerOptions extends EngineOptions, AttachOptions {
    10916    /**
    11017     * name of the path to capture
     
    12128     * @default the in-memory adapter (https://github.com/socketio/socket.io-adapter)
    12229     */
    123     adapter: any;
     30    adapter: AdapterConstructor;
    12431    /**
    12532     * the parser to use
     
    13340    connectTimeout: number;
    13441}
    135 export declare class Server extends EventEmitter {
    136     readonly sockets: Namespace;
     42export declare class Server<ListenEvents extends EventsMap = DefaultEventsMap, EmitEvents extends EventsMap = ListenEvents, ServerSideEvents extends EventsMap = DefaultEventsMap, SocketData = any> extends StrictEventEmitter<ServerSideEvents, EmitEvents, ServerReservedEventsMap<ListenEvents, EmitEvents, ServerSideEvents, SocketData>> {
     43    readonly sockets: Namespace<ListenEvents, EmitEvents, ServerSideEvents, SocketData>;
     44    /**
     45     * A reference to the underlying Engine.IO server.
     46     *
     47     * Example:
     48     *
     49     * <code>
     50     *   const clientsCount = io.engine.clientsCount;
     51     * </code>
     52     *
     53     */
     54    engine: any;
    13755    /** @private */
    13856    readonly _parser: typeof parser;
     
    14260     * @private
    14361     */
    144     _nsps: Map<string, Namespace>;
     62    _nsps: Map<string, Namespace<ListenEvents, EmitEvents, ServerSideEvents>>;
    14563    private parentNsps;
    14664    private _adapter?;
     
    14866    private opts;
    14967    private eio;
    150     private engine;
    15168    private _path;
    15269    private clientPathRegex;
     
    187104    _checkNamespace(name: string, auth: {
    188105        [key: string]: any;
    189     }, fn: (nsp: Namespace | false) => void): void;
     106    }, fn: (nsp: Namespace<ListenEvents, EmitEvents, ServerSideEvents> | false) => void): void;
    190107    /**
    191108     * Sets the client serving path.
     
    213130     * @public
    214131     */
    215     adapter(): typeof Adapter | undefined;
    216     adapter(v: typeof Adapter): this;
    217     adapter(v?: typeof Adapter): typeof Adapter | undefined | this;
     132    adapter(): AdapterConstructor | undefined;
     133    adapter(v: AdapterConstructor): this;
    218134    /**
    219135     * Attaches socket.io to a server or port.
     
    234150     */
    235151    attach(srv: http.Server | number, opts?: Partial<ServerOptions>): this;
     152    attachApp(app: any, opts?: Partial<ServerOptions>): void;
    236153    /**
    237154     * Initialize engine
     
    287204     * @public
    288205     */
    289     of(name: string | RegExp | ParentNspNameMatchFn, fn?: (socket: Socket) => void): Namespace;
     206    of(name: string | RegExp | ParentNspNameMatchFn, fn?: (socket: Socket<ListenEvents, EmitEvents, ServerSideEvents, SocketData>) => void): Namespace<ListenEvents, EmitEvents, ServerSideEvents>;
    290207    /**
    291208     * Closes server connection
     
    301218     * @public
    302219     */
    303     use(fn: (socket: Socket, next: (err?: ExtendedError) => void) => void): this;
     220    use(fn: (socket: Socket<ListenEvents, EmitEvents, ServerSideEvents, SocketData>, next: (err?: ExtendedError) => void) => void): this;
    304221    /**
    305222     * Targets a room when emitting.
    306223     *
     224     * @param room
     225     * @return self
     226     * @public
     227     */
     228    to(room: Room | Room[]): BroadcastOperator<EmitEvents>;
     229    /**
     230     * Targets a room when emitting.
     231     *
     232     * @param room
     233     * @return self
     234     * @public
     235     */
     236    in(room: Room | Room[]): BroadcastOperator<EmitEvents>;
     237    /**
     238     * Excludes a room when emitting.
     239     *
    307240     * @param name
    308241     * @return self
    309242     * @public
    310243     */
    311     to(name: Room): this;
    312     /**
    313      * Targets a room when emitting.
    314      *
    315      * @param name
    316      * @return self
    317      * @public
    318      */
    319     in(name: Room): this;
     244    except(name: Room | Room[]): BroadcastOperator<EmitEvents>;
    320245    /**
    321246     * Sends a `message` event to all clients.
     
    324249     * @public
    325250     */
    326     send(...args: readonly any[]): this;
     251    send(...args: EventParams<EmitEvents, "message">): this;
    327252    /**
    328253     * Sends a `message` event to all clients.
     
    331256     * @public
    332257     */
    333     write(...args: readonly any[]): this;
     258    write(...args: EventParams<EmitEvents, "message">): this;
     259    /**
     260     * Emit a packet to other Socket.IO servers
     261     *
     262     * @param ev - the event name
     263     * @param args - an array of arguments, which may include an acknowledgement callback at the end
     264     * @public
     265     */
     266    serverSideEmit<Ev extends EventNames<ServerSideEvents>>(ev: Ev, ...args: EventParams<ServerSideEvents, Ev>): boolean;
    334267    /**
    335268     * Gets a list of socket ids.
     
    345278     * @public
    346279     */
    347     compress(compress: boolean): this;
     280    compress(compress: boolean): BroadcastOperator<EmitEvents>;
    348281    /**
    349282     * Sets a modifier for a subsequent event emission that the event data may be lost if the client is not ready to
     
    354287     * @public
    355288     */
    356     get volatile(): this;
     289    get volatile(): BroadcastOperator<EmitEvents>;
    357290    /**
    358291     * Sets a modifier for a subsequent event emission that the event data will only be broadcast to the current node.
     
    361294     * @public
    362295     */
    363     get local(): this;
     296    get local(): BroadcastOperator<EmitEvents>;
     297    /**
     298     * Returns the matching socket instances
     299     *
     300     * @public
     301     */
     302    fetchSockets(): Promise<RemoteSocket<EmitEvents>[]>;
     303    /**
     304     * Makes the matching socket instances join the specified rooms
     305     *
     306     * @param room
     307     * @public
     308     */
     309    socketsJoin(room: Room | Room[]): void;
     310    /**
     311     * Makes the matching socket instances leave the specified rooms
     312     *
     313     * @param room
     314     * @public
     315     */
     316    socketsLeave(room: Room | Room[]): void;
     317    /**
     318     * Makes the matching socket instances disconnect
     319     *
     320     * @param close - whether to close the underlying connection
     321     * @public
     322     */
     323    disconnectSockets(close?: boolean): void;
    364324}
    365 export { Socket, ServerOptions, Namespace };
     325export { Socket, ServerOptions, Namespace, BroadcastOperator, RemoteSocket };
  • trip-planner-front/node_modules/socket.io/dist/index.js

    r59329aa re29cc2e  
    3030const stream_1 = require("stream");
    3131const path = require("path");
    32 const engine = require("engine.io");
     32const engine_io_1 = require("engine.io");
    3333const client_1 = require("./client");
    3434const events_1 = require("events");
     
    4141const socket_1 = require("./socket");
    4242Object.defineProperty(exports, "Socket", { enumerable: true, get: function () { return socket_1.Socket; } });
    43 const debug = debug_1.default("socket.io:server");
     43const typed_events_1 = require("./typed-events");
     44const uws_js_1 = require("./uws.js");
     45const debug = (0, debug_1.default)("socket.io:server");
    4446const clientVersion = require("../package.json").version;
    4547const dotMapRegex = /\.map/;
    46 class Server extends events_1.EventEmitter {
     48class Server extends typed_events_1.StrictEventEmitter {
    4749    constructor(srv, opts = {}) {
    4850        super();
     
    6668        this.sockets = this.of("/");
    6769        this.opts = opts;
    68         if (srv)
     70        if (srv || typeof srv == "number")
    6971            this.attach(srv);
    7072    }
     
    9597            nextFn.value(name, auth, (err, allow) => {
    9698                if (err || !allow) {
    97                     run();
     99                    return run();
    98100                }
    99                 else {
    100                     fn(this.parentNsps.get(nextFn.value).createChild(name));
     101                if (this._nsps.has(name)) {
     102                    // the namespace was created in the meantime
     103                    debug("dynamic namespace %s already exists", name);
     104                    return fn(this._nsps.get(name));
    101105                }
     106                const namespace = this.parentNsps.get(nextFn.value).createChild(name);
     107                debug("dynamic namespace %s was created", name);
     108                // @ts-ignore
     109                this.sockets.emitReserved("new_namespace", namespace);
     110                fn(namespace);
    102111            });
    103112        };
     
    111120        this.clientPathRegex = new RegExp("^" +
    112121            escapedPath +
    113             "/socket\\.io(\\.min|\\.msgpack\\.min)?\\.js(\\.map)?$");
     122            "/socket\\.io(\\.msgpack|\\.esm)?(\\.min)?\\.js(\\.map)?(?:\\?|$)");
    114123        return this;
    115124    }
     
    174183        return this;
    175184    }
     185    attachApp(app /*: TemplatedApp */, opts = {}) {
     186        // merge the options passed to the Socket.IO server
     187        Object.assign(opts, this.opts);
     188        // set engine.io path to `/socket.io`
     189        opts.path = opts.path || this._path;
     190        // initialize engine
     191        debug("creating uWebSockets.js-based engine with opts %j", opts);
     192        const engine = new engine_io_1.uServer(opts);
     193        engine.attach(app, opts);
     194        // bind to engine events
     195        this.bind(engine);
     196        if (this._serveClient) {
     197            // attach static file serving
     198            app.get(`${this._path}/*`, (res, req) => {
     199                if (!this.clientPathRegex.test(req.getUrl())) {
     200                    req.setYield(true);
     201                    return;
     202                }
     203                const filename = req
     204                    .getUrl()
     205                    .replace(this._path, "")
     206                    .replace(/\?.*$/, "")
     207                    .replace(/^\//, "");
     208                const isMap = dotMapRegex.test(filename);
     209                const type = isMap ? "map" : "source";
     210                // Per the standard, ETags must be quoted:
     211                // https://tools.ietf.org/html/rfc7232#section-2.3
     212                const expectedEtag = '"' + clientVersion + '"';
     213                const weakEtag = "W/" + expectedEtag;
     214                const etag = req.getHeader("if-none-match");
     215                if (etag) {
     216                    if (expectedEtag === etag || weakEtag === etag) {
     217                        debug("serve client %s 304", type);
     218                        res.writeStatus("304 Not Modified");
     219                        res.end();
     220                        return;
     221                    }
     222                }
     223                debug("serve client %s", type);
     224                res.writeHeader("cache-control", "public, max-age=0");
     225                res.writeHeader("content-type", "application/" + (isMap ? "json" : "javascript"));
     226                res.writeHeader("etag", expectedEtag);
     227                const filepath = path.join(__dirname, "../client-dist/", filename);
     228                (0, uws_js_1.serveFile)(res, filepath);
     229            });
     230        }
     231        (0, uws_js_1.patchAdapter)(app);
     232    }
    176233    /**
    177234     * Initialize engine
     
    184241        // initialize engine
    185242        debug("creating engine.io instance with opts %j", opts);
    186         this.eio = engine.attach(srv, opts);
     243        this.eio = (0, engine_io_1.attach)(srv, opts);
    187244        // attach static file serving
    188245        if (this._serveClient)
     
    222279     */
    223280    serve(req, res) {
    224         const filename = req.url.replace(this._path, "");
     281        const filename = req.url.replace(this._path, "").replace(/\?.*$/, "");
    225282        const isMap = dotMapRegex.test(filename);
    226283        const type = isMap ? "map" : "source";
     
    242299        res.setHeader("Content-Type", "application/" + (isMap ? "json" : "javascript"));
    243300        res.setHeader("ETag", expectedEtag);
    244         if (!isMap) {
    245             res.setHeader("X-SourceMap", filename.substring(1) + ".map");
    246         }
    247301        Server.sendFile(filename, req, res);
    248302    }
     
    254308     */
    255309    static sendFile(filename, req, res) {
    256         const readStream = fs_1.createReadStream(path.join(__dirname, "../client-dist/", filename));
     310        const readStream = (0, fs_1.createReadStream)(path.join(__dirname, "../client-dist/", filename));
    257311        const encoding = accepts(req).encodings(["br", "gzip", "deflate"]);
    258312        const onError = (err) => {
     
    264318            case "br":
    265319                res.writeHead(200, { "content-encoding": "br" });
    266                 readStream.pipe(zlib_1.createBrotliCompress()).pipe(res);
    267                 stream_1.pipeline(readStream, zlib_1.createBrotliCompress(), res, onError);
     320                readStream.pipe((0, zlib_1.createBrotliCompress)()).pipe(res);
     321                (0, stream_1.pipeline)(readStream, (0, zlib_1.createBrotliCompress)(), res, onError);
    268322                break;
    269323            case "gzip":
    270324                res.writeHead(200, { "content-encoding": "gzip" });
    271                 stream_1.pipeline(readStream, zlib_1.createGzip(), res, onError);
     325                (0, stream_1.pipeline)(readStream, (0, zlib_1.createGzip)(), res, onError);
    272326                break;
    273327            case "deflate":
    274328                res.writeHead(200, { "content-encoding": "deflate" });
    275                 stream_1.pipeline(readStream, zlib_1.createDeflate(), res, onError);
     329                (0, stream_1.pipeline)(readStream, (0, zlib_1.createDeflate)(), res, onError);
    276330                break;
    277331            default:
    278332                res.writeHead(200);
    279                 stream_1.pipeline(readStream, res, onError);
     333                (0, stream_1.pipeline)(readStream, res, onError);
    280334        }
    281335    }
     
    338392            nsp = new namespace_1.Namespace(this, name);
    339393            this._nsps.set(name, nsp);
     394            if (name !== "/") {
     395                // @ts-ignore
     396                this.sockets.emitReserved("new_namespace", nsp);
     397            }
    340398        }
    341399        if (fn)
     
    354412        }
    355413        this.engine.close();
     414        // restore the Adapter prototype
     415        (0, uws_js_1.restoreAdapter)();
    356416        if (this.httpServer) {
    357417            this.httpServer.close(fn);
     
    374434     * Targets a room when emitting.
    375435     *
     436     * @param room
     437     * @return self
     438     * @public
     439     */
     440    to(room) {
     441        return this.sockets.to(room);
     442    }
     443    /**
     444     * Targets a room when emitting.
     445     *
     446     * @param room
     447     * @return self
     448     * @public
     449     */
     450    in(room) {
     451        return this.sockets.in(room);
     452    }
     453    /**
     454     * Excludes a room when emitting.
     455     *
    376456     * @param name
    377457     * @return self
    378458     * @public
    379459     */
    380     to(name) {
    381         this.sockets.to(name);
    382         return this;
    383     }
    384     /**
    385      * Targets a room when emitting.
    386      *
    387      * @param name
    388      * @return self
    389      * @public
    390      */
    391     in(name) {
    392         this.sockets.in(name);
    393         return this;
     460    except(name) {
     461        return this.sockets.except(name);
    394462    }
    395463    /**
     
    414482    }
    415483    /**
     484     * Emit a packet to other Socket.IO servers
     485     *
     486     * @param ev - the event name
     487     * @param args - an array of arguments, which may include an acknowledgement callback at the end
     488     * @public
     489     */
     490    serverSideEmit(ev, ...args) {
     491        return this.sockets.serverSideEmit(ev, ...args);
     492    }
     493    /**
    416494     * Gets a list of socket ids.
    417495     *
     
    429507     */
    430508    compress(compress) {
    431         this.sockets.compress(compress);
    432         return this;
     509        return this.sockets.compress(compress);
    433510    }
    434511    /**
     
    441518     */
    442519    get volatile() {
    443         this.sockets.volatile;
    444         return this;
     520        return this.sockets.volatile;
    445521    }
    446522    /**
     
    451527     */
    452528    get local() {
    453         this.sockets.local;
    454         return this;
     529        return this.sockets.local;
     530    }
     531    /**
     532     * Returns the matching socket instances
     533     *
     534     * @public
     535     */
     536    fetchSockets() {
     537        return this.sockets.fetchSockets();
     538    }
     539    /**
     540     * Makes the matching socket instances join the specified rooms
     541     *
     542     * @param room
     543     * @public
     544     */
     545    socketsJoin(room) {
     546        return this.sockets.socketsJoin(room);
     547    }
     548    /**
     549     * Makes the matching socket instances leave the specified rooms
     550     *
     551     * @param room
     552     * @public
     553     */
     554    socketsLeave(room) {
     555        return this.sockets.socketsLeave(room);
     556    }
     557    /**
     558     * Makes the matching socket instances disconnect
     559     *
     560     * @param close - whether to close the underlying connection
     561     * @public
     562     */
     563    disconnectSockets(close = false) {
     564        return this.sockets.disconnectSockets(close);
    455565    }
    456566}
     
    469579module.exports = (srv, opts) => new Server(srv, opts);
    470580module.exports.Server = Server;
     581module.exports.Namespace = namespace_1.Namespace;
     582module.exports.Socket = socket_1.Socket;
  • trip-planner-front/node_modules/socket.io/dist/namespace.d.ts

    r59329aa re29cc2e  
    1 /// <reference types="node" />
    21import { Socket } from "./socket";
    32import type { Server } from "./index";
     3import { EventParams, EventNames, EventsMap, StrictEventEmitter, DefaultEventsMap } from "./typed-events";
    44import type { Client } from "./client";
    5 import { EventEmitter } from "events";
    65import type { Adapter, Room, SocketId } from "socket.io-adapter";
     6import { BroadcastOperator, RemoteSocket } from "./broadcast-operator";
    77export interface ExtendedError extends Error {
    88    data?: any;
    99}
    10 export declare class Namespace extends EventEmitter {
     10export interface NamespaceReservedEventsMap<ListenEvents extends EventsMap, EmitEvents extends EventsMap, ServerSideEvents extends EventsMap, SocketData> {
     11    connect: (socket: Socket<ListenEvents, EmitEvents, ServerSideEvents, SocketData>) => void;
     12    connection: (socket: Socket<ListenEvents, EmitEvents, ServerSideEvents, SocketData>) => void;
     13}
     14export interface ServerReservedEventsMap<ListenEvents, EmitEvents, ServerSideEvents, SocketData> extends NamespaceReservedEventsMap<ListenEvents, EmitEvents, ServerSideEvents, SocketData> {
     15    new_namespace: (namespace: Namespace<ListenEvents, EmitEvents, ServerSideEvents, SocketData>) => void;
     16}
     17export declare const RESERVED_EVENTS: ReadonlySet<string | Symbol>;
     18export declare class Namespace<ListenEvents extends EventsMap = DefaultEventsMap, EmitEvents extends EventsMap = ListenEvents, ServerSideEvents extends EventsMap = DefaultEventsMap, SocketData = any> extends StrictEventEmitter<ServerSideEvents, EmitEvents, NamespaceReservedEventsMap<ListenEvents, EmitEvents, ServerSideEvents, SocketData>> {
    1119    readonly name: string;
    12     readonly sockets: Map<SocketId, Socket>;
     20    readonly sockets: Map<SocketId, Socket<ListenEvents, EmitEvents, ServerSideEvents, SocketData>>;
    1321    adapter: Adapter;
    1422    /** @private */
    15     readonly server: Server;
     23    readonly server: Server<ListenEvents, EmitEvents, ServerSideEvents, SocketData>;
    1624    /** @private */
    17     _fns: Array<(socket: Socket, next: (err?: ExtendedError) => void) => void>;
    18     /** @private */
    19     _rooms: Set<Room>;
    20     /** @private */
    21     _flags: any;
     25    _fns: Array<(socket: Socket<ListenEvents, EmitEvents, ServerSideEvents, SocketData>, next: (err?: ExtendedError) => void) => void>;
    2226    /** @private */
    2327    _ids: number;
     
    2832     * @param name
    2933     */
    30     constructor(server: Server, name: string);
     34    constructor(server: Server<ListenEvents, EmitEvents, ServerSideEvents, SocketData>, name: string);
    3135    /**
    3236     * Initializes the `Adapter` for this nsp.
     
    4347     * @public
    4448     */
    45     use(fn: (socket: Socket, next: (err?: ExtendedError) => void) => void): this;
     49    use(fn: (socket: Socket<ListenEvents, EmitEvents, ServerSideEvents, SocketData>, next: (err?: ExtendedError) => void) => void): this;
    4650    /**
    4751     * Executes the middleware for an incoming client.
     
    5559     * Targets a room when emitting.
    5660     *
    57      * @param name
     61     * @param room
    5862     * @return self
    5963     * @public
    6064     */
    61     to(name: Room): this;
     65    to(room: Room | Room[]): BroadcastOperator<EmitEvents>;
    6266    /**
    6367     * Targets a room when emitting.
    6468     *
    65      * @param name
     69     * @param room
    6670     * @return self
    6771     * @public
    6872     */
    69     in(name: Room): this;
     73    in(room: Room | Room[]): BroadcastOperator<EmitEvents>;
     74    /**
     75     * Excludes a room when emitting.
     76     *
     77     * @param room
     78     * @return self
     79     * @public
     80     */
     81    except(room: Room | Room[]): BroadcastOperator<EmitEvents>;
    7082    /**
    7183     * Adds a new client.
     
    7486     * @private
    7587     */
    76     _add(client: Client, query: any, fn?: () => void): Socket;
     88    _add(client: Client<ListenEvents, EmitEvents, ServerSideEvents>, query: any, fn?: () => void): Socket<ListenEvents, EmitEvents, ServerSideEvents, SocketData>;
    7789    /**
    7890     * Removes a client. Called by each `Socket`.
     
    8092     * @private
    8193     */
    82     _remove(socket: Socket): void;
     94    _remove(socket: Socket<ListenEvents, EmitEvents, ServerSideEvents, SocketData>): void;
    8395    /**
    8496     * Emits to all clients.
     
    8799     * @public
    88100     */
    89     emit(ev: string | Symbol, ...args: any[]): true;
     101    emit<Ev extends EventNames<EmitEvents>>(ev: Ev, ...args: EventParams<EmitEvents, Ev>): boolean;
    90102    /**
    91103     * Sends a `message` event to all clients.
     
    94106     * @public
    95107     */
    96     send(...args: readonly any[]): this;
     108    send(...args: EventParams<EmitEvents, "message">): this;
    97109    /**
    98110     * Sends a `message` event to all clients.
     
    101113     * @public
    102114     */
    103     write(...args: readonly any[]): this;
     115    write(...args: EventParams<EmitEvents, "message">): this;
     116    /**
     117     * Emit a packet to other Socket.IO servers
     118     *
     119     * @param ev - the event name
     120     * @param args - an array of arguments, which may include an acknowledgement callback at the end
     121     * @public
     122     */
     123    serverSideEmit<Ev extends EventNames<ServerSideEvents>>(ev: Ev, ...args: EventParams<ServerSideEvents, Ev>): boolean;
     124    /**
     125     * Called when a packet is received from another Socket.IO server
     126     *
     127     * @param args - an array of arguments, which may include an acknowledgement callback at the end
     128     *
     129     * @private
     130     */
     131    _onServerSideEmit(args: [string, ...any[]]): void;
    104132    /**
    105133     * Gets a list of clients.
     
    116144     * @public
    117145     */
    118     compress(compress: boolean): this;
     146    compress(compress: boolean): BroadcastOperator<EmitEvents>;
    119147    /**
    120148     * Sets a modifier for a subsequent event emission that the event data may be lost if the client is not ready to
     
    125153     * @public
    126154     */
    127     get volatile(): this;
     155    get volatile(): BroadcastOperator<EmitEvents>;
    128156    /**
    129157     * Sets a modifier for a subsequent event emission that the event data will only be broadcast to the current node.
     
    132160     * @public
    133161     */
    134     get local(): this;
     162    get local(): BroadcastOperator<EmitEvents>;
     163    /**
     164     * Returns the matching socket instances
     165     *
     166     * @public
     167     */
     168    fetchSockets(): Promise<RemoteSocket<EmitEvents>[]>;
     169    /**
     170     * Makes the matching socket instances join the specified rooms
     171     *
     172     * @param room
     173     * @public
     174     */
     175    socketsJoin(room: Room | Room[]): void;
     176    /**
     177     * Makes the matching socket instances leave the specified rooms
     178     *
     179     * @param room
     180     * @public
     181     */
     182    socketsLeave(room: Room | Room[]): void;
     183    /**
     184     * Makes the matching socket instances disconnect
     185     *
     186     * @param close - whether to close the underlying connection
     187     * @public
     188     */
     189    disconnectSockets(close?: boolean): void;
    135190}
  • trip-planner-front/node_modules/socket.io/dist/namespace.js

    r59329aa re29cc2e  
    44};
    55Object.defineProperty(exports, "__esModule", { value: true });
    6 exports.Namespace = void 0;
     6exports.Namespace = exports.RESERVED_EVENTS = void 0;
    77const socket_1 = require("./socket");
    8 const events_1 = require("events");
    9 const socket_io_parser_1 = require("socket.io-parser");
     8const typed_events_1 = require("./typed-events");
    109const debug_1 = __importDefault(require("debug"));
    11 const debug = debug_1.default("socket.io:namespace");
    12 class Namespace extends events_1.EventEmitter {
     10const broadcast_operator_1 = require("./broadcast-operator");
     11const debug = (0, debug_1.default)("socket.io:namespace");
     12exports.RESERVED_EVENTS = new Set(["connect", "connection", "new_namespace"]);
     13class Namespace extends typed_events_1.StrictEventEmitter {
    1314    /**
    1415     * Namespace constructor.
     
    2324        this._fns = [];
    2425        /** @private */
    25         this._rooms = new Set();
    26         /** @private */
    27         this._flags = {};
    28         /** @private */
    2926        this._ids = 0;
    3027        this.server = server;
     
    4037     */
    4138    _initAdapter() {
     39        // @ts-ignore
    4240        this.adapter = new (this.server.adapter())(this);
    4341    }
     
    8078     * Targets a room when emitting.
    8179     *
    82      * @param name
    83      * @return self
    84      * @public
    85      */
    86     to(name) {
    87         this._rooms.add(name);
    88         return this;
     80     * @param room
     81     * @return self
     82     * @public
     83     */
     84    to(room) {
     85        return new broadcast_operator_1.BroadcastOperator(this.adapter).to(room);
    8986    }
    9087    /**
    9188     * Targets a room when emitting.
    9289     *
    93      * @param name
    94      * @return self
    95      * @public
    96      */
    97     in(name) {
    98         this._rooms.add(name);
    99         return this;
     90     * @param room
     91     * @return self
     92     * @public
     93     */
     94    in(room) {
     95        return new broadcast_operator_1.BroadcastOperator(this.adapter).in(room);
     96    }
     97    /**
     98     * Excludes a room when emitting.
     99     *
     100     * @param room
     101     * @return self
     102     * @public
     103     */
     104    except(room) {
     105        return new broadcast_operator_1.BroadcastOperator(this.adapter).except(room);
    100106    }
    101107    /**
     
    132138                        fn();
    133139                    // fire user-set events
    134                     super.emit("connect", socket);
    135                     super.emit("connection", socket);
     140                    this.emitReserved("connect", socket);
     141                    this.emitReserved("connection", socket);
    136142                }
    137143                else {
     
    162168     */
    163169    emit(ev, ...args) {
    164         if (socket_1.RESERVED_EVENTS.has(ev)) {
    165             throw new Error(`"${ev}" is a reserved event name`);
    166         }
    167         // set up packet object
    168         args.unshift(ev);
    169         const packet = {
    170             type: socket_io_parser_1.PacketType.EVENT,
    171             data: args,
    172         };
    173         if ("function" == typeof args[args.length - 1]) {
    174             throw new Error("Callbacks are not supported when broadcasting");
    175         }
    176         const rooms = new Set(this._rooms);
    177         const flags = Object.assign({}, this._flags);
    178         // reset flags
    179         this._rooms.clear();
    180         this._flags = {};
    181         this.adapter.broadcast(packet, {
    182             rooms: rooms,
    183             flags: flags,
    184         });
    185         return true;
     170        return new broadcast_operator_1.BroadcastOperator(this.adapter).emit(ev, ...args);
    186171    }
    187172    /**
     
    206191    }
    207192    /**
     193     * Emit a packet to other Socket.IO servers
     194     *
     195     * @param ev - the event name
     196     * @param args - an array of arguments, which may include an acknowledgement callback at the end
     197     * @public
     198     */
     199    serverSideEmit(ev, ...args) {
     200        if (exports.RESERVED_EVENTS.has(ev)) {
     201            throw new Error(`"${ev}" is a reserved event name`);
     202        }
     203        args.unshift(ev);
     204        this.adapter.serverSideEmit(args);
     205        return true;
     206    }
     207    /**
     208     * Called when a packet is received from another Socket.IO server
     209     *
     210     * @param args - an array of arguments, which may include an acknowledgement callback at the end
     211     *
     212     * @private
     213     */
     214    _onServerSideEmit(args) {
     215        super.emitUntyped.apply(this, args);
     216    }
     217    /**
    208218     * Gets a list of clients.
    209219     *
     
    212222     */
    213223    allSockets() {
    214         if (!this.adapter) {
    215             throw new Error("No adapter for this namespace, are you trying to get the list of clients of a dynamic namespace?");
    216         }
    217         const rooms = new Set(this._rooms);
    218         this._rooms.clear();
    219         return this.adapter.sockets(rooms);
     224        return new broadcast_operator_1.BroadcastOperator(this.adapter).allSockets();
    220225    }
    221226    /**
     
    227232     */
    228233    compress(compress) {
    229         this._flags.compress = compress;
    230         return this;
     234        return new broadcast_operator_1.BroadcastOperator(this.adapter).compress(compress);
    231235    }
    232236    /**
     
    239243     */
    240244    get volatile() {
    241         this._flags.volatile = true;
    242         return this;
     245        return new broadcast_operator_1.BroadcastOperator(this.adapter).volatile;
    243246    }
    244247    /**
     
    249252     */
    250253    get local() {
    251         this._flags.local = true;
    252         return this;
     254        return new broadcast_operator_1.BroadcastOperator(this.adapter).local;
     255    }
     256    /**
     257     * Returns the matching socket instances
     258     *
     259     * @public
     260     */
     261    fetchSockets() {
     262        return new broadcast_operator_1.BroadcastOperator(this.adapter).fetchSockets();
     263    }
     264    /**
     265     * Makes the matching socket instances join the specified rooms
     266     *
     267     * @param room
     268     * @public
     269     */
     270    socketsJoin(room) {
     271        return new broadcast_operator_1.BroadcastOperator(this.adapter).socketsJoin(room);
     272    }
     273    /**
     274     * Makes the matching socket instances leave the specified rooms
     275     *
     276     * @param room
     277     * @public
     278     */
     279    socketsLeave(room) {
     280        return new broadcast_operator_1.BroadcastOperator(this.adapter).socketsLeave(room);
     281    }
     282    /**
     283     * Makes the matching socket instances disconnect
     284     *
     285     * @param close - whether to close the underlying connection
     286     * @public
     287     */
     288    disconnectSockets(close = false) {
     289        return new broadcast_operator_1.BroadcastOperator(this.adapter).disconnectSockets(close);
    253290    }
    254291}
  • trip-planner-front/node_modules/socket.io/dist/parent-namespace.d.ts

    r59329aa re29cc2e  
    11import { Namespace } from "./namespace";
    22import type { Server } from "./index";
    3 export declare class ParentNamespace extends Namespace {
     3import type { EventParams, EventNames, EventsMap, DefaultEventsMap } from "./typed-events";
     4export declare class ParentNamespace<ListenEvents extends EventsMap = DefaultEventsMap, EmitEvents extends EventsMap = ListenEvents, ServerSideEvents extends EventsMap = DefaultEventsMap, SocketData = any> extends Namespace<ListenEvents, EmitEvents, ServerSideEvents, SocketData> {
    45    private static count;
    56    private children;
    6     constructor(server: Server);
     7    constructor(server: Server<ListenEvents, EmitEvents, ServerSideEvents, SocketData>);
    78    /**
    89     * @private
    910     */
    1011    _initAdapter(): void;
    11     emit(ev: string | Symbol, ...args: [...any]): true;
    12     createChild(name: string): Namespace;
     12    emit<Ev extends EventNames<EmitEvents>>(ev: Ev, ...args: EventParams<EmitEvents, Ev>): boolean;
     13    createChild(name: string): Namespace<ListenEvents, EmitEvents, ServerSideEvents, SocketData>;
    1314}
  • trip-planner-front/node_modules/socket.io/dist/parent-namespace.js

    r59329aa re29cc2e  
    1212     */
    1313    _initAdapter() {
    14         /* no-op */
     14        const broadcast = (packet, opts) => {
     15            this.children.forEach((nsp) => {
     16                nsp.adapter.broadcast(packet, opts);
     17            });
     18        };
     19        // @ts-ignore FIXME is there a way to declare an inner class in TypeScript?
     20        this.adapter = { broadcast };
    1521    }
    1622    emit(ev, ...args) {
    1723        this.children.forEach((nsp) => {
    18             nsp._rooms = this._rooms;
    19             nsp._flags = this._flags;
    2024            nsp.emit(ev, ...args);
    2125        });
    22         this._rooms.clear();
    23         this._flags = {};
    2426        return true;
    2527    }
  • trip-planner-front/node_modules/socket.io/dist/socket.d.ts

    r59329aa re29cc2e  
    11/// <reference types="node" />
    2 import { EventEmitter } from "events";
    32import { Packet } from "socket.io-parser";
     3import { EventParams, EventNames, EventsMap, StrictEventEmitter, DefaultEventsMap } from "./typed-events";
    44import type { Client } from "./client";
    55import type { Namespace } from "./namespace";
     
    77import type { Room, SocketId } from "socket.io-adapter";
    88import type { ParsedUrlQuery } from "querystring";
     9import { BroadcastOperator } from "./broadcast-operator";
     10export interface SocketReservedEventsMap {
     11    disconnect: (reason: string) => void;
     12    disconnecting: (reason: string) => void;
     13    error: (err: Error) => void;
     14}
     15export interface EventEmitterReservedEventsMap {
     16    newListener: (eventName: string | Symbol, listener: (...args: any[]) => void) => void;
     17    removeListener: (eventName: string | Symbol, listener: (...args: any[]) => void) => void;
     18}
    919export declare const RESERVED_EVENTS: ReadonlySet<string | Symbol>;
    1020/**
     
    5161    };
    5262}
    53 export declare class Socket extends EventEmitter {
    54     readonly nsp: Namespace;
    55     readonly client: Client;
     63declare type Event = [eventName: string, ...args: any[]];
     64export declare class Socket<ListenEvents extends EventsMap = DefaultEventsMap, EmitEvents extends EventsMap = ListenEvents, ServerSideEvents extends EventsMap = DefaultEventsMap, SocketData = any> extends StrictEventEmitter<ListenEvents, EmitEvents, SocketReservedEventsMap> {
     65    readonly nsp: Namespace<ListenEvents, EmitEvents, ServerSideEvents>;
     66    readonly client: Client<ListenEvents, EmitEvents, ServerSideEvents>;
    5667    readonly id: SocketId;
    5768    readonly handshake: Handshake;
     69    /**
     70     * Additional information that can be attached to the Socket instance and which will be used in the fetchSockets method
     71     */
     72    data: Partial<SocketData>;
    5873    connected: boolean;
    59     disconnected: boolean;
    6074    private readonly server;
    6175    private readonly adapter;
     
    6377    private fns;
    6478    private flags;
    65     private _rooms;
    6679    private _anyListeners?;
    6780    /**
     
    7386     * @package
    7487     */
    75     constructor(nsp: Namespace, client: Client, auth: object);
     88    constructor(nsp: Namespace<ListenEvents, EmitEvents, ServerSideEvents>, client: Client<ListenEvents, EmitEvents, ServerSideEvents>, auth: object);
    7689    /**
    7790     * Builds the `handshake` BC object
     
    8699     * @public
    87100     */
    88     emit(ev: string, ...args: any[]): boolean;
     101    emit<Ev extends EventNames<EmitEvents>>(ev: Ev, ...args: EventParams<EmitEvents, Ev>): boolean;
     102    /**
     103     * @private
     104     */
     105    private registerAckCallback;
    89106    /**
    90107     * Targets a room when broadcasting.
    91108     *
    92      * @param name
    93      * @return self
    94      * @public
    95      */
    96     to(name: Room): this;
     109     * @param room
     110     * @return self
     111     * @public
     112     */
     113    to(room: Room | Room[]): BroadcastOperator<EmitEvents>;
    97114    /**
    98115     * Targets a room when broadcasting.
    99116     *
    100      * @param name
    101      * @return self
    102      * @public
    103      */
    104     in(name: Room): this;
     117     * @param room
     118     * @return self
     119     * @public
     120     */
     121    in(room: Room | Room[]): BroadcastOperator<EmitEvents>;
     122    /**
     123     * Excludes a room when broadcasting.
     124     *
     125     * @param room
     126     * @return self
     127     * @public
     128     */
     129    except(room: Room | Room[]): BroadcastOperator<EmitEvents>;
    105130    /**
    106131     * Sends a `message` event.
     
    109134     * @public
    110135     */
    111     send(...args: readonly any[]): this;
     136    send(...args: EventParams<EmitEvents, "message">): this;
    112137    /**
    113138     * Sends a `message` event.
     
    116141     * @public
    117142     */
    118     write(...args: readonly any[]): this;
     143    write(...args: EventParams<EmitEvents, "message">): this;
    119144    /**
    120145     * Writes a packet.
     
    194219     * @private
    195220     */
    196     _onerror(err: any): void;
     221    _onerror(err: Error): void;
    197222    /**
    198223     * Called upon closing. Called by `Client`.
     
    245270     * @public
    246271     */
    247     get broadcast(): this;
     272    get broadcast(): BroadcastOperator<EmitEvents>;
    248273    /**
    249274     * Sets a modifier for a subsequent event emission that the event data will only be broadcast to the current node.
     
    252277     * @public
    253278     */
    254     get local(): this;
     279    get local(): BroadcastOperator<EmitEvents>;
     280    /**
     281     * Sets a modifier for a subsequent event emission that the callback will be called with an error when the
     282     * given number of milliseconds have elapsed without an acknowledgement from the client:
     283     *
     284     * ```
     285     * socket.timeout(5000).emit("my-event", (err) => {
     286     *   if (err) {
     287     *     // the client did not acknowledge the event in the given delay
     288     *   }
     289     * });
     290     * ```
     291     *
     292     * @returns self
     293     * @public
     294     */
     295    timeout(timeout: number): this;
    255296    /**
    256297     * Dispatch incoming event to socket listeners.
     
    267308     * @public
    268309     */
    269     use(fn: (event: Array<any>, next: (err: Error) => void) => void): this;
     310    use(fn: (event: Event, next: (err?: Error) => void) => void): this;
    270311    /**
    271312     * Executes the middleware for an incoming event.
     
    277318    private run;
    278319    /**
     320     * Whether the socket is currently disconnected
     321     */
     322    get disconnected(): boolean;
     323    /**
    279324     * A reference to the request that originated the underlying Engine.IO Socket.
    280325     *
     
    287332     * @public
    288333     */
    289     get conn(): any;
     334    get conn(): import("engine.io").Socket;
    290335    /**
    291336     * @public
     
    322367     */
    323368    listenersAny(): ((...args: any[]) => void)[];
     369    private newBroadcastOperator;
    324370}
     371export {};
  • trip-planner-front/node_modules/socket.io/dist/socket.js

    r59329aa re29cc2e  
    55Object.defineProperty(exports, "__esModule", { value: true });
    66exports.Socket = exports.RESERVED_EVENTS = void 0;
    7 const events_1 = require("events");
    87const socket_io_parser_1 = require("socket.io-parser");
    9 const url = require("url");
    108const debug_1 = __importDefault(require("debug"));
     9const typed_events_1 = require("./typed-events");
    1110const base64id_1 = __importDefault(require("base64id"));
    12 const debug = debug_1.default("socket.io:socket");
     11const broadcast_operator_1 = require("./broadcast-operator");
     12const debug = (0, debug_1.default)("socket.io:socket");
    1313exports.RESERVED_EVENTS = new Set([
    1414    "connect",
     
    1616    "disconnect",
    1717    "disconnecting",
    18     // EventEmitter reserved events: https://nodejs.org/api/events.html#events_event_newlistener
    1918    "newListener",
    2019    "removeListener",
    2120]);
    22 class Socket extends events_1.EventEmitter {
     21class Socket extends typed_events_1.StrictEventEmitter {
    2322    /**
    2423     * Interface to a `Client` for a given `Namespace`.
     
    3332        this.nsp = nsp;
    3433        this.client = client;
     34        /**
     35         * Additional information that can be attached to the Socket instance and which will be used in the fetchSockets method
     36         */
     37        this.data = {};
     38        this.connected = false;
    3539        this.acks = new Map();
    3640        this.fns = [];
    3741        this.flags = {};
    38         this._rooms = new Set();
    3942        this.server = nsp.server;
    4043        this.adapter = this.nsp.adapter;
     
    4649            this.id = base64id_1.default.generateId(); // don't reuse the Engine.IO id because it's sensitive information
    4750        }
    48         this.connected = true;
    49         this.disconnected = false;
    5051        this.handshake = this.buildHandshake(auth);
    5152    }
     
    6566            issued: +new Date(),
    6667            url: this.request.url,
    67             query: url.parse(this.request.url, true).query,
     68            // @ts-ignore
     69            query: this.request._query,
    6870            auth,
    6971        };
     
    7981            throw new Error(`"${ev}" is a reserved event name`);
    8082        }
    81         args.unshift(ev);
     83        const data = [ev, ...args];
    8284        const packet = {
    8385            type: socket_io_parser_1.PacketType.EVENT,
    84             data: args,
     86            data: data,
    8587        };
    8688        // access last argument to see if it's an ACK callback
    87         if (typeof args[args.length - 1] === "function") {
    88             if (this._rooms.size || this.flags.broadcast) {
    89                 throw new Error("Callbacks are not supported when broadcasting");
    90             }
    91             debug("emitting packet with ack id %d", this.nsp._ids);
    92             this.acks.set(this.nsp._ids, args.pop());
    93             packet.id = this.nsp._ids++;
    94         }
    95         const rooms = new Set(this._rooms);
     89        if (typeof data[data.length - 1] === "function") {
     90            const id = this.nsp._ids++;
     91            debug("emitting packet with ack id %d", id);
     92            this.registerAckCallback(id, data.pop());
     93            packet.id = id;
     94        }
    9695        const flags = Object.assign({}, this.flags);
    97         // reset flags
    98         this._rooms.clear();
    9996        this.flags = {};
    100         if (rooms.size || flags.broadcast) {
    101             this.adapter.broadcast(packet, {
    102                 except: new Set([this.id]),
    103                 rooms: rooms,
    104                 flags: flags,
    105             });
    106         }
    107         else {
    108             // dispatch packet
    109             this.packet(packet, flags);
    110         }
     97        this.packet(packet, flags);
    11198        return true;
    11299    }
    113100    /**
     101     * @private
     102     */
     103    registerAckCallback(id, ack) {
     104        const timeout = this.flags.timeout;
     105        if (timeout === undefined) {
     106            this.acks.set(id, ack);
     107            return;
     108        }
     109        const timer = setTimeout(() => {
     110            debug("event with ack id %d has timed out after %d ms", id, timeout);
     111            this.acks.delete(id);
     112            ack.call(this, new Error("operation has timed out"));
     113        }, timeout);
     114        this.acks.set(id, (...args) => {
     115            clearTimeout(timer);
     116            ack.apply(this, [null, ...args]);
     117        });
     118    }
     119    /**
    114120     * Targets a room when broadcasting.
    115121     *
    116      * @param name
     122     * @param room
    117123     * @return self
    118124     * @public
    119125     */
    120     to(name) {
    121         this._rooms.add(name);
    122         return this;
     126    to(room) {
     127        return this.newBroadcastOperator().to(room);
    123128    }
    124129    /**
    125130     * Targets a room when broadcasting.
    126131     *
    127      * @param name
     132     * @param room
    128133     * @return self
    129134     * @public
    130135     */
    131     in(name) {
    132         this._rooms.add(name);
    133         return this;
     136    in(room) {
     137        return this.newBroadcastOperator().in(room);
     138    }
     139    /**
     140     * Excludes a room when broadcasting.
     141     *
     142     * @param room
     143     * @return self
     144     * @public
     145     */
     146    except(room) {
     147        return this.newBroadcastOperator().except(room);
    134148    }
    135149    /**
     
    205219    _onconnect() {
    206220        debug("socket connected - writing packet");
     221        this.connected = true;
    207222        this.join(this.id);
    208223        if (this.conn.protocol === 3) {
     
    317332    _onerror(err) {
    318333        if (this.listeners("error").length) {
    319             super.emit("error", err);
     334            this.emitReserved("error", err);
    320335        }
    321336        else {
     
    336351            return this;
    337352        debug("closing socket - reason %s", reason);
    338         super.emit("disconnecting", reason);
     353        this.emitReserved("disconnecting", reason);
    339354        this.leaveAll();
    340355        this.nsp._remove(this);
    341356        this.client._remove(this);
    342357        this.connected = false;
    343         this.disconnected = true;
    344         super.emit("disconnect", reason);
     358        this.emitReserved("disconnect", reason);
    345359        return;
    346360    }
     
    406420     */
    407421    get broadcast() {
    408         this.flags.broadcast = true;
    409         return this;
     422        return this.newBroadcastOperator();
    410423    }
    411424    /**
     
    416429     */
    417430    get local() {
    418         this.flags.local = true;
     431        return this.newBroadcastOperator().local;
     432    }
     433    /**
     434     * Sets a modifier for a subsequent event emission that the callback will be called with an error when the
     435     * given number of milliseconds have elapsed without an acknowledgement from the client:
     436     *
     437     * ```
     438     * socket.timeout(5000).emit("my-event", (err) => {
     439     *   if (err) {
     440     *     // the client did not acknowledge the event in the given delay
     441     *   }
     442     * });
     443     * ```
     444     *
     445     * @returns self
     446     * @public
     447     */
     448    timeout(timeout) {
     449        this.flags.timeout = timeout;
    419450        return this;
    420451    }
     
    433464                }
    434465                if (this.connected) {
    435                     super.emit.apply(this, event);
     466                    super.emitUntyped.apply(this, event);
    436467                }
    437468                else {
     
    478509    }
    479510    /**
     511     * Whether the socket is currently disconnected
     512     */
     513    get disconnected() {
     514        return !this.connected;
     515    }
     516    /**
    480517     * A reference to the request that originated the underlying Engine.IO Socket.
    481518     *
     
    556593        return this._anyListeners || [];
    557594    }
     595    newBroadcastOperator() {
     596        const flags = Object.assign({}, this.flags);
     597        this.flags = {};
     598        return new broadcast_operator_1.BroadcastOperator(this.adapter, new Set(), new Set([this.id]), flags);
     599    }
    558600}
    559601exports.Socket = Socket;
Note: See TracChangeset for help on using the changeset viewer.