You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Pau aff9d08cee client 1 year ago
lib client 1 year ago client 1 year ago
LICENSE client 1 year ago client 1 year ago
package.json client 1 year ago

Build Status NPM version

This is the JavaScript parser for the protocol encoding, shared by both and

How to use


The parser can encode/decode packets, payloads, and payloads as binary with the following methods: encodePacket, decodePacket, encodePayload, decodePayload.


const parser = require("");
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:

  1. install the parser package

    npm install
  2. write your app code

    const parser = require("");
    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 => {
        (packet, index, total) => {
          const isLast = index + 1 == total;
          if (!isLast) {
            const buffer = new Int8Array(; // testBuffer
          } else {
            const message =; // "hello"
  3. build your app bundle

    $ browserify app.js > bundle.js
  4. include on your page

    <script src="/path/to/bundle.js"></script>


  • 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


Note: cb(type) means the type is a callback function that contains a parameter of type type when called.


  • 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))


Standalone tests can be run with npm test which will run the node.js tests.

Browser tests are run using zuul. (You must have zuul setup with a saucelabs account.)

You can run the tests locally using the following command:

npm run test:browser


The support channels for are the same as


To contribute patches, run tests or benchmarks, make sure to clone the repository:

git clone git://


npm ci

See the Tests section above for how to run tests before submitting any patches.