5.2.2 • Published 3 months ago

engine.io-parser v5.2.2

Weekly downloads
5,373,143
License
MIT
Repository
github
Last release
3 months ago

engine.io-parser

Build Status NPM version

This is the JavaScript parser for the engine.io protocol encoding, shared by both engine.io-client and 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:

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:

  1. install the parser package

    npm install engine.io-parser
  2. write your app code

    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"
          }
        });
    });
  3. build your app bundle

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

    <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. (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:

Development

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

git clone git://github.com/socketio/engine.io-parser.git

Then:

cd engine.io-parser
npm ci

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

License

MIT

engine.io-clientengine.ioct-platform-backend@arisageha/react-lazyload@arisageha/react-lazyload-fixeni-chatlevibestliblevibestlib2levilibtest19levilibtest24levilibtest25levilibtest26levilibtest27levilibtest28levilibtest29unblock-block-save-variablescclibyarntestopea-bootstraap@everything-registry/sub-chunk-1586ondvue-dev-cloneweapp.engine.ioweapp.engine.io-clientweb-component-tester-bundlewc-starterkitwebdatabasetest1webdatabasetest10webliblevi3tna6-student-management-systemtoyakotestlib17testweblibapitest-build-engine.iotest-build-engine.io-clientvchatvideo-multi-uploadervcloudcam-playkit-js-hlsunderstanding-typescript-coursestock-ticker-react-widget@moony-engineering/messageclientwinx-form-winxwxapp-engine.io-client@k4connect/engine.io@k4connect/engine.io-client3.0.0@object-studio/react-native-web@niubalib/weapp.engine.io-client@parkcedar/leaflet@ngxvoice/ngx-voicelistner@sword-in-rose/engine.io-clientengine.io-browserengine.io-client-no-github-dependencyengine.io-client-privateengine.io-client-pureengine.io-client-test-sourcemapengine.io-client-uni-appengine.io-client-weexengine.io-client-wxmpengine.io-mp-clientengine.io-pureengine.io-wxapp-client@tylerbu/engine.io-client@kingsds/engine.io-client@lofcz/sweetalert2-neutral@thedoctor0/vuex-shared-mutations@seculum/vue-dev-clone@tf2autobot/engine.io-client@unibtc/engine.iogasm@alta-ng-timeago/hiamtanh-altafhir2@alesmenzel/engine.iofixed_form_builderfenglin-uploader@zalastax/nolb-enganydebugger@azure/web-pubsub-socket.ioapilibtestbge-devcclib1jeuxuibohrbox-wheather.js@ctfdio/picocss-themeska-flow.jscustom-engine.io-client-v3.4.4kotlinapitestkotlinapitest1kotlinapitest2custompackagetestvarthini@cdevine49/react-numeric-inputcordova-plugin-amplify-paycordova-plugin-amplify-paymentcordova-plugin-tspmultiplatformlevimp-engine.io-clientmyui5librarychenmyui5librarymobohive-multisig-sdk@depyronick/engine.io-client
5.2.2

3 months ago

5.2.1

9 months ago

5.2.0

9 months ago

5.1.0

11 months ago

5.0.7

11 months ago

5.0.6

1 year ago

5.0.5

1 year ago

5.0.4

2 years ago

5.0.3

2 years ago

5.0.2

2 years ago

5.0.1

3 years ago

5.0.0

3 years ago

4.0.3

3 years ago

4.0.2

3 years ago

2.2.1

4 years ago

4.0.1

4 years ago

4.0.0

4 years ago

4.0.0-alpha.1

4 years ago

4.0.0-alpha.0

4 years ago

2.2.0

5 years ago

2.1.3

5 years ago

2.1.2

6 years ago

2.1.1

7 years ago

2.1.0

7 years ago

2.0.3

7 years ago

2.0.2

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.3.2

7 years ago

1.3.1

8 years ago

1.3.0

8 years ago

1.2.4

8 years ago

1.2.3

8 years ago

1.2.2

9 years ago

1.2.1

9 years ago

1.2.0

9 years ago

1.1.0

10 years ago

1.0.8

10 years ago

1.0.7

10 years ago

1.0.6

10 years ago

1.0.5

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago

0.3.0

11 years ago

0.2.1

11 years ago

0.2.0

11 years ago

0.1.1

11 years ago

0.1.0

11 years ago