source: trip-planner-front/node_modules/engine.io-parser/build/esm/index.js@ 8d391a1

Last change on this file since 8d391a1 was e29cc2e, checked in by Ema <ema_spirova@…>, 3 years ago

primeNG components

  • Property mode set to 100644
File size: 1.2 KB
Line 
1import encodePacket from "./encodePacket.js";
2import decodePacket from "./decodePacket.js";
3const SEPARATOR = String.fromCharCode(30); // see https://en.wikipedia.org/wiki/Delimiter#ASCII_delimited_text
4const encodePayload = (packets, callback) => {
5 // some packets may be added to the array while encoding, so the initial length must be saved
6 const length = packets.length;
7 const encodedPackets = new Array(length);
8 let count = 0;
9 packets.forEach((packet, i) => {
10 // force base64 encoding for binary packets
11 encodePacket(packet, false, encodedPacket => {
12 encodedPackets[i] = encodedPacket;
13 if (++count === length) {
14 callback(encodedPackets.join(SEPARATOR));
15 }
16 });
17 });
18};
19const decodePayload = (encodedPayload, binaryType) => {
20 const encodedPackets = encodedPayload.split(SEPARATOR);
21 const packets = [];
22 for (let i = 0; i < encodedPackets.length; i++) {
23 const decodedPacket = decodePacket(encodedPackets[i], binaryType);
24 packets.push(decodedPacket);
25 if (decodedPacket.type === "error") {
26 break;
27 }
28 }
29 return packets;
30};
31export const protocol = 4;
32export { encodePacket, encodePayload, decodePacket, decodePayload };
Note: See TracBrowser for help on using the repository browser.