Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Readme.md 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. # socket.io-parser
  2. [![Build Status](https://github.com/socketio/socket.io-parser/workflows/CI/badge.svg)](https://github.com/socketio/socket.io-parser/actions)
  3. [![NPM version](https://badge.fury.io/js/socket.io-parser.svg)](http://badge.fury.io/js/socket.io-parser)
  4. A socket.io encoder and decoder written in JavaScript complying with version `5`
  5. of [socket.io-protocol](https://github.com/socketio/socket.io-protocol).
  6. Used by [socket.io](https://github.com/automattic/socket.io) and
  7. [socket.io-client](https://github.com/automattic/socket.io-client).
  8. Compatibility table:
  9. | Parser version | Socket.IO server version | Protocol revision |
  10. |----------------| ------------------------ | ----------------- |
  11. | 3.x | 1.x / 2.x | 4 |
  12. | 4.x | 3.x | 5 |
  13. ## Parser API
  14. socket.io-parser is the reference implementation of socket.io-protocol. Read
  15. the full API here:
  16. [socket.io-protocol](https://github.com/learnboost/socket.io-protocol).
  17. ## Example Usage
  18. ### Encoding and decoding a packet
  19. ```js
  20. var parser = require('socket.io-parser');
  21. var encoder = new parser.Encoder();
  22. var packet = {
  23. type: parser.EVENT,
  24. data: 'test-packet',
  25. id: 13
  26. };
  27. encoder.encode(packet, function(encodedPackets) {
  28. var decoder = new parser.Decoder();
  29. decoder.on('decoded', function(decodedPacket) {
  30. // decodedPacket.type == parser.EVENT
  31. // decodedPacket.data == 'test-packet'
  32. // decodedPacket.id == 13
  33. });
  34. for (var i = 0; i < encodedPackets.length; i++) {
  35. decoder.add(encodedPackets[i]);
  36. }
  37. });
  38. ```
  39. ### Encoding and decoding a packet with binary data
  40. ```js
  41. var parser = require('socket.io-parser');
  42. var encoder = new parser.Encoder();
  43. var packet = {
  44. type: parser.BINARY_EVENT,
  45. data: {i: new Buffer(1234), j: new Blob([new ArrayBuffer(2)])},
  46. id: 15
  47. };
  48. encoder.encode(packet, function(encodedPackets) {
  49. var decoder = new parser.Decoder();
  50. decoder.on('decoded', function(decodedPacket) {
  51. // decodedPacket.type == parser.BINARY_EVENT
  52. // Buffer.isBuffer(decodedPacket.data.i) == true
  53. // Buffer.isBuffer(decodedPacket.data.j) == true
  54. // decodedPacket.id == 15
  55. });
  56. for (var i = 0; i < encodedPackets.length; i++) {
  57. decoder.add(encodedPackets[i]);
  58. }
  59. });
  60. ```
  61. See the test suite for more examples of how socket.io-parser is used.
  62. ## License
  63. MIT