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

primeNG components

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.