|
| 1 | +/** |
| 2 | + * @typedef {{ port: number; host?: string; timeout?: number; localAddress?: string, localPort?: number, interface?: 'wifi', reuseAddress?: boolean}} ConnectionOptions |
| 3 | + */ |
| 4 | +export default class TcpSocket { |
| 5 | + /** |
| 6 | + * Initialices a TcpSocket. |
| 7 | + * |
| 8 | + * @param {number} id |
| 9 | + * @param {import('react-native').NativeEventEmitter} eventEmitter |
| 10 | + */ |
| 11 | + constructor(id: number, eventEmitter: import("react-native").NativeEventEmitter); |
| 12 | + _id: number; |
| 13 | + _eventEmitter: import("react-native").NativeEventEmitter; |
| 14 | + /** @type {number} */ |
| 15 | + _state: number; |
| 16 | + /** @type {RemovableListener[]} */ |
| 17 | + _listeners: RemovableListener[]; |
| 18 | + /** |
| 19 | + * Adds a listener to be invoked when events of the specified type are emitted by the `TcpSocket`. |
| 20 | + * An optional calling `context` may be provided. |
| 21 | + * The data arguments emitted will be passed to the listener callback. |
| 22 | + * |
| 23 | + * @param {string} event Name of the event to listen to |
| 24 | + * @param {(arg0: any) => void} callback Function to invoke when the specified event is emitted |
| 25 | + * @param {any} [context] Optional context object to use when invoking the listener |
| 26 | + * @returns {RemovableListener} |
| 27 | + */ |
| 28 | + on(event: string, callback: (arg0: any) => void, context?: any): RemovableListener; |
| 29 | + /** |
| 30 | + * @private |
| 31 | + * @param {string} event |
| 32 | + * @param {function(any):void} callback |
| 33 | + * @param {any} [context] |
| 34 | + */ |
| 35 | + private _selectListener; |
| 36 | + /** |
| 37 | + * @deprecated |
| 38 | + */ |
| 39 | + off(): void; |
| 40 | + /** |
| 41 | + * @param {ConnectionOptions} options |
| 42 | + * @param {(address: string) => void} [callback] |
| 43 | + */ |
| 44 | + connect(options: { |
| 45 | + port: number; |
| 46 | + host?: string | undefined; |
| 47 | + timeout?: number | undefined; |
| 48 | + localAddress?: string | undefined; |
| 49 | + localPort?: number | undefined; |
| 50 | + interface?: "wifi" | undefined; |
| 51 | + reuseAddress?: boolean | undefined; |
| 52 | + }, callback?: ((address: string) => void) | undefined): TcpSocket; |
| 53 | + _destroyed: boolean | undefined; |
| 54 | + /** |
| 55 | + * @private |
| 56 | + * @param {number} msecs |
| 57 | + * @param {() => void} [wrapper] |
| 58 | + */ |
| 59 | + private _activeTimer; |
| 60 | + _timeout: { |
| 61 | + handle: NodeJS.Timeout; |
| 62 | + wrapper: () => void; |
| 63 | + msecs: number; |
| 64 | + } | null | undefined; |
| 65 | + /** |
| 66 | + * @private |
| 67 | + */ |
| 68 | + private _clearTimeout; |
| 69 | + /** |
| 70 | + * @deprecated |
| 71 | + * @param {number} msecs |
| 72 | + * @param {(...args: any[]) => void } [callback] |
| 73 | + */ |
| 74 | + setTimeout(msecs: number, callback?: ((...args: any[]) => void) | undefined): TcpSocket; |
| 75 | + address(): string | undefined; |
| 76 | + /** |
| 77 | + * @param {string | Buffer | Uint8Array} data |
| 78 | + * @param {BufferEncoding} [encoding] |
| 79 | + */ |
| 80 | + end(data: string | Buffer | Uint8Array, encoding?: "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex" | undefined): void; |
| 81 | + destroy(): void; |
| 82 | + /** |
| 83 | + * @protected |
| 84 | + */ |
| 85 | + protected _registerEvents(): void; |
| 86 | + /** |
| 87 | + * @private |
| 88 | + */ |
| 89 | + private _unregisterEvents; |
| 90 | + /** |
| 91 | + * @private |
| 92 | + * @param {string} address |
| 93 | + */ |
| 94 | + private _onConnect; |
| 95 | + /** |
| 96 | + * @private |
| 97 | + */ |
| 98 | + private _onClose; |
| 99 | + /** |
| 100 | + * @private |
| 101 | + */ |
| 102 | + private _onError; |
| 103 | + /** |
| 104 | + * Sends data on the socket. The second parameter specifies the encoding in the case of a string — it defaults to UTF8 encoding. |
| 105 | + * |
| 106 | + * The optional callback parameter will be executed when the data is finally written out, which may not be immediately. |
| 107 | + * |
| 108 | + * @param {string | Buffer | Uint8Array} buffer |
| 109 | + * @param {BufferEncoding} [encoding] |
| 110 | + * @param {(error: string | null) => void} [callback] |
| 111 | + */ |
| 112 | + write(buffer: string | Buffer | Uint8Array, encoding?: "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex" | undefined, callback?: ((error: string | null) => void) | undefined): void; |
| 113 | + /** |
| 114 | + * @param {string} address |
| 115 | + */ |
| 116 | + setAsAlreadyConnected(address: string): void; |
| 117 | + /** |
| 118 | + * @private |
| 119 | + * @param {string | Buffer | Uint8Array} buffer |
| 120 | + * @param {BufferEncoding} [encoding] |
| 121 | + */ |
| 122 | + private _generateSendBuffer; |
| 123 | + /** |
| 124 | + * @private |
| 125 | + * @param {string} address |
| 126 | + */ |
| 127 | + private setConnected; |
| 128 | + _address: string | undefined; |
| 129 | + /** |
| 130 | + * @private |
| 131 | + */ |
| 132 | + private setDisconnected; |
| 133 | +} |
| 134 | +export type ConnectionOptions = { |
| 135 | + port: number; |
| 136 | + host?: string | undefined; |
| 137 | + timeout?: number | undefined; |
| 138 | + localAddress?: string | undefined; |
| 139 | + localPort?: number | undefined; |
| 140 | + interface?: "wifi" | undefined; |
| 141 | + reuseAddress?: boolean | undefined; |
| 142 | +}; |
| 143 | +declare class RemovableListener { |
| 144 | + /** |
| 145 | + * @param {import("react-native").EmitterSubscription} listener |
| 146 | + * @param {import("react-native").NativeEventEmitter} eventEmitter |
| 147 | + */ |
| 148 | + constructor(listener: import("react-native").EmitterSubscription, eventEmitter: import("react-native").NativeEventEmitter); |
| 149 | + _listener: import("react-native").EmitterSubscription; |
| 150 | + _eventEmitter: import("react-native").NativeEventEmitter; |
| 151 | + _removed: boolean; |
| 152 | + isRemoved(): boolean; |
| 153 | + remove(): void; |
| 154 | +} |
| 155 | +export {}; |
0 commit comments