Updated script that can be controled by Nodejs web app
This commit is contained in:
8
node_modules/engine.io-client/build/cjs/transports/index.d.ts
generated
vendored
Normal file
8
node_modules/engine.io-client/build/cjs/transports/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
import { XHR } from "./polling-xhr.node.js";
|
||||
import { WS } from "./websocket.node.js";
|
||||
import { WT } from "./webtransport.js";
|
||||
export declare const transports: {
|
||||
websocket: typeof WS;
|
||||
webtransport: typeof WT;
|
||||
polling: typeof XHR;
|
||||
};
|
11
node_modules/engine.io-client/build/cjs/transports/index.js
generated
vendored
Normal file
11
node_modules/engine.io-client/build/cjs/transports/index.js
generated
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.transports = void 0;
|
||||
const polling_xhr_node_js_1 = require("./polling-xhr.node.js");
|
||||
const websocket_node_js_1 = require("./websocket.node.js");
|
||||
const webtransport_js_1 = require("./webtransport.js");
|
||||
exports.transports = {
|
||||
websocket: websocket_node_js_1.WS,
|
||||
webtransport: webtransport_js_1.WT,
|
||||
polling: polling_xhr_node_js_1.XHR,
|
||||
};
|
15
node_modules/engine.io-client/build/cjs/transports/polling-fetch.d.ts
generated
vendored
Normal file
15
node_modules/engine.io-client/build/cjs/transports/polling-fetch.d.ts
generated
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
import { Polling } from "./polling.js";
|
||||
/**
|
||||
* HTTP long-polling based on the built-in `fetch()` method.
|
||||
*
|
||||
* Usage: browser, Node.js (since v18), Deno, Bun
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/API/fetch
|
||||
* @see https://caniuse.com/fetch
|
||||
* @see https://nodejs.org/api/globals.html#fetch
|
||||
*/
|
||||
export declare class Fetch extends Polling {
|
||||
doPoll(): void;
|
||||
doWrite(data: string, callback: () => void): void;
|
||||
private _fetch;
|
||||
}
|
60
node_modules/engine.io-client/build/cjs/transports/polling-fetch.js
generated
vendored
Normal file
60
node_modules/engine.io-client/build/cjs/transports/polling-fetch.js
generated
vendored
Normal file
@ -0,0 +1,60 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Fetch = void 0;
|
||||
const polling_js_1 = require("./polling.js");
|
||||
/**
|
||||
* HTTP long-polling based on the built-in `fetch()` method.
|
||||
*
|
||||
* Usage: browser, Node.js (since v18), Deno, Bun
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/API/fetch
|
||||
* @see https://caniuse.com/fetch
|
||||
* @see https://nodejs.org/api/globals.html#fetch
|
||||
*/
|
||||
class Fetch extends polling_js_1.Polling {
|
||||
doPoll() {
|
||||
this._fetch()
|
||||
.then((res) => {
|
||||
if (!res.ok) {
|
||||
return this.onError("fetch read error", res.status, res);
|
||||
}
|
||||
res.text().then((data) => this.onData(data));
|
||||
})
|
||||
.catch((err) => {
|
||||
this.onError("fetch read error", err);
|
||||
});
|
||||
}
|
||||
doWrite(data, callback) {
|
||||
this._fetch(data)
|
||||
.then((res) => {
|
||||
if (!res.ok) {
|
||||
return this.onError("fetch write error", res.status, res);
|
||||
}
|
||||
callback();
|
||||
})
|
||||
.catch((err) => {
|
||||
this.onError("fetch write error", err);
|
||||
});
|
||||
}
|
||||
_fetch(data) {
|
||||
var _a;
|
||||
const isPost = data !== undefined;
|
||||
const headers = new Headers(this.opts.extraHeaders);
|
||||
if (isPost) {
|
||||
headers.set("content-type", "text/plain;charset=UTF-8");
|
||||
}
|
||||
(_a = this.socket._cookieJar) === null || _a === void 0 ? void 0 : _a.appendCookies(headers);
|
||||
return fetch(this.uri(), {
|
||||
method: isPost ? "POST" : "GET",
|
||||
body: isPost ? data : null,
|
||||
headers,
|
||||
credentials: this.opts.withCredentials ? "include" : "omit",
|
||||
}).then((res) => {
|
||||
var _a;
|
||||
// @ts-ignore getSetCookie() was added in Node.js v19.7.0
|
||||
(_a = this.socket._cookieJar) === null || _a === void 0 ? void 0 : _a.parseCookies(res.headers.getSetCookie());
|
||||
return res;
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.Fetch = Fetch;
|
108
node_modules/engine.io-client/build/cjs/transports/polling-xhr.d.ts
generated
vendored
Normal file
108
node_modules/engine.io-client/build/cjs/transports/polling-xhr.d.ts
generated
vendored
Normal file
@ -0,0 +1,108 @@
|
||||
import { Polling } from "./polling.js";
|
||||
import { Emitter } from "@socket.io/component-emitter";
|
||||
import type { SocketOptions } from "../socket.js";
|
||||
import type { CookieJar } from "../globals.node.js";
|
||||
import type { RawData } from "engine.io-parser";
|
||||
export declare abstract class BaseXHR extends Polling {
|
||||
protected readonly xd: boolean;
|
||||
private pollXhr;
|
||||
/**
|
||||
* XHR Polling constructor.
|
||||
*
|
||||
* @param {Object} opts
|
||||
* @package
|
||||
*/
|
||||
constructor(opts: any);
|
||||
/**
|
||||
* Creates a request.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
abstract request(opts?: Record<string, any>): any;
|
||||
/**
|
||||
* Sends data.
|
||||
*
|
||||
* @param {String} data to send.
|
||||
* @param {Function} called upon flush.
|
||||
* @private
|
||||
*/
|
||||
doWrite(data: any, fn: any): void;
|
||||
/**
|
||||
* Starts a poll cycle.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
doPoll(): void;
|
||||
}
|
||||
interface RequestReservedEvents {
|
||||
success: () => void;
|
||||
data: (data: RawData) => void;
|
||||
error: (err: number | Error, context: unknown) => void;
|
||||
}
|
||||
export type RequestOptions = SocketOptions & {
|
||||
method?: string;
|
||||
data?: RawData;
|
||||
xd: boolean;
|
||||
cookieJar: CookieJar;
|
||||
};
|
||||
export declare class Request extends Emitter<Record<never, never>, Record<never, never>, RequestReservedEvents> {
|
||||
private readonly createRequest;
|
||||
private readonly _opts;
|
||||
private readonly _method;
|
||||
private readonly _uri;
|
||||
private readonly _data;
|
||||
private _xhr;
|
||||
private setTimeoutFn;
|
||||
private _index;
|
||||
static requestsCount: number;
|
||||
static requests: {};
|
||||
/**
|
||||
* Request constructor
|
||||
*
|
||||
* @param {Object} options
|
||||
* @package
|
||||
*/
|
||||
constructor(createRequest: (opts: RequestOptions) => XMLHttpRequest, uri: string, opts: RequestOptions);
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
/**
|
||||
* HTTP long-polling based on the built-in `XMLHttpRequest` object.
|
||||
*
|
||||
* Usage: browser
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest
|
||||
*/
|
||||
export declare class XHR extends BaseXHR {
|
||||
constructor(opts: any);
|
||||
request(opts?: Record<string, any>): Request;
|
||||
}
|
||||
export {};
|
285
node_modules/engine.io-client/build/cjs/transports/polling-xhr.js
generated
vendored
Normal file
285
node_modules/engine.io-client/build/cjs/transports/polling-xhr.js
generated
vendored
Normal file
@ -0,0 +1,285 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.XHR = exports.Request = exports.BaseXHR = void 0;
|
||||
const polling_js_1 = require("./polling.js");
|
||||
const component_emitter_1 = require("@socket.io/component-emitter");
|
||||
const util_js_1 = require("../util.js");
|
||||
const globals_node_js_1 = require("../globals.node.js");
|
||||
const has_cors_js_1 = require("../contrib/has-cors.js");
|
||||
const debug_1 = __importDefault(require("debug")); // debug()
|
||||
const debug = (0, debug_1.default)("engine.io-client:polling"); // debug()
|
||||
function empty() { }
|
||||
class BaseXHR extends polling_js_1.Polling {
|
||||
/**
|
||||
* XHR Polling constructor.
|
||||
*
|
||||
* @param {Object} opts
|
||||
* @package
|
||||
*/
|
||||
constructor(opts) {
|
||||
super(opts);
|
||||
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;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
exports.BaseXHR = BaseXHR;
|
||||
class Request extends component_emitter_1.Emitter {
|
||||
/**
|
||||
* Request constructor
|
||||
*
|
||||
* @param {Object} options
|
||||
* @package
|
||||
*/
|
||||
constructor(createRequest, uri, opts) {
|
||||
super();
|
||||
this.createRequest = createRequest;
|
||||
(0, util_js_1.installTimerFunctions)(this, opts);
|
||||
this._opts = opts;
|
||||
this._method = opts.method || "GET";
|
||||
this._uri = uri;
|
||||
this._data = undefined !== opts.data ? opts.data : null;
|
||||
this._create();
|
||||
}
|
||||
/**
|
||||
* Creates the XHR object and sends the request.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
_create() {
|
||||
var _a;
|
||||
const opts = (0, util_js_1.pick)(this._opts, "agent", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "autoUnref");
|
||||
opts.xdomain = !!this._opts.xd;
|
||||
const xhr = (this._xhr = this.createRequest(opts));
|
||||
try {
|
||||
debug("xhr open %s: %s", this._method, this._uri);
|
||||
xhr.open(this._method, this._uri, true);
|
||||
try {
|
||||
if (this._opts.extraHeaders) {
|
||||
// @ts-ignore
|
||||
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) { }
|
||||
(_a = this._opts.cookieJar) === null || _a === void 0 ? void 0 : _a.addCookies(xhr);
|
||||
// ie6 check
|
||||
if ("withCredentials" in xhr) {
|
||||
xhr.withCredentials = this._opts.withCredentials;
|
||||
}
|
||||
if (this._opts.requestTimeout) {
|
||||
xhr.timeout = this._opts.requestTimeout;
|
||||
}
|
||||
xhr.onreadystatechange = () => {
|
||||
var _a;
|
||||
if (xhr.readyState === 3) {
|
||||
(_a = this._opts.cookieJar) === null || _a === void 0 ? void 0 : _a.parseCookies(
|
||||
// @ts-ignore
|
||||
xhr.getResponseHeader("set-cookie"));
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
exports.Request = Request;
|
||||
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 globals_node_js_1.globalThisShim ? "pagehide" : "unload";
|
||||
addEventListener(terminationEvent, unloadHandler, false);
|
||||
}
|
||||
}
|
||||
function unloadHandler() {
|
||||
for (let i in Request.requests) {
|
||||
if (Request.requests.hasOwnProperty(i)) {
|
||||
Request.requests[i].abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
const hasXHR2 = (function () {
|
||||
const xhr = newRequest({
|
||||
xdomain: false,
|
||||
});
|
||||
return xhr && xhr.responseType !== null;
|
||||
})();
|
||||
/**
|
||||
* HTTP long-polling based on the built-in `XMLHttpRequest` object.
|
||||
*
|
||||
* Usage: browser
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest
|
||||
*/
|
||||
class XHR extends BaseXHR {
|
||||
constructor(opts) {
|
||||
super(opts);
|
||||
const forceBase64 = opts && opts.forceBase64;
|
||||
this.supportsBinary = hasXHR2 && !forceBase64;
|
||||
}
|
||||
request(opts = {}) {
|
||||
Object.assign(opts, { xd: this.xd }, this.opts);
|
||||
return new Request(newRequest, this.uri(), opts);
|
||||
}
|
||||
}
|
||||
exports.XHR = XHR;
|
||||
function newRequest(opts) {
|
||||
const xdomain = opts.xdomain;
|
||||
// XMLHttpRequest can be disabled on IE
|
||||
try {
|
||||
if ("undefined" !== typeof XMLHttpRequest && (!xdomain || has_cors_js_1.hasCORS)) {
|
||||
return new XMLHttpRequest();
|
||||
}
|
||||
}
|
||||
catch (e) { }
|
||||
if (!xdomain) {
|
||||
try {
|
||||
return new globals_node_js_1.globalThisShim[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP");
|
||||
}
|
||||
catch (e) { }
|
||||
}
|
||||
}
|
11
node_modules/engine.io-client/build/cjs/transports/polling-xhr.node.d.ts
generated
vendored
Normal file
11
node_modules/engine.io-client/build/cjs/transports/polling-xhr.node.d.ts
generated
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
import { BaseXHR, Request } from "./polling-xhr.js";
|
||||
/**
|
||||
* HTTP long-polling based on the `XMLHttpRequest` object provided by the `xmlhttprequest-ssl` package.
|
||||
*
|
||||
* Usage: Node.js, Deno (compat), Bun (compat)
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest
|
||||
*/
|
||||
export declare class XHR extends BaseXHR {
|
||||
request(opts?: Record<string, any>): Request;
|
||||
}
|
44
node_modules/engine.io-client/build/cjs/transports/polling-xhr.node.js
generated
vendored
Normal file
44
node_modules/engine.io-client/build/cjs/transports/polling-xhr.node.js
generated
vendored
Normal file
@ -0,0 +1,44 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.XHR = void 0;
|
||||
const XMLHttpRequestModule = __importStar(require("xmlhttprequest-ssl"));
|
||||
const polling_xhr_js_1 = require("./polling-xhr.js");
|
||||
const XMLHttpRequest = XMLHttpRequestModule.default || XMLHttpRequestModule;
|
||||
/**
|
||||
* HTTP long-polling based on the `XMLHttpRequest` object provided by the `xmlhttprequest-ssl` package.
|
||||
*
|
||||
* Usage: Node.js, Deno (compat), Bun (compat)
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest
|
||||
*/
|
||||
class XHR extends polling_xhr_js_1.BaseXHR {
|
||||
request(opts = {}) {
|
||||
var _a;
|
||||
Object.assign(opts, { xd: this.xd, cookieJar: (_a = this.socket) === null || _a === void 0 ? void 0 : _a._cookieJar }, this.opts);
|
||||
return new polling_xhr_js_1.Request((opts) => new XMLHttpRequest(opts), this.uri(), opts);
|
||||
}
|
||||
}
|
||||
exports.XHR = XHR;
|
52
node_modules/engine.io-client/build/cjs/transports/polling.d.ts
generated
vendored
Normal file
52
node_modules/engine.io-client/build/cjs/transports/polling.d.ts
generated
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
import { Transport } from "../transport.js";
|
||||
export declare abstract class Polling extends Transport {
|
||||
private _polling;
|
||||
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
|
||||
*/
|
||||
private _poll;
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
protected uri(): string;
|
||||
abstract doPoll(): any;
|
||||
abstract doWrite(data: string, callback: () => void): any;
|
||||
}
|
165
node_modules/engine.io-client/build/cjs/transports/polling.js
generated
vendored
Normal file
165
node_modules/engine.io-client/build/cjs/transports/polling.js
generated
vendored
Normal file
@ -0,0 +1,165 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Polling = void 0;
|
||||
const transport_js_1 = require("../transport.js");
|
||||
const util_js_1 = require("../util.js");
|
||||
const engine_io_parser_1 = require("engine.io-parser");
|
||||
const debug_1 = __importDefault(require("debug")); // debug()
|
||||
const debug = (0, debug_1.default)("engine.io-client:polling"); // debug()
|
||||
class Polling extends transport_js_1.Transport {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this._polling = false;
|
||||
}
|
||||
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
|
||||
(0, engine_io_parser_1.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;
|
||||
(0, engine_io_parser_1.encodePayload)(packets, (data) => {
|
||||
this.doWrite(data, () => {
|
||||
this.writable = true;
|
||||
this.emitReserved("drain");
|
||||
});
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Generates uri for connection.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
uri() {
|
||||
const schema = this.opts.secure ? "https" : "http";
|
||||
const query = this.query || {};
|
||||
// cache busting is forced
|
||||
if (false !== this.opts.timestampRequests) {
|
||||
query[this.opts.timestampParam] = (0, util_js_1.randomString)();
|
||||
}
|
||||
if (!this.supportsBinary && !query.sid) {
|
||||
query.b64 = 1;
|
||||
}
|
||||
return this.createUri(schema, query);
|
||||
}
|
||||
}
|
||||
exports.Polling = Polling;
|
36
node_modules/engine.io-client/build/cjs/transports/websocket.d.ts
generated
vendored
Normal file
36
node_modules/engine.io-client/build/cjs/transports/websocket.d.ts
generated
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
import { Transport } from "../transport.js";
|
||||
import type { Packet, RawData } from "engine.io-parser";
|
||||
export declare abstract class BaseWS extends Transport {
|
||||
protected ws: any;
|
||||
get name(): string;
|
||||
doOpen(): this;
|
||||
abstract createSocket(uri: string, protocols: string | string[] | undefined, opts: Record<string, any>): any;
|
||||
/**
|
||||
* Adds event listeners to the socket
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
private addEventListeners;
|
||||
write(packets: any): void;
|
||||
abstract doWrite(packet: Packet, data: RawData): any;
|
||||
doClose(): void;
|
||||
/**
|
||||
* Generates uri for connection.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
private uri;
|
||||
}
|
||||
/**
|
||||
* WebSocket transport based on the built-in `WebSocket` object.
|
||||
*
|
||||
* Usage: browser, Node.js (since v21), Deno, Bun
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebSocket
|
||||
* @see https://caniuse.com/mdn-api_websocket
|
||||
* @see https://nodejs.org/api/globals.html#websocket
|
||||
*/
|
||||
export declare class WS extends BaseWS {
|
||||
createSocket(uri: string, protocols: string | string[] | undefined, opts: Record<string, any>): any;
|
||||
doWrite(_packet: Packet, data: RawData): void;
|
||||
}
|
136
node_modules/engine.io-client/build/cjs/transports/websocket.js
generated
vendored
Normal file
136
node_modules/engine.io-client/build/cjs/transports/websocket.js
generated
vendored
Normal file
@ -0,0 +1,136 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.WS = exports.BaseWS = void 0;
|
||||
const transport_js_1 = require("../transport.js");
|
||||
const util_js_1 = require("../util.js");
|
||||
const engine_io_parser_1 = require("engine.io-parser");
|
||||
const globals_node_js_1 = require("../globals.node.js");
|
||||
const debug_1 = __importDefault(require("debug")); // debug()
|
||||
const debug = (0, debug_1.default)("engine.io-client:websocket"); // debug()
|
||||
// detect ReactNative environment
|
||||
const isReactNative = typeof navigator !== "undefined" &&
|
||||
typeof navigator.product === "string" &&
|
||||
navigator.product.toLowerCase() === "reactnative";
|
||||
class BaseWS extends transport_js_1.Transport {
|
||||
get name() {
|
||||
return "websocket";
|
||||
}
|
||||
doOpen() {
|
||||
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
|
||||
? {}
|
||||
: (0, util_js_1.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 = this.createSocket(uri, protocols, opts);
|
||||
}
|
||||
catch (err) {
|
||||
return this.emitReserved("error", err);
|
||||
}
|
||||
this.ws.binaryType = this.socket.binaryType;
|
||||
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;
|
||||
(0, engine_io_parser_1.encodePacket)(packet, this.supportsBinary, (data) => {
|
||||
// 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 {
|
||||
this.doWrite(packet, data);
|
||||
}
|
||||
catch (e) {
|
||||
debug("websocket closed before onclose event");
|
||||
}
|
||||
if (lastPacket) {
|
||||
// fake drain
|
||||
// defer to next tick to allow Socket to clear writeBuffer
|
||||
(0, globals_node_js_1.nextTick)(() => {
|
||||
this.writable = true;
|
||||
this.emitReserved("drain");
|
||||
}, this.setTimeoutFn);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
doClose() {
|
||||
if (typeof this.ws !== "undefined") {
|
||||
this.ws.onerror = () => { };
|
||||
this.ws.close();
|
||||
this.ws = null;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Generates uri for connection.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
uri() {
|
||||
const schema = this.opts.secure ? "wss" : "ws";
|
||||
const query = this.query || {};
|
||||
// append timestamp to URI
|
||||
if (this.opts.timestampRequests) {
|
||||
query[this.opts.timestampParam] = (0, util_js_1.randomString)();
|
||||
}
|
||||
// communicate binary support capabilities
|
||||
if (!this.supportsBinary) {
|
||||
query.b64 = 1;
|
||||
}
|
||||
return this.createUri(schema, query);
|
||||
}
|
||||
}
|
||||
exports.BaseWS = BaseWS;
|
||||
const WebSocketCtor = globals_node_js_1.globalThisShim.WebSocket || globals_node_js_1.globalThisShim.MozWebSocket;
|
||||
/**
|
||||
* WebSocket transport based on the built-in `WebSocket` object.
|
||||
*
|
||||
* Usage: browser, Node.js (since v21), Deno, Bun
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebSocket
|
||||
* @see https://caniuse.com/mdn-api_websocket
|
||||
* @see https://nodejs.org/api/globals.html#websocket
|
||||
*/
|
||||
class WS extends BaseWS {
|
||||
createSocket(uri, protocols, opts) {
|
||||
return !isReactNative
|
||||
? protocols
|
||||
? new WebSocketCtor(uri, protocols)
|
||||
: new WebSocketCtor(uri)
|
||||
: new WebSocketCtor(uri, protocols, opts);
|
||||
}
|
||||
doWrite(_packet, data) {
|
||||
this.ws.send(data);
|
||||
}
|
||||
}
|
||||
exports.WS = WS;
|
14
node_modules/engine.io-client/build/cjs/transports/websocket.node.d.ts
generated
vendored
Normal file
14
node_modules/engine.io-client/build/cjs/transports/websocket.node.d.ts
generated
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
import type { Packet, RawData } from "engine.io-parser";
|
||||
import { BaseWS } from "./websocket.js";
|
||||
/**
|
||||
* WebSocket transport based on the `WebSocket` object provided by the `ws` package.
|
||||
*
|
||||
* Usage: Node.js, Deno (compat), Bun (compat)
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebSocket
|
||||
* @see https://caniuse.com/mdn-api_websocket
|
||||
*/
|
||||
export declare class WS extends BaseWS {
|
||||
createSocket(uri: string, protocols: string | string[] | undefined, opts: Record<string, any>): any;
|
||||
doWrite(packet: Packet, data: RawData): void;
|
||||
}
|
45
node_modules/engine.io-client/build/cjs/transports/websocket.node.js
generated
vendored
Normal file
45
node_modules/engine.io-client/build/cjs/transports/websocket.node.js
generated
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.WS = void 0;
|
||||
const ws_1 = require("ws");
|
||||
const websocket_js_1 = require("./websocket.js");
|
||||
/**
|
||||
* WebSocket transport based on the `WebSocket` object provided by the `ws` package.
|
||||
*
|
||||
* Usage: Node.js, Deno (compat), Bun (compat)
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebSocket
|
||||
* @see https://caniuse.com/mdn-api_websocket
|
||||
*/
|
||||
class WS extends websocket_js_1.BaseWS {
|
||||
createSocket(uri, protocols, opts) {
|
||||
var _a;
|
||||
if ((_a = this.socket) === null || _a === void 0 ? void 0 : _a._cookieJar) {
|
||||
opts.headers = opts.headers || {};
|
||||
opts.headers.cookie =
|
||||
typeof opts.headers.cookie === "string"
|
||||
? [opts.headers.cookie]
|
||||
: opts.headers.cookie || [];
|
||||
for (const [name, cookie] of this.socket._cookieJar.cookies) {
|
||||
opts.headers.cookie.push(`${name}=${cookie.value}`);
|
||||
}
|
||||
}
|
||||
return new ws_1.WebSocket(uri, protocols, opts);
|
||||
}
|
||||
doWrite(packet, data) {
|
||||
const opts = {};
|
||||
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;
|
||||
}
|
||||
}
|
||||
this.ws.send(data, opts);
|
||||
}
|
||||
}
|
||||
exports.WS = WS;
|
18
node_modules/engine.io-client/build/cjs/transports/webtransport.d.ts
generated
vendored
Normal file
18
node_modules/engine.io-client/build/cjs/transports/webtransport.d.ts
generated
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
import { Transport } from "../transport.js";
|
||||
import { Packet } from "engine.io-parser";
|
||||
/**
|
||||
* WebTransport transport based on the built-in `WebTransport` object.
|
||||
*
|
||||
* Usage: browser, Node.js (with the `@fails-components/webtransport` package)
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebTransport
|
||||
* @see https://caniuse.com/webtransport
|
||||
*/
|
||||
export declare class WT extends Transport {
|
||||
private _transport;
|
||||
private _writer;
|
||||
get name(): string;
|
||||
protected doOpen(): this;
|
||||
protected write(packets: Packet[]): void;
|
||||
protected doClose(): void;
|
||||
}
|
94
node_modules/engine.io-client/build/cjs/transports/webtransport.js
generated
vendored
Normal file
94
node_modules/engine.io-client/build/cjs/transports/webtransport.js
generated
vendored
Normal file
@ -0,0 +1,94 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.WT = void 0;
|
||||
const transport_js_1 = require("../transport.js");
|
||||
const globals_node_js_1 = require("../globals.node.js");
|
||||
const engine_io_parser_1 = require("engine.io-parser");
|
||||
const debug_1 = __importDefault(require("debug")); // debug()
|
||||
const debug = (0, debug_1.default)("engine.io-client:webtransport"); // debug()
|
||||
/**
|
||||
* WebTransport transport based on the built-in `WebTransport` object.
|
||||
*
|
||||
* Usage: browser, Node.js (with the `@fails-components/webtransport` package)
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebTransport
|
||||
* @see https://caniuse.com/webtransport
|
||||
*/
|
||||
class WT extends transport_js_1.Transport {
|
||||
get name() {
|
||||
return "webtransport";
|
||||
}
|
||||
doOpen() {
|
||||
try {
|
||||
// @ts-ignore
|
||||
this._transport = new WebTransport(this.createUri("https"), this.opts.transportOptions[this.name]);
|
||||
}
|
||||
catch (err) {
|
||||
return this.emitReserved("error", err);
|
||||
}
|
||||
this._transport.closed
|
||||
.then(() => {
|
||||
debug("transport closed gracefully");
|
||||
this.onClose();
|
||||
})
|
||||
.catch((err) => {
|
||||
debug("transport closed due to %s", err);
|
||||
this.onError("webtransport error", err);
|
||||
});
|
||||
// note: we could have used async/await, but that would require some additional polyfills
|
||||
this._transport.ready.then(() => {
|
||||
this._transport.createBidirectionalStream().then((stream) => {
|
||||
const decoderStream = (0, engine_io_parser_1.createPacketDecoderStream)(Number.MAX_SAFE_INTEGER, this.socket.binaryType);
|
||||
const reader = stream.readable.pipeThrough(decoderStream).getReader();
|
||||
const encoderStream = (0, engine_io_parser_1.createPacketEncoderStream)();
|
||||
encoderStream.readable.pipeTo(stream.writable);
|
||||
this._writer = encoderStream.writable.getWriter();
|
||||
const read = () => {
|
||||
reader
|
||||
.read()
|
||||
.then(({ done, value }) => {
|
||||
if (done) {
|
||||
debug("session is closed");
|
||||
return;
|
||||
}
|
||||
debug("received chunk: %o", value);
|
||||
this.onPacket(value);
|
||||
read();
|
||||
})
|
||||
.catch((err) => {
|
||||
debug("an error occurred while reading: %s", err);
|
||||
});
|
||||
};
|
||||
read();
|
||||
const packet = { type: "open" };
|
||||
if (this.query.sid) {
|
||||
packet.data = `{"sid":"${this.query.sid}"}`;
|
||||
}
|
||||
this._writer.write(packet).then(() => this.onOpen());
|
||||
});
|
||||
});
|
||||
}
|
||||
write(packets) {
|
||||
this.writable = false;
|
||||
for (let i = 0; i < packets.length; i++) {
|
||||
const packet = packets[i];
|
||||
const lastPacket = i === packets.length - 1;
|
||||
this._writer.write(packet).then(() => {
|
||||
if (lastPacket) {
|
||||
(0, globals_node_js_1.nextTick)(() => {
|
||||
this.writable = true;
|
||||
this.emitReserved("drain");
|
||||
}, this.setTimeoutFn);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
doClose() {
|
||||
var _a;
|
||||
(_a = this._transport) === null || _a === void 0 ? void 0 : _a.close();
|
||||
}
|
||||
}
|
||||
exports.WT = WT;
|
Reference in New Issue
Block a user