Big update!Introducing GitHub Bot Commands. Learn more
Socket
Log inBook a demo

socket.io-parser

Package Overview
Dependencies
2
Maintainers
2
Versions
49
Issues
File Explorer

Advanced tools

socket.io-parser

socket.io protocol parser

    4.2.1latest

Version published
Maintainers
2
Weekly downloads
6,090,365
decreased by-24.64%

Weekly downloads

Changelog

Source

4.2.1 (2022-06-27)

Bug Fixes

  • check the format of the index of each attachment (b5d0cb7)

Features

  • allow the usage of custom replacer and reviver (#112) (b08bc1a)

Readme

Source

socket.io-parser

Build Status NPM version

A socket.io encoder and decoder written in JavaScript complying with version 5 of socket.io-protocol. Used by socket.io and socket.io-client.

Compatibility table:

Parser versionSocket.IO server versionProtocol revision
3.x1.x / 2.x4
4.x3.x5

Parser API

socket.io-parser is the reference implementation of socket.io-protocol. Read the full API here: socket.io-protocol.

Example Usage

Encoding and decoding a packet

var parser = require('socket.io-parser'); var encoder = new parser.Encoder(); var packet = { type: parser.EVENT, data: 'test-packet', id: 13 }; encoder.encode(packet, function(encodedPackets) { var decoder = new parser.Decoder(); decoder.on('decoded', function(decodedPacket) { // decodedPacket.type == parser.EVENT // decodedPacket.data == 'test-packet' // decodedPacket.id == 13 }); for (var i = 0; i < encodedPackets.length; i++) { decoder.add(encodedPackets[i]); } });

Encoding and decoding a packet with binary data

var parser = require('socket.io-parser'); var encoder = new parser.Encoder(); var packet = { type: parser.BINARY_EVENT, data: {i: new Buffer(1234), j: new Blob([new ArrayBuffer(2)])}, id: 15 }; encoder.encode(packet, function(encodedPackets) { var decoder = new parser.Decoder(); decoder.on('decoded', function(decodedPacket) { // decodedPacket.type == parser.BINARY_EVENT // Buffer.isBuffer(decodedPacket.data.i) == true // Buffer.isBuffer(decodedPacket.data.j) == true // decodedPacket.id == 15 }); for (var i = 0; i < encodedPackets.length; i++) { decoder.add(encodedPackets[i]); } });

See the test suite for more examples of how socket.io-parser is used.

License

MIT

FAQs

What is socket.io-parser?

socket.io protocol parser

Is socket.io-parser popular?

The npm package socket.io-parser receives a total of 5,053,374 weekly downloads. As such, socket.io-parser popularity was classified as popular.

Is socket.io-parser well maintained?

We found that socket.io-parser demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.It has 2 open source maintainers collaborating on the project.

Last updated on 27 Jun 2022

Did you know?

Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install Socket
Socket

Product

Subscribe to our newsletter

Get open source security insights delivered straight into your inbox. Be the first to learn about new features and product updates.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc