4.2.4 • Published 10 months ago

socket.io-parser v4.2.4

Weekly downloads
7,772,701
License
MIT
Repository
github
Last release
10 months ago

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

3.4.3

10 months ago

4.2.3

10 months ago

4.2.4

10 months ago

4.2.2

1 year ago

3.4.2

1 year ago

3.3.3

1 year ago

4.0.5

2 years ago

4.2.1

2 years ago

4.2.0

2 years ago

4.1.2

2 years ago

4.1.0

2 years ago

4.1.1

2 years ago

4.0.4

3 years ago

3.3.2

3 years ago

4.0.3

3 years ago

4.0.2

3 years ago

4.0.1

3 years ago

4.0.1-rc3

3 years ago

4.0.1-rc2

3 years ago

4.0.1-rc1

3 years ago

3.3.1

3 years ago

4.0.0

3 years ago

3.4.1

4 years ago

3.4.0

5 years ago

3.3.0

5 years ago

3.2.0

6 years ago

3.1.3

6 years ago

3.1.2

7 years ago

3.1.1

7 years ago

3.1.0

7 years ago

3.0.0

7 years ago

2.3.2

7 years ago

2.3.1

7 years ago

2.3.0

7 years ago

2.2.6

8 years ago

2.2.5

8 years ago

2.2.4

9 years ago

2.2.3

9 years ago

2.2.2

10 years ago

2.2.1

10 years ago

2.2.0

10 years ago

2.1.5

10 years ago

2.1.4

10 years ago

2.1.3

10 years ago

2.1.2

10 years ago

2.1.1

10 years ago

2.1.0

10 years ago

2.0.0

10 years ago

1.1.2

10 years ago

1.1.1

10 years ago

1.1.0

10 years ago

1.0.2

11 years ago

1.0.1

11 years ago