source: trip-planner-front/node_modules/engine.io/build/transport.js@ 84d0fbb

Last change on this file since 84d0fbb was e29cc2e, checked in by Ema <ema_spirova@…>, 3 years ago

primeNG components

  • Property mode set to 100644
File size: 2.7 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.Transport = void 0;
4const events_1 = require("events");
5const parser_v4 = require("engine.io-parser");
6const parser_v3 = require("./parser-v3/index");
7const debug_1 = require("debug");
8const debug = (0, debug_1.default)("engine:transport");
9/**
10 * Noop function.
11 *
12 * @api private
13 */
14function noop() { }
15class Transport extends events_1.EventEmitter {
16 /**
17 * Transport constructor.
18 *
19 * @param {http.IncomingMessage} request
20 * @api public
21 */
22 constructor(req) {
23 super();
24 this.readyState = "open";
25 this.discarded = false;
26 this.protocol = req._query.EIO === "4" ? 4 : 3; // 3rd revision by default
27 this.parser = this.protocol === 4 ? parser_v4 : parser_v3;
28 }
29 get readyState() {
30 return this._readyState;
31 }
32 set readyState(state) {
33 debug("readyState updated from %s to %s (%s)", this._readyState, state, this.name);
34 this._readyState = state;
35 }
36 /**
37 * Flags the transport as discarded.
38 *
39 * @api private
40 */
41 discard() {
42 this.discarded = true;
43 }
44 /**
45 * Called with an incoming HTTP request.
46 *
47 * @param {http.IncomingMessage} request
48 * @api protected
49 */
50 onRequest(req) {
51 debug("setting request");
52 this.req = req;
53 }
54 /**
55 * Closes the transport.
56 *
57 * @api private
58 */
59 close(fn) {
60 if ("closed" === this.readyState || "closing" === this.readyState)
61 return;
62 this.readyState = "closing";
63 this.doClose(fn || noop);
64 }
65 /**
66 * Called with a transport error.
67 *
68 * @param {String} message error
69 * @param {Object} error description
70 * @api protected
71 */
72 onError(msg, desc) {
73 if (this.listeners("error").length) {
74 const err = new Error(msg);
75 // @ts-ignore
76 err.type = "TransportError";
77 // @ts-ignore
78 err.description = desc;
79 this.emit("error", err);
80 }
81 else {
82 debug("ignored transport error %s (%s)", msg, desc);
83 }
84 }
85 /**
86 * Called with parsed out a packets from the data stream.
87 *
88 * @param {Object} packet
89 * @api protected
90 */
91 onPacket(packet) {
92 this.emit("packet", packet);
93 }
94 /**
95 * Called with the encoded packet data.
96 *
97 * @param {String} data
98 * @api protected
99 */
100 onData(data) {
101 this.onPacket(this.parser.decodePacket(data));
102 }
103 /**
104 * Called upon transport close.
105 *
106 * @api protected
107 */
108 onClose() {
109 this.readyState = "closed";
110 this.emit("close");
111 }
112}
113exports.Transport = Transport;
Note: See TracBrowser for help on using the repository browser.