33 *
44 * @typedef {import('react-native').NativeEventEmitter } NativeEventEmitter
55 *
6+ * @typedef {{address: string, family: string, port: number} } AddressInfo
7+ *
8+ * @typedef {{localAddress: string, localPort: number, remoteAddress: string, remotePort: number, remoteFamily: string} } NativeConnectionInfo
9+ *
610 * @typedef {{
711 * port: number;
812 * host?: string;
1519 * tlsCheckValidity?: boolean,
1620 * tlsCert?: any,
1721 * }} ConnectionOptions
22+ *
23+ * @extends {EventEmitter<'connect' | 'timeout' | 'data' | 'error' | 'close', any> }
1824 */
19- export default class TcpSocket extends EventEmitter {
25+ export default class TcpSocket extends EventEmitter < "connect" | "timeout" | "data" | "error" | "close" , any > {
2026 /**
2127 * Initialices a TcpSocket.
2228 *
2329 * @param {number } id
2430 * @param {NativeEventEmitter } eventEmitter
25- * @param {string } [address ]
31+ * @param {NativeConnectionInfo } [connectionInfo ]
2632 */
27- constructor ( id : number , eventEmitter : NativeEventEmitter , address ?: string | undefined ) ;
28- /** @protected */
29- protected _id : number ;
30- /** @protected */
31- protected _eventEmitter : import ( "react-native" ) . NativeEventEmitter ;
33+ constructor ( id : number , eventEmitter : NativeEventEmitter , connectionInfo ?: NativeConnectionInfo | undefined ) ;
34+ /** @private */
35+ private _id ;
36+ /** @private */
37+ private _eventEmitter ;
3238 /** @type {number } @private */
3339 private _timeoutMsecs ;
3440 /** @private */
@@ -37,23 +43,16 @@ export default class TcpSocket extends EventEmitter {
3743 private _state ;
3844 /** @private */
3945 private _encoding ;
40- /**
41- * @protected
42- */
43- protected _registerEvents ( ) : void ;
44- _dataListener : import ( "react-native" ) . EmitterSubscription | undefined ;
45- _errorListener : import ( "react-native" ) . EmitterSubscription | undefined ;
46- _closeListener : import ( "react-native" ) . EmitterSubscription | undefined ;
47- _connectListener : import ( "react-native" ) . EmitterSubscription | undefined ;
48- /**
49- * @protected
50- */
51- protected _unregisterEvents ( ) : void ;
46+ localAddress : string | undefined ;
47+ localPort : number | undefined ;
48+ remoteAddress : string | undefined ;
49+ remotePort : number | undefined ;
50+ remoteFamily : string | undefined ;
5251 /**
5352 * @param {ConnectionOptions } options
54- * @param {(address: string ) => void } [callback]
53+ * @param {() => void } [callback]
5554 */
56- connect ( options : ConnectionOptions , callback ?: ( ( address : string ) => void ) | undefined ) : TcpSocket ;
55+ connect ( options : ConnectionOptions , callback ?: ( ( ) => void ) | undefined ) : TcpSocket ;
5756 _destroyed : boolean | undefined ;
5857 /**
5958 * Sets the socket to timeout after `timeout` milliseconds of inactivity on the socket. By default `TcpSocket` do not have a timeout.
@@ -107,26 +106,19 @@ export default class TcpSocket extends EventEmitter {
107106 * @param {number } initialDelay ***IGNORED**. Default: `0`
108107 */
109108 setKeepAlive ( enable ?: boolean , initialDelay ?: number ) : TcpSocket ;
110- address ( ) : string | undefined ;
109+ /**
110+ * Returns the bound `address`, the address `family` name and `port` of the socket as reported
111+ * by the operating system: `{ port: 12346, family: 'IPv4', address: '127.0.0.1' }`.
112+ *
113+ * @returns {AddressInfo | {} }
114+ */
115+ address ( ) : AddressInfo | { } ;
111116 /**
112117 * @param {string | Buffer | Uint8Array } data
113118 * @param {BufferEncoding } [encoding]
114119 */
115120 end ( data : string | Buffer | Uint8Array , encoding ?: "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex" | undefined ) : void ;
116121 destroy ( ) : void ;
117- /**
118- * @private
119- * @param {string } address
120- */
121- private _onConnect ;
122- /**
123- * @private
124- */
125- private _onClose ;
126- /**
127- * @private
128- */
129- private _onError ;
130122 /**
131123 * Sends data on the socket. The second parameter specifies the encoding in the case of a string — it defaults to UTF8 encoding.
132124 *
@@ -137,6 +129,20 @@ export default class TcpSocket extends EventEmitter {
137129 * @param {(error: string | null) => void } [callback]
138130 */
139131 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 ;
132+ ref ( ) : void ;
133+ unref ( ) : void ;
134+ /**
135+ * @private
136+ */
137+ private _registerEvents ;
138+ _dataListener : import ( "react-native" ) . EmitterSubscription | undefined ;
139+ _errorListener : import ( "react-native" ) . EmitterSubscription | undefined ;
140+ _closeListener : import ( "react-native" ) . EmitterSubscription | undefined ;
141+ _connectListener : import ( "react-native" ) . EmitterSubscription | undefined ;
142+ /**
143+ * @private
144+ */
145+ private _unregisterEvents ;
140146 /**
141147 * @private
142148 * @param {string | Buffer | Uint8Array } buffer
@@ -145,19 +151,28 @@ export default class TcpSocket extends EventEmitter {
145151 private _generateSendBuffer ;
146152 /**
147153 * @private
148- * @param {string } address
154+ * @param {NativeConnectionInfo } connectionInfo
149155 */
150156 private _setConnected ;
151- _address : string | undefined ;
152157 /**
153158 * @private
154159 */
155160 private _setDisconnected ;
156- ref ( ) : void ;
157- unref ( ) : void ;
158161}
159162export type BufferEncoding = "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex" ;
160163export type NativeEventEmitter = import ( "react-native" ) . NativeEventEmitter ;
164+ export type AddressInfo = {
165+ address : string ;
166+ family : string ;
167+ port : number ;
168+ } ;
169+ export type NativeConnectionInfo = {
170+ localAddress : string ;
171+ localPort : number ;
172+ remoteAddress : string ;
173+ remotePort : number ;
174+ remoteFamily : string ;
175+ } ;
161176export type ConnectionOptions = {
162177 port : number ;
163178 host ?: string | undefined ;
@@ -170,5 +185,5 @@ export type ConnectionOptions = {
170185 tlsCheckValidity ?: boolean | undefined ;
171186 tlsCert ?: any ;
172187} ;
173- import { EventEmitter } from "events " ;
188+ import EventEmitter from "eventemitter3 " ;
174189import { Buffer } from "buffer" ;
0 commit comments