mirror of
https://github.com/litruv/API-WebSocket-Bridge.git
synced 2026-07-25 03:06:03 +10:00
first commit
This commit is contained in:
124
node_modules/engine.io-client/build/cjs/transport.js
generated
vendored
Normal file
124
node_modules/engine.io-client/build/cjs/transport.js
generated
vendored
Normal file
@@ -0,0 +1,124 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Transport = void 0;
|
||||
const engine_io_parser_1 = require("engine.io-parser");
|
||||
const component_emitter_1 = require("@socket.io/component-emitter");
|
||||
const util_js_1 = require("./util.js");
|
||||
const debug_1 = __importDefault(require("debug")); // debug()
|
||||
const debug = (0, debug_1.default)("engine.io-client:transport"); // debug()
|
||||
class TransportError extends Error {
|
||||
constructor(reason, description, context) {
|
||||
super(reason);
|
||||
this.description = description;
|
||||
this.context = context;
|
||||
this.type = "TransportError";
|
||||
}
|
||||
}
|
||||
class Transport extends component_emitter_1.Emitter {
|
||||
/**
|
||||
* Transport abstract constructor.
|
||||
*
|
||||
* @param {Object} opts - options
|
||||
* @protected
|
||||
*/
|
||||
constructor(opts) {
|
||||
super();
|
||||
this.writable = false;
|
||||
(0, util_js_1.installTimerFunctions)(this, opts);
|
||||
this.opts = opts;
|
||||
this.query = opts.query;
|
||||
this.socket = opts.socket;
|
||||
}
|
||||
/**
|
||||
* Emits an error.
|
||||
*
|
||||
* @param {String} reason
|
||||
* @param description
|
||||
* @param context - the error context
|
||||
* @return {Transport} for chaining
|
||||
* @protected
|
||||
*/
|
||||
onError(reason, description, context) {
|
||||
super.emitReserved("error", new TransportError(reason, description, context));
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Opens the transport.
|
||||
*/
|
||||
open() {
|
||||
this.readyState = "opening";
|
||||
this.doOpen();
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Closes the transport.
|
||||
*/
|
||||
close() {
|
||||
if (this.readyState === "opening" || this.readyState === "open") {
|
||||
this.doClose();
|
||||
this.onClose();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Sends multiple packets.
|
||||
*
|
||||
* @param {Array} packets
|
||||
*/
|
||||
send(packets) {
|
||||
if (this.readyState === "open") {
|
||||
this.write(packets);
|
||||
}
|
||||
else {
|
||||
// this might happen if the transport was silently closed in the beforeunload event handler
|
||||
debug("transport is not open, discarding packets");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Called upon open
|
||||
*
|
||||
* @protected
|
||||
*/
|
||||
onOpen() {
|
||||
this.readyState = "open";
|
||||
this.writable = true;
|
||||
super.emitReserved("open");
|
||||
}
|
||||
/**
|
||||
* Called with data.
|
||||
*
|
||||
* @param {String} data
|
||||
* @protected
|
||||
*/
|
||||
onData(data) {
|
||||
const packet = (0, engine_io_parser_1.decodePacket)(data, this.socket.binaryType);
|
||||
this.onPacket(packet);
|
||||
}
|
||||
/**
|
||||
* Called with a decoded packet.
|
||||
*
|
||||
* @protected
|
||||
*/
|
||||
onPacket(packet) {
|
||||
super.emitReserved("packet", packet);
|
||||
}
|
||||
/**
|
||||
* Called upon close.
|
||||
*
|
||||
* @protected
|
||||
*/
|
||||
onClose(details) {
|
||||
this.readyState = "closed";
|
||||
super.emitReserved("close", details);
|
||||
}
|
||||
/**
|
||||
* Pauses the transport, in order not to lose packets during an upgrade.
|
||||
*
|
||||
* @param onPause
|
||||
*/
|
||||
pause(onPause) { }
|
||||
}
|
||||
exports.Transport = Transport;
|
||||
Reference in New Issue
Block a user