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.

transport.js 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. const EventEmitter = require("events");
  2. const parser_v4 = require("engine.io-parser");
  3. const parser_v3 = require("./parser-v3/index");
  4. const debug = require("debug")("engine:transport");
  5. /**
  6. * Noop function.
  7. *
  8. * @api private
  9. */
  10. function noop() {}
  11. class Transport extends EventEmitter {
  12. /**
  13. * Transport constructor.
  14. *
  15. * @param {http.IncomingMessage} request
  16. * @api public
  17. */
  18. constructor(req) {
  19. super();
  20. this.readyState = "open";
  21. this.discarded = false;
  22. this.protocol = req._query.EIO === "4" ? 4 : 3; // 3rd revision by default
  23. this.parser = this.protocol === 4 ? parser_v4 : parser_v3;
  24. }
  25. /**
  26. * Flags the transport as discarded.
  27. *
  28. * @api private
  29. */
  30. discard() {
  31. this.discarded = true;
  32. }
  33. /**
  34. * Called with an incoming HTTP request.
  35. *
  36. * @param {http.IncomingMessage} request
  37. * @api private
  38. */
  39. onRequest(req) {
  40. debug("setting request");
  41. this.req = req;
  42. }
  43. /**
  44. * Closes the transport.
  45. *
  46. * @api private
  47. */
  48. close(fn) {
  49. if ("closed" === this.readyState || "closing" === this.readyState) return;
  50. this.readyState = "closing";
  51. this.doClose(fn || noop);
  52. }
  53. /**
  54. * Called with a transport error.
  55. *
  56. * @param {String} message error
  57. * @param {Object} error description
  58. * @api private
  59. */
  60. onError(msg, desc) {
  61. if (this.listeners("error").length) {
  62. const err = new Error(msg);
  63. err.type = "TransportError";
  64. err.description = desc;
  65. this.emit("error", err);
  66. } else {
  67. debug("ignored transport error %s (%s)", msg, desc);
  68. }
  69. }
  70. /**
  71. * Called with parsed out a packets from the data stream.
  72. *
  73. * @param {Object} packet
  74. * @api private
  75. */
  76. onPacket(packet) {
  77. this.emit("packet", packet);
  78. }
  79. /**
  80. * Called with the encoded packet data.
  81. *
  82. * @param {String} data
  83. * @api private
  84. */
  85. onData(data) {
  86. this.onPacket(this.parser.decodePacket(data));
  87. }
  88. /**
  89. * Called upon transport close.
  90. *
  91. * @api private
  92. */
  93. onClose() {
  94. this.readyState = "closed";
  95. this.emit("close");
  96. }
  97. }
  98. module.exports = Transport;