Skip to content

Commit 3ccc1ce

Browse files
committed
Compile latest code - 4.2.3
`npm run compile`
1 parent 89b8dfb commit 3ccc1ce

23 files changed

+1678
-4
lines changed

build/cjs/binary.d.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Replaces every Buffer | ArrayBuffer | Blob | File in packet with a numbered placeholder.
3+
*
4+
* @param {Object} packet - socket.io event packet
5+
* @return {Object} with deconstructed packet and list of buffers
6+
* @public
7+
*/
8+
export declare function deconstructPacket(packet: any): {
9+
packet: any;
10+
buffers: any[];
11+
};
12+
/**
13+
* Reconstructs a binary packet from its placeholder packet and buffers
14+
*
15+
* @param {Object} packet - event packet with placeholders
16+
* @param {Array} buffers - binary buffers to put in placeholder positions
17+
* @return {Object} reconstructed packet
18+
* @public
19+
*/
20+
export declare function reconstructPacket(packet: any, buffers: any): any;

build/cjs/binary.js

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.reconstructPacket = exports.deconstructPacket = void 0;
4+
const is_binary_js_1 = require("./is-binary.js");
5+
/**
6+
* Replaces every Buffer | ArrayBuffer | Blob | File in packet with a numbered placeholder.
7+
*
8+
* @param {Object} packet - socket.io event packet
9+
* @return {Object} with deconstructed packet and list of buffers
10+
* @public
11+
*/
12+
function deconstructPacket(packet) {
13+
const buffers = [];
14+
const packetData = packet.data;
15+
const pack = packet;
16+
pack.data = _deconstructPacket(packetData, buffers);
17+
pack.attachments = buffers.length; // number of binary 'attachments'
18+
return { packet: pack, buffers: buffers };
19+
}
20+
exports.deconstructPacket = deconstructPacket;
21+
function _deconstructPacket(data, buffers) {
22+
if (!data)
23+
return data;
24+
if ((0, is_binary_js_1.isBinary)(data)) {
25+
const placeholder = { _placeholder: true, num: buffers.length };
26+
buffers.push(data);
27+
return placeholder;
28+
}
29+
else if (Array.isArray(data)) {
30+
const newData = new Array(data.length);
31+
for (let i = 0; i < data.length; i++) {
32+
newData[i] = _deconstructPacket(data[i], buffers);
33+
}
34+
return newData;
35+
}
36+
else if (typeof data === "object" && !(data instanceof Date)) {
37+
const newData = {};
38+
for (const key in data) {
39+
if (Object.prototype.hasOwnProperty.call(data, key)) {
40+
newData[key] = _deconstructPacket(data[key], buffers);
41+
}
42+
}
43+
return newData;
44+
}
45+
return data;
46+
}
47+
/**
48+
* Reconstructs a binary packet from its placeholder packet and buffers
49+
*
50+
* @param {Object} packet - event packet with placeholders
51+
* @param {Array} buffers - binary buffers to put in placeholder positions
52+
* @return {Object} reconstructed packet
53+
* @public
54+
*/
55+
function reconstructPacket(packet, buffers) {
56+
packet.data = _reconstructPacket(packet.data, buffers);
57+
delete packet.attachments; // no longer useful
58+
return packet;
59+
}
60+
exports.reconstructPacket = reconstructPacket;
61+
function _reconstructPacket(data, buffers) {
62+
if (!data)
63+
return data;
64+
if (data && data._placeholder === true) {
65+
const isIndexValid = typeof data.num === "number" &&
66+
data.num >= 0 &&
67+
data.num < buffers.length;
68+
if (isIndexValid) {
69+
return buffers[data.num]; // appropriate buffer (should be natural order anyway)
70+
}
71+
else {
72+
throw new Error("illegal attachments");
73+
}
74+
}
75+
else if (Array.isArray(data)) {
76+
for (let i = 0; i < data.length; i++) {
77+
data[i] = _reconstructPacket(data[i], buffers);
78+
}
79+
}
80+
else if (typeof data === "object") {
81+
for (const key in data) {
82+
if (Object.prototype.hasOwnProperty.call(data, key)) {
83+
data[key] = _reconstructPacket(data[key], buffers);
84+
}
85+
}
86+
}
87+
return data;
88+
}

build/cjs/index.d.ts

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import { Emitter } from "@socket.io/component-emitter";
2+
/**
3+
* Protocol version.
4+
*
5+
* @public
6+
*/
7+
export declare const protocol: number;
8+
export declare const metricsEmitter: Emitter<import("@socket.io/component-emitter").EventsMap, import("@socket.io/component-emitter").EventsMap, {}>;
9+
export declare enum PacketType {
10+
CONNECT = 0,
11+
DISCONNECT = 1,
12+
EVENT = 2,
13+
ACK = 3,
14+
CONNECT_ERROR = 4,
15+
BINARY_EVENT = 5,
16+
BINARY_ACK = 6
17+
}
18+
export interface Packet {
19+
type: PacketType;
20+
nsp: string;
21+
data?: any;
22+
id?: number;
23+
attachments?: number;
24+
}
25+
/**
26+
* A socket.io Encoder instance
27+
*/
28+
export declare class Encoder {
29+
private replacer?;
30+
/**
31+
* Encoder constructor
32+
*
33+
* @param {function} replacer - custom replacer to pass down to JSON.parse
34+
*/
35+
constructor(replacer?: (this: any, key: string, value: any) => any);
36+
/**
37+
* Encode a packet as a single string if non-binary, or as a
38+
* buffer sequence, depending on packet type.
39+
*
40+
* @param {Object} obj - packet object
41+
*/
42+
encode(obj: Packet): any[];
43+
/**
44+
* Encode packet as string.
45+
*/
46+
private encodeAsString;
47+
/**
48+
* Encode packet as 'buffer sequence' by removing blobs, and
49+
* deconstructing packet into object with placeholders and
50+
* a list of buffers.
51+
*/
52+
private encodeAsBinary;
53+
}
54+
interface DecoderReservedEvents {
55+
decoded: (packet: Packet) => void;
56+
}
57+
/**
58+
* A socket.io Decoder instance
59+
*
60+
* @return {Object} decoder
61+
*/
62+
export declare class Decoder extends Emitter<{}, {}, DecoderReservedEvents> {
63+
private reviver?;
64+
private reconstructor;
65+
/**
66+
* Decoder constructor
67+
*
68+
* @param {function} reviver - custom reviver to pass down to JSON.stringify
69+
*/
70+
constructor(reviver?: (this: any, key: string, value: any) => any);
71+
/**
72+
* Decodes an encoded packet string into packet JSON.
73+
*
74+
* @param {String} obj - encoded packet
75+
*/
76+
add(obj: any): void;
77+
/**
78+
* Decode a packet String (JSON data)
79+
*
80+
* @param {String} str
81+
* @return {Object} packet
82+
*/
83+
private decodeString;
84+
private tryParse;
85+
private static isPayloadValid;
86+
/**
87+
* Deallocates a parser's resources
88+
*/
89+
destroy(): void;
90+
}
91+
export {};

0 commit comments

Comments
 (0)