client.d.ts 2.8 KB

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