mirror of
https://github.com/litruv/API-WebSocket-Bridge.git
synced 2026-07-24 18:56:02 +10:00
first commit
This commit is contained in:
6
node_modules/engine.io-client/build/esm-debug/transports/index.d.ts
generated
vendored
Normal file
6
node_modules/engine.io-client/build/esm-debug/transports/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
import { Polling } from "./polling.js";
|
||||
import { WS } from "./websocket.js";
|
||||
export declare const transports: {
|
||||
websocket: typeof WS;
|
||||
polling: typeof Polling;
|
||||
};
|
||||
6
node_modules/engine.io-client/build/esm-debug/transports/index.js
generated
vendored
Normal file
6
node_modules/engine.io-client/build/esm-debug/transports/index.js
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
import { Polling } from "./polling.js";
|
||||
import { WS } from "./websocket.js";
|
||||
export const transports = {
|
||||
websocket: WS,
|
||||
polling: Polling,
|
||||
};
|
||||
138
node_modules/engine.io-client/build/esm-debug/transports/polling.d.ts
generated
vendored
Normal file
138
node_modules/engine.io-client/build/esm-debug/transports/polling.d.ts
generated
vendored
Normal file
@@ -0,0 +1,138 @@
|
||||
import { Transport } from "../transport.js";
|
||||
import { RawData } from "engine.io-parser";
|
||||
import { Emitter } from "@socket.io/component-emitter";
|
||||
export declare class Polling extends Transport {
|
||||
private readonly xd;
|
||||
private readonly xs;
|
||||
private polling;
|
||||
private pollXhr;
|
||||
/**
|
||||
* XHR Polling constructor.
|
||||
*
|
||||
* @param {Object} opts
|
||||
* @package
|
||||
*/
|
||||
constructor(opts: any);
|
||||
get name(): string;
|
||||
/**
|
||||
* Opens the socket (triggers polling). We write a PING message to determine
|
||||
* when the transport is open.
|
||||
*
|
||||
* @protected
|
||||
*/
|
||||
doOpen(): void;
|
||||
/**
|
||||
* Pauses polling.
|
||||
*
|
||||
* @param {Function} onPause - callback upon buffers are flushed and transport is paused
|
||||
* @package
|
||||
*/
|
||||
pause(onPause: any): void;
|
||||
/**
|
||||
* Starts polling cycle.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
poll(): void;
|
||||
/**
|
||||
* Overloads onData to detect payloads.
|
||||
*
|
||||
* @protected
|
||||
*/
|
||||
onData(data: any): void;
|
||||
/**
|
||||
* For polling, send a close packet.
|
||||
*
|
||||
* @protected
|
||||
*/
|
||||
doClose(): void;
|
||||
/**
|
||||
* Writes a packets payload.
|
||||
*
|
||||
* @param {Array} packets - data packets
|
||||
* @protected
|
||||
*/
|
||||
write(packets: any): void;
|
||||
/**
|
||||
* Generates uri for connection.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
uri(): string;
|
||||
/**
|
||||
* Creates a request.
|
||||
*
|
||||
* @param {String} method
|
||||
* @private
|
||||
*/
|
||||
request(opts?: {}): Request;
|
||||
/**
|
||||
* Sends data.
|
||||
*
|
||||
* @param {String} data to send.
|
||||
* @param {Function} called upon flush.
|
||||
* @private
|
||||
*/
|
||||
private doWrite;
|
||||
/**
|
||||
* Starts a poll cycle.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
private doPoll;
|
||||
}
|
||||
interface RequestReservedEvents {
|
||||
success: () => void;
|
||||
data: (data: RawData) => void;
|
||||
error: (err: number | Error, context: unknown) => void;
|
||||
}
|
||||
export declare class Request extends Emitter<{}, {}, RequestReservedEvents> {
|
||||
private readonly opts;
|
||||
private readonly method;
|
||||
private readonly uri;
|
||||
private readonly async;
|
||||
private readonly data;
|
||||
private xhr;
|
||||
private setTimeoutFn;
|
||||
private index;
|
||||
static requestsCount: number;
|
||||
static requests: {};
|
||||
/**
|
||||
* Request constructor
|
||||
*
|
||||
* @param {Object} options
|
||||
* @package
|
||||
*/
|
||||
constructor(uri: any, opts: any);
|
||||
/**
|
||||
* Creates the XHR object and sends the request.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
private create;
|
||||
/**
|
||||
* Called upon error.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
private onError;
|
||||
/**
|
||||
* Cleans up house.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
private cleanup;
|
||||
/**
|
||||
* Called upon load.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
private onLoad;
|
||||
/**
|
||||
* Aborts the request.
|
||||
*
|
||||
* @package
|
||||
*/
|
||||
abort(): void;
|
||||
}
|
||||
export {};
|
||||
415
node_modules/engine.io-client/build/esm-debug/transports/polling.js
generated
vendored
Normal file
415
node_modules/engine.io-client/build/esm-debug/transports/polling.js
generated
vendored
Normal file
@@ -0,0 +1,415 @@
|
||||
import { Transport } from "../transport.js";
|
||||
import debugModule from "debug"; // debug()
|
||||
import { yeast } from "../contrib/yeast.js";
|
||||
import { encode } from "../contrib/parseqs.js";
|
||||
import { encodePayload, decodePayload } from "engine.io-parser";
|
||||
import { XHR as XMLHttpRequest } from "./xmlhttprequest.js";
|
||||
import { Emitter } from "@socket.io/component-emitter";
|
||||
import { installTimerFunctions, pick } from "../util.js";
|
||||
import { globalThisShim as globalThis } from "../globalThis.js";
|
||||
const debug = debugModule("engine.io-client:polling"); // debug()
|
||||
function empty() { }
|
||||
const hasXHR2 = (function () {
|
||||
const xhr = new XMLHttpRequest({
|
||||
xdomain: false,
|
||||
});
|
||||
return null != xhr.responseType;
|
||||
})();
|
||||
export class Polling extends Transport {
|
||||
/**
|
||||
* XHR Polling constructor.
|
||||
*
|
||||
* @param {Object} opts
|
||||
* @package
|
||||
*/
|
||||
constructor(opts) {
|
||||
super(opts);
|
||||
this.polling = false;
|
||||
if (typeof location !== "undefined") {
|
||||
const isSSL = "https:" === location.protocol;
|
||||
let port = location.port;
|
||||
// some user agents have empty `location.port`
|
||||
if (!port) {
|
||||
port = isSSL ? "443" : "80";
|
||||
}
|
||||
this.xd =
|
||||
(typeof location !== "undefined" &&
|
||||
opts.hostname !== location.hostname) ||
|
||||
port !== opts.port;
|
||||
this.xs = opts.secure !== isSSL;
|
||||
}
|
||||
/**
|
||||
* XHR supports binary
|
||||
*/
|
||||
const forceBase64 = opts && opts.forceBase64;
|
||||
this.supportsBinary = hasXHR2 && !forceBase64;
|
||||
}
|
||||
get name() {
|
||||
return "polling";
|
||||
}
|
||||
/**
|
||||
* Opens the socket (triggers polling). We write a PING message to determine
|
||||
* when the transport is open.
|
||||
*
|
||||
* @protected
|
||||
*/
|
||||
doOpen() {
|
||||
this.poll();
|
||||
}
|
||||
/**
|
||||
* Pauses polling.
|
||||
*
|
||||
* @param {Function} onPause - callback upon buffers are flushed and transport is paused
|
||||
* @package
|
||||
*/
|
||||
pause(onPause) {
|
||||
this.readyState = "pausing";
|
||||
const pause = () => {
|
||||
debug("paused");
|
||||
this.readyState = "paused";
|
||||
onPause();
|
||||
};
|
||||
if (this.polling || !this.writable) {
|
||||
let total = 0;
|
||||
if (this.polling) {
|
||||
debug("we are currently polling - waiting to pause");
|
||||
total++;
|
||||
this.once("pollComplete", function () {
|
||||
debug("pre-pause polling complete");
|
||||
--total || pause();
|
||||
});
|
||||
}
|
||||
if (!this.writable) {
|
||||
debug("we are currently writing - waiting to pause");
|
||||
total++;
|
||||
this.once("drain", function () {
|
||||
debug("pre-pause writing complete");
|
||||
--total || pause();
|
||||
});
|
||||
}
|
||||
}
|
||||
else {
|
||||
pause();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Starts polling cycle.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
poll() {
|
||||
debug("polling");
|
||||
this.polling = true;
|
||||
this.doPoll();
|
||||
this.emitReserved("poll");
|
||||
}
|
||||
/**
|
||||
* Overloads onData to detect payloads.
|
||||
*
|
||||
* @protected
|
||||
*/
|
||||
onData(data) {
|
||||
debug("polling got data %s", data);
|
||||
const callback = (packet) => {
|
||||
// if its the first message we consider the transport open
|
||||
if ("opening" === this.readyState && packet.type === "open") {
|
||||
this.onOpen();
|
||||
}
|
||||
// if its a close packet, we close the ongoing requests
|
||||
if ("close" === packet.type) {
|
||||
this.onClose({ description: "transport closed by the server" });
|
||||
return false;
|
||||
}
|
||||
// otherwise bypass onData and handle the message
|
||||
this.onPacket(packet);
|
||||
};
|
||||
// decode payload
|
||||
decodePayload(data, this.socket.binaryType).forEach(callback);
|
||||
// if an event did not trigger closing
|
||||
if ("closed" !== this.readyState) {
|
||||
// if we got data we're not polling
|
||||
this.polling = false;
|
||||
this.emitReserved("pollComplete");
|
||||
if ("open" === this.readyState) {
|
||||
this.poll();
|
||||
}
|
||||
else {
|
||||
debug('ignoring poll - transport state "%s"', this.readyState);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* For polling, send a close packet.
|
||||
*
|
||||
* @protected
|
||||
*/
|
||||
doClose() {
|
||||
const close = () => {
|
||||
debug("writing close packet");
|
||||
this.write([{ type: "close" }]);
|
||||
};
|
||||
if ("open" === this.readyState) {
|
||||
debug("transport open - closing");
|
||||
close();
|
||||
}
|
||||
else {
|
||||
// in case we're trying to close while
|
||||
// handshaking is in progress (GH-164)
|
||||
debug("transport not open - deferring close");
|
||||
this.once("open", close);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Writes a packets payload.
|
||||
*
|
||||
* @param {Array} packets - data packets
|
||||
* @protected
|
||||
*/
|
||||
write(packets) {
|
||||
this.writable = false;
|
||||
encodePayload(packets, (data) => {
|
||||
this.doWrite(data, () => {
|
||||
this.writable = true;
|
||||
this.emitReserved("drain");
|
||||
});
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Generates uri for connection.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
uri() {
|
||||
let query = this.query || {};
|
||||
const schema = this.opts.secure ? "https" : "http";
|
||||
let port = "";
|
||||
// cache busting is forced
|
||||
if (false !== this.opts.timestampRequests) {
|
||||
query[this.opts.timestampParam] = yeast();
|
||||
}
|
||||
if (!this.supportsBinary && !query.sid) {
|
||||
query.b64 = 1;
|
||||
}
|
||||
// avoid port if default for schema
|
||||
if (this.opts.port &&
|
||||
(("https" === schema && Number(this.opts.port) !== 443) ||
|
||||
("http" === schema && Number(this.opts.port) !== 80))) {
|
||||
port = ":" + this.opts.port;
|
||||
}
|
||||
const encodedQuery = encode(query);
|
||||
const ipv6 = this.opts.hostname.indexOf(":") !== -1;
|
||||
return (schema +
|
||||
"://" +
|
||||
(ipv6 ? "[" + this.opts.hostname + "]" : this.opts.hostname) +
|
||||
port +
|
||||
this.opts.path +
|
||||
(encodedQuery.length ? "?" + encodedQuery : ""));
|
||||
}
|
||||
/**
|
||||
* Creates a request.
|
||||
*
|
||||
* @param {String} method
|
||||
* @private
|
||||
*/
|
||||
request(opts = {}) {
|
||||
Object.assign(opts, { xd: this.xd, xs: this.xs }, this.opts);
|
||||
return new Request(this.uri(), opts);
|
||||
}
|
||||
/**
|
||||
* Sends data.
|
||||
*
|
||||
* @param {String} data to send.
|
||||
* @param {Function} called upon flush.
|
||||
* @private
|
||||
*/
|
||||
doWrite(data, fn) {
|
||||
const req = this.request({
|
||||
method: "POST",
|
||||
data: data,
|
||||
});
|
||||
req.on("success", fn);
|
||||
req.on("error", (xhrStatus, context) => {
|
||||
this.onError("xhr post error", xhrStatus, context);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Starts a poll cycle.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
doPoll() {
|
||||
debug("xhr poll");
|
||||
const req = this.request();
|
||||
req.on("data", this.onData.bind(this));
|
||||
req.on("error", (xhrStatus, context) => {
|
||||
this.onError("xhr poll error", xhrStatus, context);
|
||||
});
|
||||
this.pollXhr = req;
|
||||
}
|
||||
}
|
||||
export class Request extends Emitter {
|
||||
/**
|
||||
* Request constructor
|
||||
*
|
||||
* @param {Object} options
|
||||
* @package
|
||||
*/
|
||||
constructor(uri, opts) {
|
||||
super();
|
||||
installTimerFunctions(this, opts);
|
||||
this.opts = opts;
|
||||
this.method = opts.method || "GET";
|
||||
this.uri = uri;
|
||||
this.async = false !== opts.async;
|
||||
this.data = undefined !== opts.data ? opts.data : null;
|
||||
this.create();
|
||||
}
|
||||
/**
|
||||
* Creates the XHR object and sends the request.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
create() {
|
||||
const opts = pick(this.opts, "agent", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "autoUnref");
|
||||
opts.xdomain = !!this.opts.xd;
|
||||
opts.xscheme = !!this.opts.xs;
|
||||
const xhr = (this.xhr = new XMLHttpRequest(opts));
|
||||
try {
|
||||
debug("xhr open %s: %s", this.method, this.uri);
|
||||
xhr.open(this.method, this.uri, this.async);
|
||||
try {
|
||||
if (this.opts.extraHeaders) {
|
||||
xhr.setDisableHeaderCheck && xhr.setDisableHeaderCheck(true);
|
||||
for (let i in this.opts.extraHeaders) {
|
||||
if (this.opts.extraHeaders.hasOwnProperty(i)) {
|
||||
xhr.setRequestHeader(i, this.opts.extraHeaders[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e) { }
|
||||
if ("POST" === this.method) {
|
||||
try {
|
||||
xhr.setRequestHeader("Content-type", "text/plain;charset=UTF-8");
|
||||
}
|
||||
catch (e) { }
|
||||
}
|
||||
try {
|
||||
xhr.setRequestHeader("Accept", "*/*");
|
||||
}
|
||||
catch (e) { }
|
||||
// ie6 check
|
||||
if ("withCredentials" in xhr) {
|
||||
xhr.withCredentials = this.opts.withCredentials;
|
||||
}
|
||||
if (this.opts.requestTimeout) {
|
||||
xhr.timeout = this.opts.requestTimeout;
|
||||
}
|
||||
xhr.onreadystatechange = () => {
|
||||
if (4 !== xhr.readyState)
|
||||
return;
|
||||
if (200 === xhr.status || 1223 === xhr.status) {
|
||||
this.onLoad();
|
||||
}
|
||||
else {
|
||||
// make sure the `error` event handler that's user-set
|
||||
// does not throw in the same tick and gets caught here
|
||||
this.setTimeoutFn(() => {
|
||||
this.onError(typeof xhr.status === "number" ? xhr.status : 0);
|
||||
}, 0);
|
||||
}
|
||||
};
|
||||
debug("xhr data %s", this.data);
|
||||
xhr.send(this.data);
|
||||
}
|
||||
catch (e) {
|
||||
// Need to defer since .create() is called directly from the constructor
|
||||
// and thus the 'error' event can only be only bound *after* this exception
|
||||
// occurs. Therefore, also, we cannot throw here at all.
|
||||
this.setTimeoutFn(() => {
|
||||
this.onError(e);
|
||||
}, 0);
|
||||
return;
|
||||
}
|
||||
if (typeof document !== "undefined") {
|
||||
this.index = Request.requestsCount++;
|
||||
Request.requests[this.index] = this;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Called upon error.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
onError(err) {
|
||||
this.emitReserved("error", err, this.xhr);
|
||||
this.cleanup(true);
|
||||
}
|
||||
/**
|
||||
* Cleans up house.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
cleanup(fromError) {
|
||||
if ("undefined" === typeof this.xhr || null === this.xhr) {
|
||||
return;
|
||||
}
|
||||
this.xhr.onreadystatechange = empty;
|
||||
if (fromError) {
|
||||
try {
|
||||
this.xhr.abort();
|
||||
}
|
||||
catch (e) { }
|
||||
}
|
||||
if (typeof document !== "undefined") {
|
||||
delete Request.requests[this.index];
|
||||
}
|
||||
this.xhr = null;
|
||||
}
|
||||
/**
|
||||
* Called upon load.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
onLoad() {
|
||||
const data = this.xhr.responseText;
|
||||
if (data !== null) {
|
||||
this.emitReserved("data", data);
|
||||
this.emitReserved("success");
|
||||
this.cleanup();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Aborts the request.
|
||||
*
|
||||
* @package
|
||||
*/
|
||||
abort() {
|
||||
this.cleanup();
|
||||
}
|
||||
}
|
||||
Request.requestsCount = 0;
|
||||
Request.requests = {};
|
||||
/**
|
||||
* Aborts pending requests when unloading the window. This is needed to prevent
|
||||
* memory leaks (e.g. when using IE) and to ensure that no spurious error is
|
||||
* emitted.
|
||||
*/
|
||||
if (typeof document !== "undefined") {
|
||||
// @ts-ignore
|
||||
if (typeof attachEvent === "function") {
|
||||
// @ts-ignore
|
||||
attachEvent("onunload", unloadHandler);
|
||||
}
|
||||
else if (typeof addEventListener === "function") {
|
||||
const terminationEvent = "onpagehide" in globalThis ? "pagehide" : "unload";
|
||||
addEventListener(terminationEvent, unloadHandler, false);
|
||||
}
|
||||
}
|
||||
function unloadHandler() {
|
||||
for (let i in Request.requests) {
|
||||
if (Request.requests.hasOwnProperty(i)) {
|
||||
Request.requests[i].abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
4
node_modules/engine.io-client/build/esm-debug/transports/websocket-constructor.browser.d.ts
generated
vendored
Normal file
4
node_modules/engine.io-client/build/esm-debug/transports/websocket-constructor.browser.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
export declare const nextTick: (cb: any, setTimeoutFn: any) => any;
|
||||
export declare const WebSocket: any;
|
||||
export declare const usingBrowserWebSocket = true;
|
||||
export declare const defaultBinaryType = "arraybuffer";
|
||||
13
node_modules/engine.io-client/build/esm-debug/transports/websocket-constructor.browser.js
generated
vendored
Normal file
13
node_modules/engine.io-client/build/esm-debug/transports/websocket-constructor.browser.js
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
import { globalThisShim as globalThis } from "../globalThis.js";
|
||||
export const nextTick = (() => {
|
||||
const isPromiseAvailable = typeof Promise === "function" && typeof Promise.resolve === "function";
|
||||
if (isPromiseAvailable) {
|
||||
return (cb) => Promise.resolve().then(cb);
|
||||
}
|
||||
else {
|
||||
return (cb, setTimeoutFn) => setTimeoutFn(cb, 0);
|
||||
}
|
||||
})();
|
||||
export const WebSocket = globalThis.WebSocket || globalThis.MozWebSocket;
|
||||
export const usingBrowserWebSocket = true;
|
||||
export const defaultBinaryType = "arraybuffer";
|
||||
4
node_modules/engine.io-client/build/esm-debug/transports/websocket-constructor.d.ts
generated
vendored
Normal file
4
node_modules/engine.io-client/build/esm-debug/transports/websocket-constructor.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
export declare const WebSocket: any;
|
||||
export declare const usingBrowserWebSocket = false;
|
||||
export declare const defaultBinaryType = "nodebuffer";
|
||||
export declare const nextTick: (callback: Function, ...args: any[]) => void;
|
||||
5
node_modules/engine.io-client/build/esm-debug/transports/websocket-constructor.js
generated
vendored
Normal file
5
node_modules/engine.io-client/build/esm-debug/transports/websocket-constructor.js
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import ws from "ws";
|
||||
export const WebSocket = ws;
|
||||
export const usingBrowserWebSocket = false;
|
||||
export const defaultBinaryType = "nodebuffer";
|
||||
export const nextTick = process.nextTick;
|
||||
34
node_modules/engine.io-client/build/esm-debug/transports/websocket.d.ts
generated
vendored
Normal file
34
node_modules/engine.io-client/build/esm-debug/transports/websocket.d.ts
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
import { Transport } from "../transport.js";
|
||||
export declare class WS extends Transport {
|
||||
private ws;
|
||||
/**
|
||||
* WebSocket transport constructor.
|
||||
*
|
||||
* @param {Object} opts - connection options
|
||||
* @protected
|
||||
*/
|
||||
constructor(opts: any);
|
||||
get name(): string;
|
||||
doOpen(): this;
|
||||
/**
|
||||
* Adds event listeners to the socket
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
private addEventListeners;
|
||||
write(packets: any): void;
|
||||
doClose(): void;
|
||||
/**
|
||||
* Generates uri for connection.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
uri(): string;
|
||||
/**
|
||||
* Feature detection for WebSocket.
|
||||
*
|
||||
* @return {Boolean} whether this transport is available.
|
||||
* @private
|
||||
*/
|
||||
private check;
|
||||
}
|
||||
170
node_modules/engine.io-client/build/esm-debug/transports/websocket.js
generated
vendored
Normal file
170
node_modules/engine.io-client/build/esm-debug/transports/websocket.js
generated
vendored
Normal file
@@ -0,0 +1,170 @@
|
||||
import { Transport } from "../transport.js";
|
||||
import { encode } from "../contrib/parseqs.js";
|
||||
import { yeast } from "../contrib/yeast.js";
|
||||
import { pick } from "../util.js";
|
||||
import { defaultBinaryType, nextTick, usingBrowserWebSocket, WebSocket, } from "./websocket-constructor.js";
|
||||
import debugModule from "debug"; // debug()
|
||||
import { encodePacket } from "engine.io-parser";
|
||||
const debug = debugModule("engine.io-client:websocket"); // debug()
|
||||
// detect ReactNative environment
|
||||
const isReactNative = typeof navigator !== "undefined" &&
|
||||
typeof navigator.product === "string" &&
|
||||
navigator.product.toLowerCase() === "reactnative";
|
||||
export class WS extends Transport {
|
||||
/**
|
||||
* WebSocket transport constructor.
|
||||
*
|
||||
* @param {Object} opts - connection options
|
||||
* @protected
|
||||
*/
|
||||
constructor(opts) {
|
||||
super(opts);
|
||||
this.supportsBinary = !opts.forceBase64;
|
||||
}
|
||||
get name() {
|
||||
return "websocket";
|
||||
}
|
||||
doOpen() {
|
||||
if (!this.check()) {
|
||||
// let probe timeout
|
||||
return;
|
||||
}
|
||||
const uri = this.uri();
|
||||
const protocols = this.opts.protocols;
|
||||
// React Native only supports the 'headers' option, and will print a warning if anything else is passed
|
||||
const opts = isReactNative
|
||||
? {}
|
||||
: pick(this.opts, "agent", "perMessageDeflate", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "localAddress", "protocolVersion", "origin", "maxPayload", "family", "checkServerIdentity");
|
||||
if (this.opts.extraHeaders) {
|
||||
opts.headers = this.opts.extraHeaders;
|
||||
}
|
||||
try {
|
||||
this.ws =
|
||||
usingBrowserWebSocket && !isReactNative
|
||||
? protocols
|
||||
? new WebSocket(uri, protocols)
|
||||
: new WebSocket(uri)
|
||||
: new WebSocket(uri, protocols, opts);
|
||||
}
|
||||
catch (err) {
|
||||
return this.emitReserved("error", err);
|
||||
}
|
||||
this.ws.binaryType = this.socket.binaryType || defaultBinaryType;
|
||||
this.addEventListeners();
|
||||
}
|
||||
/**
|
||||
* Adds event listeners to the socket
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
addEventListeners() {
|
||||
this.ws.onopen = () => {
|
||||
if (this.opts.autoUnref) {
|
||||
this.ws._socket.unref();
|
||||
}
|
||||
this.onOpen();
|
||||
};
|
||||
this.ws.onclose = (closeEvent) => this.onClose({
|
||||
description: "websocket connection closed",
|
||||
context: closeEvent,
|
||||
});
|
||||
this.ws.onmessage = (ev) => this.onData(ev.data);
|
||||
this.ws.onerror = (e) => this.onError("websocket error", e);
|
||||
}
|
||||
write(packets) {
|
||||
this.writable = false;
|
||||
// encodePacket efficient as it uses WS framing
|
||||
// no need for encodePayload
|
||||
for (let i = 0; i < packets.length; i++) {
|
||||
const packet = packets[i];
|
||||
const lastPacket = i === packets.length - 1;
|
||||
encodePacket(packet, this.supportsBinary, (data) => {
|
||||
// always create a new object (GH-437)
|
||||
const opts = {};
|
||||
if (!usingBrowserWebSocket) {
|
||||
if (packet.options) {
|
||||
opts.compress = packet.options.compress;
|
||||
}
|
||||
if (this.opts.perMessageDeflate) {
|
||||
const len =
|
||||
// @ts-ignore
|
||||
"string" === typeof data ? Buffer.byteLength(data) : data.length;
|
||||
if (len < this.opts.perMessageDeflate.threshold) {
|
||||
opts.compress = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Sometimes the websocket has already been closed but the browser didn't
|
||||
// have a chance of informing us about it yet, in that case send will
|
||||
// throw an error
|
||||
try {
|
||||
if (usingBrowserWebSocket) {
|
||||
// TypeError is thrown when passing the second argument on Safari
|
||||
this.ws.send(data);
|
||||
}
|
||||
else {
|
||||
this.ws.send(data, opts);
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
debug("websocket closed before onclose event");
|
||||
}
|
||||
if (lastPacket) {
|
||||
// fake drain
|
||||
// defer to next tick to allow Socket to clear writeBuffer
|
||||
nextTick(() => {
|
||||
this.writable = true;
|
||||
this.emitReserved("drain");
|
||||
}, this.setTimeoutFn);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
doClose() {
|
||||
if (typeof this.ws !== "undefined") {
|
||||
this.ws.close();
|
||||
this.ws = null;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Generates uri for connection.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
uri() {
|
||||
let query = this.query || {};
|
||||
const schema = this.opts.secure ? "wss" : "ws";
|
||||
let port = "";
|
||||
// avoid port if default for schema
|
||||
if (this.opts.port &&
|
||||
(("wss" === schema && Number(this.opts.port) !== 443) ||
|
||||
("ws" === schema && Number(this.opts.port) !== 80))) {
|
||||
port = ":" + this.opts.port;
|
||||
}
|
||||
// append timestamp to URI
|
||||
if (this.opts.timestampRequests) {
|
||||
query[this.opts.timestampParam] = yeast();
|
||||
}
|
||||
// communicate binary support capabilities
|
||||
if (!this.supportsBinary) {
|
||||
query.b64 = 1;
|
||||
}
|
||||
const encodedQuery = encode(query);
|
||||
const ipv6 = this.opts.hostname.indexOf(":") !== -1;
|
||||
return (schema +
|
||||
"://" +
|
||||
(ipv6 ? "[" + this.opts.hostname + "]" : this.opts.hostname) +
|
||||
port +
|
||||
this.opts.path +
|
||||
(encodedQuery.length ? "?" + encodedQuery : ""));
|
||||
}
|
||||
/**
|
||||
* Feature detection for WebSocket.
|
||||
*
|
||||
* @return {Boolean} whether this transport is available.
|
||||
* @private
|
||||
*/
|
||||
check() {
|
||||
return !!WebSocket;
|
||||
}
|
||||
}
|
||||
1
node_modules/engine.io-client/build/esm-debug/transports/xmlhttprequest.browser.d.ts
generated
vendored
Normal file
1
node_modules/engine.io-client/build/esm-debug/transports/xmlhttprequest.browser.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export declare function XHR(opts: any): any;
|
||||
19
node_modules/engine.io-client/build/esm-debug/transports/xmlhttprequest.browser.js
generated
vendored
Normal file
19
node_modules/engine.io-client/build/esm-debug/transports/xmlhttprequest.browser.js
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
// browser shim for xmlhttprequest module
|
||||
import { hasCORS } from "../contrib/has-cors.js";
|
||||
import { globalThisShim as globalThis } from "../globalThis.js";
|
||||
export function XHR(opts) {
|
||||
const xdomain = opts.xdomain;
|
||||
// XMLHttpRequest can be disabled on IE
|
||||
try {
|
||||
if ("undefined" !== typeof XMLHttpRequest && (!xdomain || hasCORS)) {
|
||||
return new XMLHttpRequest();
|
||||
}
|
||||
}
|
||||
catch (e) { }
|
||||
if (!xdomain) {
|
||||
try {
|
||||
return new globalThis[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP");
|
||||
}
|
||||
catch (e) { }
|
||||
}
|
||||
}
|
||||
1
node_modules/engine.io-client/build/esm-debug/transports/xmlhttprequest.d.ts
generated
vendored
Normal file
1
node_modules/engine.io-client/build/esm-debug/transports/xmlhttprequest.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export declare const XHR: any;
|
||||
2
node_modules/engine.io-client/build/esm-debug/transports/xmlhttprequest.js
generated
vendored
Normal file
2
node_modules/engine.io-client/build/esm-debug/transports/xmlhttprequest.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import * as XMLHttpRequestModule from "xmlhttprequest-ssl";
|
||||
export const XHR = XMLHttpRequestModule.default || XMLHttpRequestModule;
|
||||
Reference in New Issue
Block a user