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 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. # engine.io-parser
  2. [![Build Status](https://github.com/socketio/engine.io-parser/workflows/CI/badge.svg)](https://github.com/socketio/engine.io-parser/actions)
  3. [![NPM version](https://badge.fury.io/js/engine.io-parser.svg)](https://npmjs.com/package/engine.io-parser)
  4. This is the JavaScript parser for the engine.io protocol encoding,
  5. shared by both
  6. [engine.io-client](https://github.com/socketio/engine.io-client) and
  7. [engine.io](https://github.com/socketio/engine.io).
  8. ## How to use
  9. ### Standalone
  10. The parser can encode/decode packets, payloads, and payloads as binary
  11. with the following methods: `encodePacket`, `decodePacket`, `encodePayload`,
  12. `decodePayload`.
  13. Example:
  14. ```js
  15. const parser = require("engine.io-parser");
  16. const data = Buffer.from([ 1, 2, 3, 4 ]);
  17. parser.encodePacket({ type: "message", data }, encoded => {
  18. const decodedData = parser.decodePacket(encoded); // decodedData === data
  19. });
  20. ```
  21. ### With browserify
  22. Engine.IO Parser is a commonjs module, which means you can include it by using
  23. `require` on the browser and package using [browserify](http://browserify.org/):
  24. 1. install the parser package
  25. ```shell
  26. npm install engine.io-parser
  27. ```
  28. 1. write your app code
  29. ```js
  30. const parser = require("engine.io-parser");
  31. const testBuffer = new Int8Array(10);
  32. for (let i = 0; i < testBuffer.length; i++) testBuffer[i] = i;
  33. const packets = [{ type: "message", data: testBuffer.buffer }, { type: "message", data: "hello" }];
  34. parser.encodePayload(packets, encoded => {
  35. parser.decodePayload(encoded,
  36. (packet, index, total) => {
  37. const isLast = index + 1 == total;
  38. if (!isLast) {
  39. const buffer = new Int8Array(packet.data); // testBuffer
  40. } else {
  41. const message = packet.data; // "hello"
  42. }
  43. });
  44. });
  45. ```
  46. 1. build your app bundle
  47. ```bash
  48. $ browserify app.js > bundle.js
  49. ```
  50. 1. include on your page
  51. ```html
  52. <script src="/path/to/bundle.js"></script>
  53. ```
  54. ## Features
  55. - Runs on browser and node.js seamlessly
  56. - Runs inside HTML5 WebWorker
  57. - Can encode and decode packets
  58. - Encodes from/to ArrayBuffer or Blob when in browser, and Buffer or ArrayBuffer in Node
  59. ## API
  60. Note: `cb(type)` means the type is a callback function that contains a parameter of type `type` when called.
  61. ### Node
  62. - `encodePacket`
  63. - Encodes a packet.
  64. - **Parameters**
  65. - `Object`: the packet to encode, has `type` and `data`.
  66. - `data`: can be a `String`, `Number`, `Buffer`, `ArrayBuffer`
  67. - `Boolean`: binary support
  68. - `Function`: callback, returns the encoded packet (`cb(String)`)
  69. - `decodePacket`
  70. - Decodes a packet. Data also available as an ArrayBuffer if requested.
  71. - Returns data as `String` or (`Blob` on browser, `ArrayBuffer` on Node)
  72. - **Parameters**
  73. - `String` | `ArrayBuffer`: the packet to decode, has `type` and `data`
  74. - `String`: optional, the binary type
  75. - `encodePayload`
  76. - Encodes multiple messages (payload).
  77. - If any contents are binary, they will be encoded as base64 strings. Base64
  78. encoded strings are marked with a b before the length specifier
  79. - **Parameters**
  80. - `Array`: an array of packets
  81. - `Function`: callback, returns the encoded payload (`cb(String)`)
  82. - `decodePayload`
  83. - Decodes data when a payload is maybe expected. Possible binary contents are
  84. decoded from their base64 representation.
  85. - **Parameters**
  86. - `String`: the payload
  87. - `Function`: callback, returns (cb(`Object`: packet, `Number`:packet index, `Number`:packet total))
  88. ## Tests
  89. Standalone tests can be run with `npm test` which will run the node.js tests.
  90. Browser tests are run using [zuul](https://github.com/defunctzombie/zuul).
  91. (You must have zuul setup with a saucelabs account.)
  92. You can run the tests locally using the following command:
  93. ```
  94. npm run test:browser
  95. ```
  96. ## Support
  97. The support channels for `engine.io-parser` are the same as `socket.io`:
  98. - irc.freenode.net **#socket.io**
  99. - [Github Discussions](https://github.com/socketio/socket.io/discussions)
  100. - [Website](https://socket.io)
  101. ## Development
  102. To contribute patches, run tests or benchmarks, make sure to clone the
  103. repository:
  104. ```bash
  105. git clone git://github.com/socketio/engine.io-parser.git
  106. ```
  107. Then:
  108. ```bash
  109. cd engine.io-parser
  110. npm ci
  111. ```
  112. See the `Tests` section above for how to run tests before submitting any patches.
  113. ## License
  114. MIT