|
| 1 | +/** |
| 2 | + * @extends {EventEmitter<'connection' | 'listening' | 'error' | 'close', any>} |
| 3 | + */ |
| 4 | +export default class Server extends EventEmitter<"error" | "close" | "connection" | "listening", any> { |
| 5 | + /** |
| 6 | + * @param {(socket: TcpSocket) => void} [connectionCallback] Automatically set as a listener for the `'connection'` event. |
| 7 | + */ |
| 8 | + constructor(connectionCallback?: ((socket: TcpSocket) => void) | undefined); |
| 9 | + /** @private */ |
| 10 | + private _id; |
| 11 | + /** @private */ |
| 12 | + private _eventEmitter; |
| 13 | + /** @private @type {TcpSocket[]} */ |
| 14 | + private _connections; |
| 15 | + /** @private */ |
| 16 | + private _localAddress; |
| 17 | + /** @private */ |
| 18 | + private _localPort; |
| 19 | + /** @private */ |
| 20 | + private _localFamily; |
| 21 | + listening: boolean; |
| 22 | + /** |
| 23 | + * Start a server listening for connections. |
| 24 | + * |
| 25 | + * This function is asynchronous. When the server starts listening, the `'listening'` event will be emitted. |
| 26 | + * The last parameter `callback` will be added as a listener for the `'listening'` event. |
| 27 | + * |
| 28 | + * The `server.listen()` method can be called again if and only if there was an error during the first |
| 29 | + * `server.listen()` call or `server.close()` has been called. Otherwise, an `ERR_SERVER_ALREADY_LISTEN` |
| 30 | + * error will be thrown. |
| 31 | + * |
| 32 | + * @param {{ port: number; host: string; reuseAddress?: boolean}} options |
| 33 | + * @param {() => void} [callback] |
| 34 | + * @returns {Server} |
| 35 | + */ |
| 36 | + listen(options: { |
| 37 | + port: number; |
| 38 | + host: string; |
| 39 | + reuseAddress?: boolean; |
| 40 | + }, callback?: (() => void) | undefined): Server; |
| 41 | + /** |
| 42 | + * Asynchronously get the number of concurrent connections on the server. |
| 43 | + * |
| 44 | + * Callback should take two arguments `err` and `count`. |
| 45 | + * |
| 46 | + * @param {(err: Error | null, count: number) => void} callback |
| 47 | + * @returns {Server} |
| 48 | + */ |
| 49 | + getConnections(callback: (err: Error | null, count: number) => void): Server; |
| 50 | + /** |
| 51 | + * Stops the server from accepting new connections and keeps existing connections. |
| 52 | + * This function is asynchronous, the server is finally closed when all connections are ended and the server emits a `'close'` event. |
| 53 | + * The optional callback will be called once the `'close'` event occurs. Unlike that event, it will be called with an `Error` as its |
| 54 | + * only argument if the server was not open when it was closed. |
| 55 | + * |
| 56 | + * @param {(err?: Error) => void} [callback] Called when the server is closed. |
| 57 | + * @returns {Server} |
| 58 | + */ |
| 59 | + close(callback?: ((err?: Error | undefined) => void) | undefined): Server; |
| 60 | + /** |
| 61 | + * Returns the bound `address`, the address `family` name, and `port` of the server as reported by the operating system if listening |
| 62 | + * on an IP socket (useful to find which port was assigned when getting an OS-assigned address): |
| 63 | + * `{ port: 12346, family: 'IPv4', address: '127.0.0.1' }`. |
| 64 | + * |
| 65 | + * @returns {import('./TcpSocket').AddressInfo | null} |
| 66 | + */ |
| 67 | + address(): import('./TcpSocket').AddressInfo | null; |
| 68 | + ref(): Server; |
| 69 | + unref(): Server; |
| 70 | + /** |
| 71 | + * @private |
| 72 | + */ |
| 73 | + private _registerEvents; |
| 74 | + _errorListener: import("react-native").EmitterSubscription | undefined; |
| 75 | + _closeListener: import("react-native").EmitterSubscription | undefined; |
| 76 | + _connectionsListener: import("react-native").EmitterSubscription | undefined; |
| 77 | + /** |
| 78 | + * @private |
| 79 | + */ |
| 80 | + private _unregisterEvents; |
| 81 | + /** |
| 82 | + * @private |
| 83 | + */ |
| 84 | + private _setDisconnected; |
| 85 | + /** |
| 86 | + * @private |
| 87 | + * @param {{ id: number; connection: import('./TcpSocket').NativeConnectionInfo; }} info |
| 88 | + */ |
| 89 | + private _buildSocket; |
| 90 | +} |
| 91 | +import EventEmitter from "eventemitter3"; |
| 92 | +import TcpSocket from "./TcpSocket"; |
0 commit comments