socket.io-parser
    Overview
    Documentation
    Tutorials
    Chat
    Insights
    Code
    Dependencies
    Contributors
    Jobs

socket.io-parser

socket.io protocol parser

3.3.0  •  Updated 1 years ago  •  by socketio  •  MIT License

socket.io-parser

Build Status NPM version

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

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

Popularity

Maintenance

Development

Last ver 1 year ago
Created 7 years ago
Last commit 7 months ago
16 days between commits

Technology

Node version: 10.9.0
16.5K unpacked

Compliance

MIT License
OSI Approved
0 vulnerabilities

Contributors

16 contributors
Guillermo Rauch
Maintainer, 52 commits, 21 merges
Works at https://zeit.co
Damien Arrachequesne
Maintainer, 38 commits, 31 merges, 25 PRs
Kevin Roark
14 commits, 10 PRs
Naoyuki Kanezawa
Maintainer, 6 commits, 2 merges, 4 PRs
Works at zeit
Tony Kovanen
6 commits
Gatsbill
3 commits, 3 PRs
Works at Gatsbill
Openbase helps developers choose among and use millions of open-source packages, so they can build amazing products faster.
FacebookTwitterLinkedIn
© 2020 Devstore, Inc.