socket.io-parser
socket.io protocol parser
Last updated 4 years ago by darrachequesne .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install socket.io-parser 
SYNC missed versions from official npm registry.

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 version Socket.IO server version Protocol revision
3.x 1.x / 2.x 4
4.x 3.x 5

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

Current Tags

  • 4.0.1-rc3                                ...           beta (4 years ago)
  • 3.3.4                                ...           latest (4 months ago)
  • 3.3.3                                ...           v2-latest (2 years ago)
  • 4.0.5                                ...           v4.0-latest (2 years ago)

54 Versions

  • 3.3.4                                ...           4 months ago
  • 4.2.4                                ...           a year ago
  • 3.4.3                                ...           a year ago
  • 4.2.3                                ...           a year ago
  • 4.2.2                                ...           2 years ago
  • 3.3.3                                ...           2 years ago
  • 3.4.2                                ...           2 years ago
  • 4.0.5                                ...           2 years ago
  • 4.2.1                                ...           2 years ago
  • 4.2.0                                ...           3 years ago
  • 4.1.2                                ...           3 years ago
  • 4.1.1                                ...           3 years ago
  • 4.1.0                                ...           3 years ago
  • 4.0.4                                ...           4 years ago
  • 3.3.2                                ...           4 years ago
  • 4.0.3                                ...           4 years ago
  • 4.0.2                                ...           4 years ago
  • 4.0.1                                ...           4 years ago
  • 4.0.1-rc3                                ...           4 years ago
  • 4.0.1-rc2                                ...           4 years ago
  • 4.0.1-rc1                                ...           4 years ago
  • 3.3.1                                ...           4 years ago
  • 4.0.0                                ...           4 years ago
  • 3.4.1                                ...           5 years ago
  • 3.4.0                                ...           5 years ago
  • 3.3.0                                ...           6 years ago
  • 3.2.0                                ...           7 years ago
  • 3.1.3                                ...           7 years ago
  • 3.1.2                                ...           8 years ago
  • 3.1.1                                ...           8 years ago
  • 3.1.0                                ...           8 years ago
  • 3.0.0                                ...           8 years ago
  • 2.3.2                                ...           8 years ago
  • 2.3.1                                ...           8 years ago
  • 2.3.0                                ...           8 years ago
  • 2.2.6                                ...           9 years ago
  • 2.2.5                                ...           9 years ago
  • 2.2.4                                ...           10 years ago
  • 2.2.3                                ...           10 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                                ...           11 years ago
  • 2.1.2                                ...           11 years ago
  • 2.1.1                                ...           11 years ago
  • 2.1.0                                ...           11 years ago
  • 2.0.0                                ...           11 years ago
  • 1.1.2                                ...           11 years ago
  • 1.1.1                                ...           11 years ago
  • 1.1.0                                ...           11 years ago
  • 1.0.2                                ...           12 years ago
  • 1.0.1                                ...           12 years ago
Downloads
Total 1
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (3)
Dev Dependencies (6)

© 2010 - cnpmjs.org x YWFE | Home | YWFE