client.d.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import { Packet } from "socket.io-parser";
  2. import type { IncomingMessage } from "http";
  3. import type { Server } from "./index";
  4. import type { EventsMap } from "./typed-events";
  5. import type { Socket } from "./socket";
  6. import type { Socket as RawSocket } from "engine.io";
  7. interface WriteOptions {
  8. compress?: boolean;
  9. volatile?: boolean;
  10. preEncoded?: boolean;
  11. wsPreEncoded?: string;
  12. }
  13. export declare class Client<ListenEvents extends EventsMap, EmitEvents extends EventsMap, ServerSideEvents extends EventsMap, SocketData = any> {
  14. readonly conn: RawSocket;
  15. private readonly id;
  16. private readonly server;
  17. private readonly encoder;
  18. private readonly decoder;
  19. private sockets;
  20. private nsps;
  21. private connectTimeout?;
  22. /**
  23. * Client constructor.
  24. *
  25. * @param server instance
  26. * @param conn
  27. * @package
  28. */
  29. constructor(server: Server<ListenEvents, EmitEvents, ServerSideEvents, SocketData>, conn: any);
  30. /**
  31. * @return the reference to the request that originated the Engine.IO connection
  32. *
  33. * @public
  34. */
  35. get request(): IncomingMessage;
  36. /**
  37. * Sets up event listeners.
  38. *
  39. * @private
  40. */
  41. private setup;
  42. /**
  43. * Connects a client to a namespace.
  44. *
  45. * @param {String} name - the namespace
  46. * @param {Object} auth - the auth parameters
  47. * @private
  48. */
  49. private connect;
  50. /**
  51. * Connects a client to a namespace.
  52. *
  53. * @param name - the namespace
  54. * @param {Object} auth - the auth parameters
  55. *
  56. * @private
  57. */
  58. private doConnect;
  59. /**
  60. * Disconnects from all namespaces and closes transport.
  61. *
  62. * @private
  63. */
  64. _disconnect(): void;
  65. /**
  66. * Removes a socket. Called by each `Socket`.
  67. *
  68. * @private
  69. */
  70. _remove(socket: Socket<ListenEvents, EmitEvents, ServerSideEvents, SocketData>): void;
  71. /**
  72. * Closes the underlying connection.
  73. *
  74. * @private
  75. */
  76. private close;
  77. /**
  78. * Writes a packet to the transport.
  79. *
  80. * @param {Object} packet object
  81. * @param {Object} opts
  82. * @private
  83. */
  84. _packet(packet: Packet | any[], opts?: WriteOptions): void;
  85. private writeToEngine;
  86. /**
  87. * Called with incoming transport data.
  88. *
  89. * @private
  90. */
  91. private ondata;
  92. /**
  93. * Called when parser fully decodes a packet.
  94. *
  95. * @private
  96. */
  97. private ondecoded;
  98. /**
  99. * Handles an error.
  100. *
  101. * @param {Object} err object
  102. * @private
  103. */
  104. private onerror;
  105. /**
  106. * Called upon transport close.
  107. *
  108. * @param reason
  109. * @param description
  110. * @private
  111. */
  112. private onclose;
  113. /**
  114. * Cleans up event listeners.
  115. * @private
  116. */
  117. private destroy;
  118. }
  119. export {};