transport.d.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /// <reference types="node" />
  2. import { EventEmitter } from "events";
  3. import { IncomingMessage } from "http";
  4. import { Packet } from "engine.io-parser";
  5. declare type ReadyState = "open" | "closing" | "closed";
  6. export declare abstract class Transport extends EventEmitter {
  7. sid: string;
  8. writable: boolean;
  9. protocol: number;
  10. protected _readyState: ReadyState;
  11. protected discarded: boolean;
  12. protected parser: any;
  13. protected req: IncomingMessage & {
  14. cleanup: Function;
  15. };
  16. protected supportsBinary: boolean;
  17. get readyState(): ReadyState;
  18. set readyState(state: ReadyState);
  19. /**
  20. * Transport constructor.
  21. *
  22. * @param {http.IncomingMessage} req
  23. * @api public
  24. */
  25. constructor(req: any);
  26. /**
  27. * Flags the transport as discarded.
  28. *
  29. * @api private
  30. */
  31. discard(): void;
  32. /**
  33. * Called with an incoming HTTP request.
  34. *
  35. * @param {http.IncomingMessage} req
  36. * @api protected
  37. */
  38. protected onRequest(req: any): void;
  39. /**
  40. * Closes the transport.
  41. *
  42. * @api private
  43. */
  44. close(fn?: any): void;
  45. /**
  46. * Called with a transport error.
  47. *
  48. * @param {String} msg - message error
  49. * @param {Object} desc - error description
  50. * @api protected
  51. */
  52. protected onError(msg: string, desc?: any): void;
  53. /**
  54. * Called with parsed out a packets from the data stream.
  55. *
  56. * @param {Object} packet
  57. * @api protected
  58. */
  59. protected onPacket(packet: Packet): void;
  60. /**
  61. * Called with the encoded packet data.
  62. *
  63. * @param {String} data
  64. * @api protected
  65. */
  66. protected onData(data: any): void;
  67. /**
  68. * Called upon transport close.
  69. *
  70. * @api protected
  71. */
  72. protected onClose(): void;
  73. /**
  74. * Advertise framing support.
  75. */
  76. abstract get supportsFraming(): any;
  77. /**
  78. * The name of the transport.
  79. */
  80. abstract get name(): any;
  81. /**
  82. * Sends an array of packets.
  83. *
  84. * @param {Array} packets
  85. * @package
  86. */
  87. abstract send(packets: any): any;
  88. /**
  89. * Closes the transport.
  90. */
  91. abstract doClose(fn?: any): any;
  92. }
  93. export {};