Updated the files.

This commit is contained in:
Batuhan Berk Başoğlu 2024-02-08 19:38:41 -05:00
parent 1553e6b971
commit 753967d4f5
23418 changed files with 3784666 additions and 0 deletions

22
my-app/node_modules/engine.io-parser/LICENSE generated vendored Executable file
View file

@ -0,0 +1,22 @@
(The MIT License)
Copyright (c) 2016 Guillermo Rauch (@rauchg)
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

158
my-app/node_modules/engine.io-parser/Readme.md generated vendored Executable file
View file

@ -0,0 +1,158 @@
# engine.io-parser
[![Build Status](https://github.com/socketio/engine.io-parser/workflows/CI/badge.svg?branch=main)](https://github.com/socketio/engine.io-parser/actions)
[![NPM version](https://badge.fury.io/js/engine.io-parser.svg)](https://npmjs.com/package/engine.io-parser)
This is the JavaScript parser for the engine.io protocol encoding,
shared by both
[engine.io-client](https://github.com/socketio/engine.io-client) and
[engine.io](https://github.com/socketio/engine.io).
## How to use
### Standalone
The parser can encode/decode packets, payloads, and payloads as binary
with the following methods: `encodePacket`, `decodePacket`, `encodePayload`,
`decodePayload`.
Example:
```js
const parser = require("engine.io-parser");
const data = Buffer.from([ 1, 2, 3, 4 ]);
parser.encodePacket({ type: "message", data }, encoded => {
const decodedData = parser.decodePacket(encoded); // decodedData === data
});
```
### With browserify
Engine.IO Parser is a commonjs module, which means you can include it by using
`require` on the browser and package using [browserify](http://browserify.org/):
1. install the parser package
```shell
npm install engine.io-parser
```
1. write your app code
```js
const parser = require("engine.io-parser");
const testBuffer = new Int8Array(10);
for (let i = 0; i < testBuffer.length; i++) testBuffer[i] = i;
const packets = [{ type: "message", data: testBuffer.buffer }, { type: "message", data: "hello" }];
parser.encodePayload(packets, encoded => {
parser.decodePayload(encoded,
(packet, index, total) => {
const isLast = index + 1 == total;
if (!isLast) {
const buffer = new Int8Array(packet.data); // testBuffer
} else {
const message = packet.data; // "hello"
}
});
});
```
1. build your app bundle
```bash
$ browserify app.js > bundle.js
```
1. include on your page
```html
<script src="/path/to/bundle.js"></script>
```
## Features
- Runs on browser and node.js seamlessly
- Runs inside HTML5 WebWorker
- Can encode and decode packets
- Encodes from/to ArrayBuffer or Blob when in browser, and Buffer or ArrayBuffer in Node
## API
Note: `cb(type)` means the type is a callback function that contains a parameter of type `type` when called.
### Node
- `encodePacket`
- Encodes a packet.
- **Parameters**
- `Object`: the packet to encode, has `type` and `data`.
- `data`: can be a `String`, `Number`, `Buffer`, `ArrayBuffer`
- `Boolean`: binary support
- `Function`: callback, returns the encoded packet (`cb(String)`)
- `decodePacket`
- Decodes a packet. Data also available as an ArrayBuffer if requested.
- Returns data as `String` or (`Blob` on browser, `ArrayBuffer` on Node)
- **Parameters**
- `String` | `ArrayBuffer`: the packet to decode, has `type` and `data`
- `String`: optional, the binary type
- `encodePayload`
- Encodes multiple messages (payload).
- If any contents are binary, they will be encoded as base64 strings. Base64
encoded strings are marked with a b before the length specifier
- **Parameters**
- `Array`: an array of packets
- `Function`: callback, returns the encoded payload (`cb(String)`)
- `decodePayload`
- Decodes data when a payload is maybe expected. Possible binary contents are
decoded from their base64 representation.
- **Parameters**
- `String`: the payload
- `Function`: callback, returns (cb(`Object`: packet, `Number`:packet index, `Number`:packet total))
## Tests
Standalone tests can be run with `npm test` which will run the node.js tests.
Browser tests are run using [zuul](https://github.com/defunctzombie/zuul).
(You must have zuul setup with a saucelabs account.)
You can run the tests locally using the following command:
```
npm run test:browser
```
## Support
The support channels for `engine.io-parser` are the same as `socket.io`:
- irc.freenode.net **#socket.io**
- [Github Discussions](https://github.com/socketio/socket.io/discussions)
- [Website](https://socket.io)
## Development
To contribute patches, run tests or benchmarks, make sure to clone the
repository:
```bash
git clone git://github.com/socketio/engine.io-parser.git
```
Then:
```bash
cd engine.io-parser
npm ci
```
See the `Tests` section above for how to run tests before submitting any patches.
## License
MIT

14
my-app/node_modules/engine.io-parser/build/cjs/commons.d.ts generated vendored Executable file
View file

@ -0,0 +1,14 @@
declare const PACKET_TYPES: any;
declare const PACKET_TYPES_REVERSE: any;
declare const ERROR_PACKET: Packet;
export { PACKET_TYPES, PACKET_TYPES_REVERSE, ERROR_PACKET };
export declare type PacketType = "open" | "close" | "ping" | "pong" | "message" | "upgrade" | "noop" | "error";
export declare type RawData = any;
export interface Packet {
type: PacketType;
options?: {
compress: boolean;
};
data?: RawData;
}
export declare type BinaryType = "nodebuffer" | "arraybuffer" | "blob";

19
my-app/node_modules/engine.io-parser/build/cjs/commons.js generated vendored Executable file
View file

@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ERROR_PACKET = exports.PACKET_TYPES_REVERSE = exports.PACKET_TYPES = void 0;
const PACKET_TYPES = Object.create(null); // no Map = no polyfill
exports.PACKET_TYPES = PACKET_TYPES;
PACKET_TYPES["open"] = "0";
PACKET_TYPES["close"] = "1";
PACKET_TYPES["ping"] = "2";
PACKET_TYPES["pong"] = "3";
PACKET_TYPES["message"] = "4";
PACKET_TYPES["upgrade"] = "5";
PACKET_TYPES["noop"] = "6";
const PACKET_TYPES_REVERSE = Object.create(null);
exports.PACKET_TYPES_REVERSE = PACKET_TYPES_REVERSE;
Object.keys(PACKET_TYPES).forEach((key) => {
PACKET_TYPES_REVERSE[PACKET_TYPES[key]] = key;
});
const ERROR_PACKET = { type: "error", data: "parser error" };
exports.ERROR_PACKET = ERROR_PACKET;

View file

@ -0,0 +1,2 @@
export declare const encode: (arraybuffer: ArrayBuffer) => string;
export declare const decode: (base64: string) => ArrayBuffer;

View file

@ -0,0 +1,48 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.decode = exports.encode = void 0;
// imported from https://github.com/socketio/base64-arraybuffer
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
// Use a lookup table to find the index.
const lookup = typeof Uint8Array === 'undefined' ? [] : new Uint8Array(256);
for (let i = 0; i < chars.length; i++) {
lookup[chars.charCodeAt(i)] = i;
}
const encode = (arraybuffer) => {
let bytes = new Uint8Array(arraybuffer), i, len = bytes.length, base64 = '';
for (i = 0; i < len; i += 3) {
base64 += chars[bytes[i] >> 2];
base64 += chars[((bytes[i] & 3) << 4) | (bytes[i + 1] >> 4)];
base64 += chars[((bytes[i + 1] & 15) << 2) | (bytes[i + 2] >> 6)];
base64 += chars[bytes[i + 2] & 63];
}
if (len % 3 === 2) {
base64 = base64.substring(0, base64.length - 1) + '=';
}
else if (len % 3 === 1) {
base64 = base64.substring(0, base64.length - 2) + '==';
}
return base64;
};
exports.encode = encode;
const decode = (base64) => {
let bufferLength = base64.length * 0.75, len = base64.length, i, p = 0, encoded1, encoded2, encoded3, encoded4;
if (base64[base64.length - 1] === '=') {
bufferLength--;
if (base64[base64.length - 2] === '=') {
bufferLength--;
}
}
const arraybuffer = new ArrayBuffer(bufferLength), bytes = new Uint8Array(arraybuffer);
for (i = 0; i < len; i += 4) {
encoded1 = lookup[base64.charCodeAt(i)];
encoded2 = lookup[base64.charCodeAt(i + 1)];
encoded3 = lookup[base64.charCodeAt(i + 2)];
encoded4 = lookup[base64.charCodeAt(i + 3)];
bytes[p++] = (encoded1 << 2) | (encoded2 >> 4);
bytes[p++] = ((encoded2 & 15) << 4) | (encoded3 >> 2);
bytes[p++] = ((encoded3 & 3) << 6) | (encoded4 & 63);
}
return arraybuffer;
};
exports.decode = decode;

View file

@ -0,0 +1,2 @@
import { Packet, BinaryType, RawData } from "./commons.js";
export declare const decodePacket: (encodedPacket: RawData, binaryType?: BinaryType) => Packet;

View file

@ -0,0 +1,66 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.decodePacket = void 0;
const commons_js_1 = require("./commons.js");
const base64_arraybuffer_js_1 = require("./contrib/base64-arraybuffer.js");
const withNativeArrayBuffer = typeof ArrayBuffer === "function";
const decodePacket = (encodedPacket, binaryType) => {
if (typeof encodedPacket !== "string") {
return {
type: "message",
data: mapBinary(encodedPacket, binaryType),
};
}
const type = encodedPacket.charAt(0);
if (type === "b") {
return {
type: "message",
data: decodeBase64Packet(encodedPacket.substring(1), binaryType),
};
}
const packetType = commons_js_1.PACKET_TYPES_REVERSE[type];
if (!packetType) {
return commons_js_1.ERROR_PACKET;
}
return encodedPacket.length > 1
? {
type: commons_js_1.PACKET_TYPES_REVERSE[type],
data: encodedPacket.substring(1),
}
: {
type: commons_js_1.PACKET_TYPES_REVERSE[type],
};
};
exports.decodePacket = decodePacket;
const decodeBase64Packet = (data, binaryType) => {
if (withNativeArrayBuffer) {
const decoded = (0, base64_arraybuffer_js_1.decode)(data);
return mapBinary(decoded, binaryType);
}
else {
return { base64: true, data }; // fallback for old browsers
}
};
const mapBinary = (data, binaryType) => {
switch (binaryType) {
case "blob":
if (data instanceof Blob) {
// from WebSocket + binaryType "blob"
return data;
}
else {
// from HTTP long-polling or WebTransport
return new Blob([data]);
}
case "arraybuffer":
default:
if (data instanceof ArrayBuffer) {
// from HTTP long-polling (base64) or WebSocket + binaryType "arraybuffer"
return data;
}
else {
// from WebTransport (Uint8Array)
return data.buffer;
}
}
};

View file

@ -0,0 +1,2 @@
import { Packet, BinaryType, RawData } from "./commons.js";
export declare const decodePacket: (encodedPacket: RawData, binaryType?: BinaryType) => Packet;

View file

@ -0,0 +1,59 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.decodePacket = void 0;
const commons_js_1 = require("./commons.js");
const decodePacket = (encodedPacket, binaryType) => {
if (typeof encodedPacket !== "string") {
return {
type: "message",
data: mapBinary(encodedPacket, binaryType),
};
}
const type = encodedPacket.charAt(0);
if (type === "b") {
const buffer = Buffer.from(encodedPacket.substring(1), "base64");
return {
type: "message",
data: mapBinary(buffer, binaryType),
};
}
if (!commons_js_1.PACKET_TYPES_REVERSE[type]) {
return commons_js_1.ERROR_PACKET;
}
return encodedPacket.length > 1
? {
type: commons_js_1.PACKET_TYPES_REVERSE[type],
data: encodedPacket.substring(1),
}
: {
type: commons_js_1.PACKET_TYPES_REVERSE[type],
};
};
exports.decodePacket = decodePacket;
const mapBinary = (data, binaryType) => {
switch (binaryType) {
case "arraybuffer":
if (data instanceof ArrayBuffer) {
// from WebSocket & binaryType "arraybuffer"
return data;
}
else if (Buffer.isBuffer(data)) {
// from HTTP long-polling
return data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
}
else {
// from WebTransport (Uint8Array)
return data.buffer;
}
case "nodebuffer":
default:
if (Buffer.isBuffer(data)) {
// from HTTP long-polling or WebSocket & binaryType "nodebuffer" (default)
return data;
}
else {
// from WebTransport (Uint8Array)
return Buffer.from(data);
}
}
};

View file

@ -0,0 +1,4 @@
import { Packet, RawData } from "./commons.js";
declare const encodePacket: ({ type, data }: Packet, supportsBinary: boolean, callback: (encodedPacket: RawData) => void) => void;
export declare function encodePacketToBinary(packet: Packet, callback: (encodedPacket: RawData) => void): void | Promise<void>;
export { encodePacket };

View file

@ -0,0 +1,72 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.encodePacket = exports.encodePacketToBinary = void 0;
const commons_js_1 = require("./commons.js");
const withNativeBlob = typeof Blob === "function" ||
(typeof Blob !== "undefined" &&
Object.prototype.toString.call(Blob) === "[object BlobConstructor]");
const withNativeArrayBuffer = typeof ArrayBuffer === "function";
// ArrayBuffer.isView method is not defined in IE10
const isView = (obj) => {
return typeof ArrayBuffer.isView === "function"
? ArrayBuffer.isView(obj)
: obj && obj.buffer instanceof ArrayBuffer;
};
const encodePacket = ({ type, data }, supportsBinary, callback) => {
if (withNativeBlob && data instanceof Blob) {
if (supportsBinary) {
return callback(data);
}
else {
return encodeBlobAsBase64(data, callback);
}
}
else if (withNativeArrayBuffer &&
(data instanceof ArrayBuffer || isView(data))) {
if (supportsBinary) {
return callback(data);
}
else {
return encodeBlobAsBase64(new Blob([data]), callback);
}
}
// plain string
return callback(commons_js_1.PACKET_TYPES[type] + (data || ""));
};
exports.encodePacket = encodePacket;
const encodeBlobAsBase64 = (data, callback) => {
const fileReader = new FileReader();
fileReader.onload = function () {
const content = fileReader.result.split(",")[1];
callback("b" + (content || ""));
};
return fileReader.readAsDataURL(data);
};
function toArray(data) {
if (data instanceof Uint8Array) {
return data;
}
else if (data instanceof ArrayBuffer) {
return new Uint8Array(data);
}
else {
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
}
}
let TEXT_ENCODER;
function encodePacketToBinary(packet, callback) {
if (withNativeBlob && packet.data instanceof Blob) {
return packet.data.arrayBuffer().then(toArray).then(callback);
}
else if (withNativeArrayBuffer &&
(packet.data instanceof ArrayBuffer || isView(packet.data))) {
return callback(toArray(packet.data));
}
encodePacket(packet, false, (encoded) => {
if (!TEXT_ENCODER) {
TEXT_ENCODER = new TextEncoder();
}
callback(TEXT_ENCODER.encode(encoded));
});
}
exports.encodePacketToBinary = encodePacketToBinary;

View file

@ -0,0 +1,3 @@
import { Packet, RawData } from "./commons.js";
export declare const encodePacket: ({ type, data }: Packet, supportsBinary: boolean, callback: (encodedPacket: RawData) => void) => void;
export declare function encodePacketToBinary(packet: Packet, callback: (encodedPacket: RawData) => void): void;

View file

@ -0,0 +1,38 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.encodePacketToBinary = exports.encodePacket = void 0;
const commons_js_1 = require("./commons.js");
const encodePacket = ({ type, data }, supportsBinary, callback) => {
if (data instanceof ArrayBuffer || ArrayBuffer.isView(data)) {
return callback(supportsBinary ? data : "b" + toBuffer(data, true).toString("base64"));
}
// plain string
return callback(commons_js_1.PACKET_TYPES[type] + (data || ""));
};
exports.encodePacket = encodePacket;
const toBuffer = (data, forceBufferConversion) => {
if (Buffer.isBuffer(data) ||
(data instanceof Uint8Array && !forceBufferConversion)) {
return data;
}
else if (data instanceof ArrayBuffer) {
return Buffer.from(data);
}
else {
return Buffer.from(data.buffer, data.byteOffset, data.byteLength);
}
};
let TEXT_ENCODER;
function encodePacketToBinary(packet, callback) {
if (packet.data instanceof ArrayBuffer || ArrayBuffer.isView(packet.data)) {
return callback(toBuffer(packet.data, false));
}
(0, exports.encodePacket)(packet, true, (encoded) => {
if (!TEXT_ENCODER) {
// lazily created for compatibility with Node.js 10
TEXT_ENCODER = new TextEncoder();
}
callback(TEXT_ENCODER.encode(encoded));
});
}
exports.encodePacketToBinary = encodePacketToBinary;

11
my-app/node_modules/engine.io-parser/build/cjs/index.d.ts generated vendored Executable file
View file

@ -0,0 +1,11 @@
/// <reference types="node" />
import { encodePacket } from "./encodePacket.js";
import { decodePacket } from "./decodePacket.js";
import { Packet, PacketType, RawData, BinaryType } from "./commons.js";
import type { TransformStream } from "node:stream/web";
declare const encodePayload: (packets: Packet[], callback: (encodedPayload: string) => void) => void;
declare const decodePayload: (encodedPayload: string, binaryType?: BinaryType) => Packet[];
export declare function createPacketEncoderStream(): TransformStream<Packet, any>;
export declare function createPacketDecoderStream(maxPayload: number, binaryType: BinaryType): TransformStream<Uint8Array, any>;
export declare const protocol = 4;
export { encodePacket, encodePayload, decodePacket, decodePayload, Packet, PacketType, RawData, BinaryType, };

166
my-app/node_modules/engine.io-parser/build/cjs/index.js generated vendored Executable file
View file

@ -0,0 +1,166 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.decodePayload = exports.decodePacket = exports.encodePayload = exports.encodePacket = exports.protocol = exports.createPacketDecoderStream = exports.createPacketEncoderStream = void 0;
const encodePacket_js_1 = require("./encodePacket.js");
Object.defineProperty(exports, "encodePacket", { enumerable: true, get: function () { return encodePacket_js_1.encodePacket; } });
const decodePacket_js_1 = require("./decodePacket.js");
Object.defineProperty(exports, "decodePacket", { enumerable: true, get: function () { return decodePacket_js_1.decodePacket; } });
const commons_js_1 = require("./commons.js");
const SEPARATOR = String.fromCharCode(30); // see https://en.wikipedia.org/wiki/Delimiter#ASCII_delimited_text
const encodePayload = (packets, callback) => {
// some packets may be added to the array while encoding, so the initial length must be saved
const length = packets.length;
const encodedPackets = new Array(length);
let count = 0;
packets.forEach((packet, i) => {
// force base64 encoding for binary packets
(0, encodePacket_js_1.encodePacket)(packet, false, (encodedPacket) => {
encodedPackets[i] = encodedPacket;
if (++count === length) {
callback(encodedPackets.join(SEPARATOR));
}
});
});
};
exports.encodePayload = encodePayload;
const decodePayload = (encodedPayload, binaryType) => {
const encodedPackets = encodedPayload.split(SEPARATOR);
const packets = [];
for (let i = 0; i < encodedPackets.length; i++) {
const decodedPacket = (0, decodePacket_js_1.decodePacket)(encodedPackets[i], binaryType);
packets.push(decodedPacket);
if (decodedPacket.type === "error") {
break;
}
}
return packets;
};
exports.decodePayload = decodePayload;
function createPacketEncoderStream() {
// @ts-expect-error
return new TransformStream({
transform(packet, controller) {
(0, encodePacket_js_1.encodePacketToBinary)(packet, (encodedPacket) => {
const payloadLength = encodedPacket.length;
let header;
// inspired by the WebSocket format: https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_servers#decoding_payload_length
if (payloadLength < 126) {
header = new Uint8Array(1);
new DataView(header.buffer).setUint8(0, payloadLength);
}
else if (payloadLength < 65536) {
header = new Uint8Array(3);
const view = new DataView(header.buffer);
view.setUint8(0, 126);
view.setUint16(1, payloadLength);
}
else {
header = new Uint8Array(9);
const view = new DataView(header.buffer);
view.setUint8(0, 127);
view.setBigUint64(1, BigInt(payloadLength));
}
// first bit indicates whether the payload is plain text (0) or binary (1)
if (packet.data && typeof packet.data !== "string") {
header[0] |= 0x80;
}
controller.enqueue(header);
controller.enqueue(encodedPacket);
});
},
});
}
exports.createPacketEncoderStream = createPacketEncoderStream;
let TEXT_DECODER;
function totalLength(chunks) {
return chunks.reduce((acc, chunk) => acc + chunk.length, 0);
}
function concatChunks(chunks, size) {
if (chunks[0].length === size) {
return chunks.shift();
}
const buffer = new Uint8Array(size);
let j = 0;
for (let i = 0; i < size; i++) {
buffer[i] = chunks[0][j++];
if (j === chunks[0].length) {
chunks.shift();
j = 0;
}
}
if (chunks.length && j < chunks[0].length) {
chunks[0] = chunks[0].slice(j);
}
return buffer;
}
function createPacketDecoderStream(maxPayload, binaryType) {
if (!TEXT_DECODER) {
TEXT_DECODER = new TextDecoder();
}
const chunks = [];
let state = 0 /* READ_HEADER */;
let expectedLength = -1;
let isBinary = false;
// @ts-expect-error
return new TransformStream({
transform(chunk, controller) {
chunks.push(chunk);
while (true) {
if (state === 0 /* READ_HEADER */) {
if (totalLength(chunks) < 1) {
break;
}
const header = concatChunks(chunks, 1);
isBinary = (header[0] & 0x80) === 0x80;
expectedLength = header[0] & 0x7f;
if (expectedLength < 126) {
state = 3 /* READ_PAYLOAD */;
}
else if (expectedLength === 126) {
state = 1 /* READ_EXTENDED_LENGTH_16 */;
}
else {
state = 2 /* READ_EXTENDED_LENGTH_64 */;
}
}
else if (state === 1 /* READ_EXTENDED_LENGTH_16 */) {
if (totalLength(chunks) < 2) {
break;
}
const headerArray = concatChunks(chunks, 2);
expectedLength = new DataView(headerArray.buffer, headerArray.byteOffset, headerArray.length).getUint16(0);
state = 3 /* READ_PAYLOAD */;
}
else if (state === 2 /* READ_EXTENDED_LENGTH_64 */) {
if (totalLength(chunks) < 8) {
break;
}
const headerArray = concatChunks(chunks, 8);
const view = new DataView(headerArray.buffer, headerArray.byteOffset, headerArray.length);
const n = view.getUint32(0);
if (n > Math.pow(2, 53 - 32) - 1) {
// the maximum safe integer in JavaScript is 2^53 - 1
controller.enqueue(commons_js_1.ERROR_PACKET);
break;
}
expectedLength = n * Math.pow(2, 32) + view.getUint32(4);
state = 3 /* READ_PAYLOAD */;
}
else {
if (totalLength(chunks) < expectedLength) {
break;
}
const data = concatChunks(chunks, expectedLength);
controller.enqueue((0, decodePacket_js_1.decodePacket)(isBinary ? data : TEXT_DECODER.decode(data), binaryType));
state = 0 /* READ_HEADER */;
}
if (expectedLength === 0 || expectedLength > maxPayload) {
controller.enqueue(commons_js_1.ERROR_PACKET);
break;
}
}
},
});
}
exports.createPacketDecoderStream = createPacketDecoderStream;
exports.protocol = 4;

View file

@ -0,0 +1,8 @@
{
"name": "engine.io-parser",
"type": "commonjs",
"browser": {
"./encodePacket.js": "./encodePacket.browser.js",
"./decodePacket.js": "./decodePacket.browser.js"
}
}

14
my-app/node_modules/engine.io-parser/build/esm/commons.d.ts generated vendored Executable file
View file

@ -0,0 +1,14 @@
declare const PACKET_TYPES: any;
declare const PACKET_TYPES_REVERSE: any;
declare const ERROR_PACKET: Packet;
export { PACKET_TYPES, PACKET_TYPES_REVERSE, ERROR_PACKET };
export declare type PacketType = "open" | "close" | "ping" | "pong" | "message" | "upgrade" | "noop" | "error";
export declare type RawData = any;
export interface Packet {
type: PacketType;
options?: {
compress: boolean;
};
data?: RawData;
}
export declare type BinaryType = "nodebuffer" | "arraybuffer" | "blob";

14
my-app/node_modules/engine.io-parser/build/esm/commons.js generated vendored Executable file
View file

@ -0,0 +1,14 @@
const PACKET_TYPES = Object.create(null); // no Map = no polyfill
PACKET_TYPES["open"] = "0";
PACKET_TYPES["close"] = "1";
PACKET_TYPES["ping"] = "2";
PACKET_TYPES["pong"] = "3";
PACKET_TYPES["message"] = "4";
PACKET_TYPES["upgrade"] = "5";
PACKET_TYPES["noop"] = "6";
const PACKET_TYPES_REVERSE = Object.create(null);
Object.keys(PACKET_TYPES).forEach((key) => {
PACKET_TYPES_REVERSE[PACKET_TYPES[key]] = key;
});
const ERROR_PACKET = { type: "error", data: "parser error" };
export { PACKET_TYPES, PACKET_TYPES_REVERSE, ERROR_PACKET };

View file

@ -0,0 +1,2 @@
export declare const encode: (arraybuffer: ArrayBuffer) => string;
export declare const decode: (base64: string) => ArrayBuffer;

View file

@ -0,0 +1,43 @@
// imported from https://github.com/socketio/base64-arraybuffer
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
// Use a lookup table to find the index.
const lookup = typeof Uint8Array === 'undefined' ? [] : new Uint8Array(256);
for (let i = 0; i < chars.length; i++) {
lookup[chars.charCodeAt(i)] = i;
}
export const encode = (arraybuffer) => {
let bytes = new Uint8Array(arraybuffer), i, len = bytes.length, base64 = '';
for (i = 0; i < len; i += 3) {
base64 += chars[bytes[i] >> 2];
base64 += chars[((bytes[i] & 3) << 4) | (bytes[i + 1] >> 4)];
base64 += chars[((bytes[i + 1] & 15) << 2) | (bytes[i + 2] >> 6)];
base64 += chars[bytes[i + 2] & 63];
}
if (len % 3 === 2) {
base64 = base64.substring(0, base64.length - 1) + '=';
}
else if (len % 3 === 1) {
base64 = base64.substring(0, base64.length - 2) + '==';
}
return base64;
};
export const decode = (base64) => {
let bufferLength = base64.length * 0.75, len = base64.length, i, p = 0, encoded1, encoded2, encoded3, encoded4;
if (base64[base64.length - 1] === '=') {
bufferLength--;
if (base64[base64.length - 2] === '=') {
bufferLength--;
}
}
const arraybuffer = new ArrayBuffer(bufferLength), bytes = new Uint8Array(arraybuffer);
for (i = 0; i < len; i += 4) {
encoded1 = lookup[base64.charCodeAt(i)];
encoded2 = lookup[base64.charCodeAt(i + 1)];
encoded3 = lookup[base64.charCodeAt(i + 2)];
encoded4 = lookup[base64.charCodeAt(i + 3)];
bytes[p++] = (encoded1 << 2) | (encoded2 >> 4);
bytes[p++] = ((encoded2 & 15) << 4) | (encoded3 >> 2);
bytes[p++] = ((encoded3 & 3) << 6) | (encoded4 & 63);
}
return arraybuffer;
};

View file

@ -0,0 +1,2 @@
import { Packet, BinaryType, RawData } from "./commons.js";
export declare const decodePacket: (encodedPacket: RawData, binaryType?: BinaryType) => Packet;

View file

@ -0,0 +1,62 @@
import { ERROR_PACKET, PACKET_TYPES_REVERSE, } from "./commons.js";
import { decode } from "./contrib/base64-arraybuffer.js";
const withNativeArrayBuffer = typeof ArrayBuffer === "function";
export const decodePacket = (encodedPacket, binaryType) => {
if (typeof encodedPacket !== "string") {
return {
type: "message",
data: mapBinary(encodedPacket, binaryType),
};
}
const type = encodedPacket.charAt(0);
if (type === "b") {
return {
type: "message",
data: decodeBase64Packet(encodedPacket.substring(1), binaryType),
};
}
const packetType = PACKET_TYPES_REVERSE[type];
if (!packetType) {
return ERROR_PACKET;
}
return encodedPacket.length > 1
? {
type: PACKET_TYPES_REVERSE[type],
data: encodedPacket.substring(1),
}
: {
type: PACKET_TYPES_REVERSE[type],
};
};
const decodeBase64Packet = (data, binaryType) => {
if (withNativeArrayBuffer) {
const decoded = decode(data);
return mapBinary(decoded, binaryType);
}
else {
return { base64: true, data }; // fallback for old browsers
}
};
const mapBinary = (data, binaryType) => {
switch (binaryType) {
case "blob":
if (data instanceof Blob) {
// from WebSocket + binaryType "blob"
return data;
}
else {
// from HTTP long-polling or WebTransport
return new Blob([data]);
}
case "arraybuffer":
default:
if (data instanceof ArrayBuffer) {
// from HTTP long-polling (base64) or WebSocket + binaryType "arraybuffer"
return data;
}
else {
// from WebTransport (Uint8Array)
return data.buffer;
}
}
};

View file

@ -0,0 +1,2 @@
import { Packet, BinaryType, RawData } from "./commons.js";
export declare const decodePacket: (encodedPacket: RawData, binaryType?: BinaryType) => Packet;

View file

@ -0,0 +1,55 @@
import { ERROR_PACKET, PACKET_TYPES_REVERSE, } from "./commons.js";
export const decodePacket = (encodedPacket, binaryType) => {
if (typeof encodedPacket !== "string") {
return {
type: "message",
data: mapBinary(encodedPacket, binaryType),
};
}
const type = encodedPacket.charAt(0);
if (type === "b") {
const buffer = Buffer.from(encodedPacket.substring(1), "base64");
return {
type: "message",
data: mapBinary(buffer, binaryType),
};
}
if (!PACKET_TYPES_REVERSE[type]) {
return ERROR_PACKET;
}
return encodedPacket.length > 1
? {
type: PACKET_TYPES_REVERSE[type],
data: encodedPacket.substring(1),
}
: {
type: PACKET_TYPES_REVERSE[type],
};
};
const mapBinary = (data, binaryType) => {
switch (binaryType) {
case "arraybuffer":
if (data instanceof ArrayBuffer) {
// from WebSocket & binaryType "arraybuffer"
return data;
}
else if (Buffer.isBuffer(data)) {
// from HTTP long-polling
return data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
}
else {
// from WebTransport (Uint8Array)
return data.buffer;
}
case "nodebuffer":
default:
if (Buffer.isBuffer(data)) {
// from HTTP long-polling or WebSocket & binaryType "nodebuffer" (default)
return data;
}
else {
// from WebTransport (Uint8Array)
return Buffer.from(data);
}
}
};

View file

@ -0,0 +1,4 @@
import { Packet, RawData } from "./commons.js";
declare const encodePacket: ({ type, data }: Packet, supportsBinary: boolean, callback: (encodedPacket: RawData) => void) => void;
export declare function encodePacketToBinary(packet: Packet, callback: (encodedPacket: RawData) => void): void | Promise<void>;
export { encodePacket };

View file

@ -0,0 +1,68 @@
import { PACKET_TYPES } from "./commons.js";
const withNativeBlob = typeof Blob === "function" ||
(typeof Blob !== "undefined" &&
Object.prototype.toString.call(Blob) === "[object BlobConstructor]");
const withNativeArrayBuffer = typeof ArrayBuffer === "function";
// ArrayBuffer.isView method is not defined in IE10
const isView = (obj) => {
return typeof ArrayBuffer.isView === "function"
? ArrayBuffer.isView(obj)
: obj && obj.buffer instanceof ArrayBuffer;
};
const encodePacket = ({ type, data }, supportsBinary, callback) => {
if (withNativeBlob && data instanceof Blob) {
if (supportsBinary) {
return callback(data);
}
else {
return encodeBlobAsBase64(data, callback);
}
}
else if (withNativeArrayBuffer &&
(data instanceof ArrayBuffer || isView(data))) {
if (supportsBinary) {
return callback(data);
}
else {
return encodeBlobAsBase64(new Blob([data]), callback);
}
}
// plain string
return callback(PACKET_TYPES[type] + (data || ""));
};
const encodeBlobAsBase64 = (data, callback) => {
const fileReader = new FileReader();
fileReader.onload = function () {
const content = fileReader.result.split(",")[1];
callback("b" + (content || ""));
};
return fileReader.readAsDataURL(data);
};
function toArray(data) {
if (data instanceof Uint8Array) {
return data;
}
else if (data instanceof ArrayBuffer) {
return new Uint8Array(data);
}
else {
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
}
}
let TEXT_ENCODER;
export function encodePacketToBinary(packet, callback) {
if (withNativeBlob && packet.data instanceof Blob) {
return packet.data.arrayBuffer().then(toArray).then(callback);
}
else if (withNativeArrayBuffer &&
(packet.data instanceof ArrayBuffer || isView(packet.data))) {
return callback(toArray(packet.data));
}
encodePacket(packet, false, (encoded) => {
if (!TEXT_ENCODER) {
TEXT_ENCODER = new TextEncoder();
}
callback(TEXT_ENCODER.encode(encoded));
});
}
export { encodePacket };

View file

@ -0,0 +1,3 @@
import { Packet, RawData } from "./commons.js";
export declare const encodePacket: ({ type, data }: Packet, supportsBinary: boolean, callback: (encodedPacket: RawData) => void) => void;
export declare function encodePacketToBinary(packet: Packet, callback: (encodedPacket: RawData) => void): void;

View file

@ -0,0 +1,33 @@
import { PACKET_TYPES } from "./commons.js";
export const encodePacket = ({ type, data }, supportsBinary, callback) => {
if (data instanceof ArrayBuffer || ArrayBuffer.isView(data)) {
return callback(supportsBinary ? data : "b" + toBuffer(data, true).toString("base64"));
}
// plain string
return callback(PACKET_TYPES[type] + (data || ""));
};
const toBuffer = (data, forceBufferConversion) => {
if (Buffer.isBuffer(data) ||
(data instanceof Uint8Array && !forceBufferConversion)) {
return data;
}
else if (data instanceof ArrayBuffer) {
return Buffer.from(data);
}
else {
return Buffer.from(data.buffer, data.byteOffset, data.byteLength);
}
};
let TEXT_ENCODER;
export function encodePacketToBinary(packet, callback) {
if (packet.data instanceof ArrayBuffer || ArrayBuffer.isView(packet.data)) {
return callback(toBuffer(packet.data, false));
}
encodePacket(packet, true, (encoded) => {
if (!TEXT_ENCODER) {
// lazily created for compatibility with Node.js 10
TEXT_ENCODER = new TextEncoder();
}
callback(TEXT_ENCODER.encode(encoded));
});
}

11
my-app/node_modules/engine.io-parser/build/esm/index.d.ts generated vendored Executable file
View file

@ -0,0 +1,11 @@
/// <reference types="node" />
import { encodePacket } from "./encodePacket.js";
import { decodePacket } from "./decodePacket.js";
import { Packet, PacketType, RawData, BinaryType } from "./commons.js";
import type { TransformStream } from "node:stream/web";
declare const encodePayload: (packets: Packet[], callback: (encodedPayload: string) => void) => void;
declare const decodePayload: (encodedPayload: string, binaryType?: BinaryType) => Packet[];
export declare function createPacketEncoderStream(): TransformStream<Packet, any>;
export declare function createPacketDecoderStream(maxPayload: number, binaryType: BinaryType): TransformStream<Uint8Array, any>;
export declare const protocol = 4;
export { encodePacket, encodePayload, decodePacket, decodePayload, Packet, PacketType, RawData, BinaryType, };

158
my-app/node_modules/engine.io-parser/build/esm/index.js generated vendored Executable file
View file

@ -0,0 +1,158 @@
import { encodePacket, encodePacketToBinary } from "./encodePacket.js";
import { decodePacket } from "./decodePacket.js";
import { ERROR_PACKET, } from "./commons.js";
const SEPARATOR = String.fromCharCode(30); // see https://en.wikipedia.org/wiki/Delimiter#ASCII_delimited_text
const encodePayload = (packets, callback) => {
// some packets may be added to the array while encoding, so the initial length must be saved
const length = packets.length;
const encodedPackets = new Array(length);
let count = 0;
packets.forEach((packet, i) => {
// force base64 encoding for binary packets
encodePacket(packet, false, (encodedPacket) => {
encodedPackets[i] = encodedPacket;
if (++count === length) {
callback(encodedPackets.join(SEPARATOR));
}
});
});
};
const decodePayload = (encodedPayload, binaryType) => {
const encodedPackets = encodedPayload.split(SEPARATOR);
const packets = [];
for (let i = 0; i < encodedPackets.length; i++) {
const decodedPacket = decodePacket(encodedPackets[i], binaryType);
packets.push(decodedPacket);
if (decodedPacket.type === "error") {
break;
}
}
return packets;
};
export function createPacketEncoderStream() {
// @ts-expect-error
return new TransformStream({
transform(packet, controller) {
encodePacketToBinary(packet, (encodedPacket) => {
const payloadLength = encodedPacket.length;
let header;
// inspired by the WebSocket format: https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_servers#decoding_payload_length
if (payloadLength < 126) {
header = new Uint8Array(1);
new DataView(header.buffer).setUint8(0, payloadLength);
}
else if (payloadLength < 65536) {
header = new Uint8Array(3);
const view = new DataView(header.buffer);
view.setUint8(0, 126);
view.setUint16(1, payloadLength);
}
else {
header = new Uint8Array(9);
const view = new DataView(header.buffer);
view.setUint8(0, 127);
view.setBigUint64(1, BigInt(payloadLength));
}
// first bit indicates whether the payload is plain text (0) or binary (1)
if (packet.data && typeof packet.data !== "string") {
header[0] |= 0x80;
}
controller.enqueue(header);
controller.enqueue(encodedPacket);
});
},
});
}
let TEXT_DECODER;
function totalLength(chunks) {
return chunks.reduce((acc, chunk) => acc + chunk.length, 0);
}
function concatChunks(chunks, size) {
if (chunks[0].length === size) {
return chunks.shift();
}
const buffer = new Uint8Array(size);
let j = 0;
for (let i = 0; i < size; i++) {
buffer[i] = chunks[0][j++];
if (j === chunks[0].length) {
chunks.shift();
j = 0;
}
}
if (chunks.length && j < chunks[0].length) {
chunks[0] = chunks[0].slice(j);
}
return buffer;
}
export function createPacketDecoderStream(maxPayload, binaryType) {
if (!TEXT_DECODER) {
TEXT_DECODER = new TextDecoder();
}
const chunks = [];
let state = 0 /* READ_HEADER */;
let expectedLength = -1;
let isBinary = false;
// @ts-expect-error
return new TransformStream({
transform(chunk, controller) {
chunks.push(chunk);
while (true) {
if (state === 0 /* READ_HEADER */) {
if (totalLength(chunks) < 1) {
break;
}
const header = concatChunks(chunks, 1);
isBinary = (header[0] & 0x80) === 0x80;
expectedLength = header[0] & 0x7f;
if (expectedLength < 126) {
state = 3 /* READ_PAYLOAD */;
}
else if (expectedLength === 126) {
state = 1 /* READ_EXTENDED_LENGTH_16 */;
}
else {
state = 2 /* READ_EXTENDED_LENGTH_64 */;
}
}
else if (state === 1 /* READ_EXTENDED_LENGTH_16 */) {
if (totalLength(chunks) < 2) {
break;
}
const headerArray = concatChunks(chunks, 2);
expectedLength = new DataView(headerArray.buffer, headerArray.byteOffset, headerArray.length).getUint16(0);
state = 3 /* READ_PAYLOAD */;
}
else if (state === 2 /* READ_EXTENDED_LENGTH_64 */) {
if (totalLength(chunks) < 8) {
break;
}
const headerArray = concatChunks(chunks, 8);
const view = new DataView(headerArray.buffer, headerArray.byteOffset, headerArray.length);
const n = view.getUint32(0);
if (n > Math.pow(2, 53 - 32) - 1) {
// the maximum safe integer in JavaScript is 2^53 - 1
controller.enqueue(ERROR_PACKET);
break;
}
expectedLength = n * Math.pow(2, 32) + view.getUint32(4);
state = 3 /* READ_PAYLOAD */;
}
else {
if (totalLength(chunks) < expectedLength) {
break;
}
const data = concatChunks(chunks, expectedLength);
controller.enqueue(decodePacket(isBinary ? data : TEXT_DECODER.decode(data), binaryType));
state = 0 /* READ_HEADER */;
}
if (expectedLength === 0 || expectedLength > maxPayload) {
controller.enqueue(ERROR_PACKET);
break;
}
}
},
});
}
export const protocol = 4;
export { encodePacket, encodePayload, decodePacket, decodePayload, };

View file

@ -0,0 +1,8 @@
{
"name": "engine.io-parser",
"type": "module",
"browser": {
"./encodePacket.js": "./encodePacket.browser.js",
"./decodePacket.js": "./decodePacket.browser.js"
}
}

59
my-app/node_modules/engine.io-parser/package.json generated vendored Executable file
View file

@ -0,0 +1,59 @@
{
"name": "engine.io-parser",
"description": "Parser for the client for the realtime Engine",
"license": "MIT",
"version": "5.2.2",
"main": "./build/cjs/index.js",
"module": "./build/esm/index.js",
"exports": {
"import": "./build/esm/index.js",
"require": "./build/cjs/index.js"
},
"types": "build/esm/index.d.ts",
"homepage": "https://github.com/socketio/engine.io-parser",
"devDependencies": {
"@babel/core": "~7.9.6",
"@babel/preset-env": "~7.9.6",
"@types/mocha": "^9.0.0",
"@types/node": "^16.9.6",
"babelify": "^10.0.0",
"benchmark": "^2.1.4",
"expect.js": "0.3.1",
"mocha": "^5.2.0",
"nyc": "~15.0.1",
"prettier": "^3.2.5",
"rimraf": "^3.0.2",
"socket.io-browsers": "^1.0.4",
"ts-node": "^10.2.1",
"tsify": "^5.0.4",
"typescript": "^4.4.3",
"zuul": "3.11.1",
"zuul-ngrok": "4.0.0"
},
"scripts": {
"compile": "rimraf ./build && tsc && tsc -p tsconfig.esm.json && ./postcompile.sh",
"test": "npm run format:check && npm run compile && if test \"$BROWSERS\" = \"1\" ; then npm run test:browser; else npm run test:node; fi",
"test:node": "nyc mocha -r ts-node/register test/index.ts",
"test:browser": "zuul test/index.ts --no-coverage",
"format:check": "prettier --check 'lib/**/*.ts' 'test/**/*.ts'",
"format:fix": "prettier --write 'lib/**/*.ts' 'test/**/*.ts'",
"prepack": "npm run compile"
},
"repository": {
"type": "git",
"url": "git@github.com:socketio/engine.io-parser.git"
},
"files": [
"build/"
],
"browser": {
"./test/node": "./test/browser",
"./build/esm/encodePacket.js": "./build/esm/encodePacket.browser.js",
"./build/esm/decodePacket.js": "./build/esm/decodePacket.browser.js",
"./build/cjs/encodePacket.js": "./build/cjs/encodePacket.browser.js",
"./build/cjs/decodePacket.js": "./build/cjs/decodePacket.browser.js"
},
"engines": {
"node": ">=10.0.0"
}
}