polling.d.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import { Transport } from "../transport.js";
  2. import { RawData } from "engine.io-parser";
  3. import { Emitter } from "@socket.io/component-emitter";
  4. export declare class Polling extends Transport {
  5. private readonly xd;
  6. private polling;
  7. private pollXhr;
  8. private cookieJar?;
  9. /**
  10. * XHR Polling constructor.
  11. *
  12. * @param {Object} opts
  13. * @package
  14. */
  15. constructor(opts: any);
  16. get name(): string;
  17. /**
  18. * Opens the socket (triggers polling). We write a PING message to determine
  19. * when the transport is open.
  20. *
  21. * @protected
  22. */
  23. doOpen(): void;
  24. /**
  25. * Pauses polling.
  26. *
  27. * @param {Function} onPause - callback upon buffers are flushed and transport is paused
  28. * @package
  29. */
  30. pause(onPause: any): void;
  31. /**
  32. * Starts polling cycle.
  33. *
  34. * @private
  35. */
  36. poll(): void;
  37. /**
  38. * Overloads onData to detect payloads.
  39. *
  40. * @protected
  41. */
  42. onData(data: any): void;
  43. /**
  44. * For polling, send a close packet.
  45. *
  46. * @protected
  47. */
  48. doClose(): void;
  49. /**
  50. * Writes a packets payload.
  51. *
  52. * @param {Array} packets - data packets
  53. * @protected
  54. */
  55. write(packets: any): void;
  56. /**
  57. * Generates uri for connection.
  58. *
  59. * @private
  60. */
  61. private uri;
  62. /**
  63. * Creates a request.
  64. *
  65. * @param {String} method
  66. * @private
  67. */
  68. request(opts?: {}): Request;
  69. /**
  70. * Sends data.
  71. *
  72. * @param {String} data to send.
  73. * @param {Function} called upon flush.
  74. * @private
  75. */
  76. private doWrite;
  77. /**
  78. * Starts a poll cycle.
  79. *
  80. * @private
  81. */
  82. private doPoll;
  83. }
  84. interface RequestReservedEvents {
  85. success: () => void;
  86. data: (data: RawData) => void;
  87. error: (err: number | Error, context: unknown) => void;
  88. }
  89. export declare class Request extends Emitter<{}, {}, RequestReservedEvents> {
  90. private readonly opts;
  91. private readonly method;
  92. private readonly uri;
  93. private readonly data;
  94. private xhr;
  95. private setTimeoutFn;
  96. private index;
  97. static requestsCount: number;
  98. static requests: {};
  99. /**
  100. * Request constructor
  101. *
  102. * @param {Object} options
  103. * @package
  104. */
  105. constructor(uri: any, opts: any);
  106. /**
  107. * Creates the XHR object and sends the request.
  108. *
  109. * @private
  110. */
  111. private create;
  112. /**
  113. * Called upon error.
  114. *
  115. * @private
  116. */
  117. private onError;
  118. /**
  119. * Cleans up house.
  120. *
  121. * @private
  122. */
  123. private cleanup;
  124. /**
  125. * Called upon load.
  126. *
  127. * @private
  128. */
  129. private onLoad;
  130. /**
  131. * Aborts the request.
  132. *
  133. * @package
  134. */
  135. abort(): void;
  136. }
  137. export {};