2020 * tlsCert?: any,
2121 * }} ConnectionOptions
2222 *
23- * @extends {EventEmitter<'connect' | 'timeout' | 'data' | 'error' | 'close', any> }
23+ * @typedef {object } ReadableEvents
24+ * @property {() => void } pause
25+ * @property {() => void } resume
26+ *
27+ * @typedef {object } SocketEvents
28+ * @property {(had_error: boolean) => void } close
29+ * @property {() => void } connect
30+ * @property {(data: Buffer | string) => void } data
31+ * @property {() => void } drain
32+ * @property {(err: Error) => void } error
33+ * @property {() => void } timeout
34+ *
35+ * @extends {EventEmitter<SocketEvents & ReadableEvents, any> }
2436 */
25- export default class Socket extends EventEmitter < "connect" | "timeout" | "data" | "error" | "close" , any > {
37+ export default class Socket extends EventEmitter < SocketEvents & ReadableEvents , any > {
2638 /** @private */
2739 private _id ;
2840 /** @private */
2941 private _eventEmitter ;
42+ /** @type {EventEmitter<'written', any> } @private */
43+ private _msgEvtEmitter ;
3044 /** @type {number } @private */
3145 private _timeoutMsecs ;
3246 /** @private */
@@ -35,6 +49,24 @@ export default class Socket extends EventEmitter<"connect" | "timeout" | "data"
3549 private _state ;
3650 /** @private */
3751 private _encoding ;
52+ /** @private */
53+ private _msgId ;
54+ /** @private */
55+ private _lastRcvMsgId ;
56+ /** @private */
57+ private _lastSentMsgId ;
58+ /** @private */
59+ private _paused ;
60+ /** @private */
61+ private _resuming ;
62+ /** @private */
63+ private _writeBufferSize ;
64+ /** @type {{ id: number; data: string; }[] } @private */
65+ private _pausedDataEvents ;
66+ readableHighWaterMark : number ;
67+ writableHighWaterMark : number ;
68+ writableNeedDrain : boolean ;
69+ bytesSent : number ;
3870 localAddress : string | undefined ;
3971 localPort : number | undefined ;
4072 remoteAddress : string | undefined ;
@@ -124,15 +156,36 @@ export default class Socket extends EventEmitter<"connect" | "timeout" | "data"
124156 /**
125157 * Sends data on the socket. The second parameter specifies the encoding in the case of a string — it defaults to UTF8 encoding.
126158 *
159+ * Returns `true` if the entire data was flushed successfully to the kernel buffer. Returns `false` if all or part of the data
160+ * was queued in user memory. `'drain'` will be emitted when the buffer is again free.
161+ *
127162 * The optional callback parameter will be executed when the data is finally written out, which may not be immediately.
128163 *
129164 * @param {string | Buffer | Uint8Array } buffer
130165 * @param {BufferEncoding } [encoding]
131- * @param {(error: string | null) => void } [callback]
166+ * @param {(err?: Error) => void } [cb]
167+ *
168+ * @return {boolean }
169+ */
170+ write ( buffer : string | Buffer | Uint8Array , encoding ?: "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex" | undefined , cb ?: ( ( err ?: Error | undefined ) => void ) | undefined ) : boolean ;
171+ /**
172+ * Pauses the reading of data. That is, `'data'` events will not be emitted. Useful to throttle back an upload.
173+ */
174+ pause ( ) : void ;
175+ /**
176+ * Resumes reading after a call to `socket.pause()`.
132177 */
133- 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 ;
178+ resume ( ) : void ;
134179 ref ( ) : void ;
135180 unref ( ) : void ;
181+ /**
182+ * @private
183+ */
184+ private _recoverDataEventsAfterPause ;
185+ /**
186+ * @private
187+ */
188+ private _onDeviceDataEvt ;
136189 /**
137190 * @private
138191 */
@@ -141,6 +194,7 @@ export default class Socket extends EventEmitter<"connect" | "timeout" | "data"
141194 _errorListener : import ( "react-native" ) . EmitterSubscription | undefined ;
142195 _closeListener : import ( "react-native" ) . EmitterSubscription | undefined ;
143196 _connectListener : import ( "react-native" ) . EmitterSubscription | undefined ;
197+ _writtenListener : import ( "react-native" ) . EmitterSubscription | undefined ;
144198 /**
145199 * @private
146200 */
@@ -182,5 +236,17 @@ export type ConnectionOptions = {
182236 tlsCheckValidity ?: boolean | undefined ;
183237 tlsCert ?: any ;
184238} ;
239+ export type ReadableEvents = {
240+ pause : ( ) => void ;
241+ resume : ( ) => void ;
242+ } ;
243+ export type SocketEvents = {
244+ close : ( had_error : boolean ) => void ;
245+ connect : ( ) => void ;
246+ data : ( data : Buffer | string ) => void ;
247+ drain : ( ) => void ;
248+ error : ( err : Error ) => void ;
249+ timeout : ( ) => void ;
250+ } ;
185251import EventEmitter from "eventemitter3" ;
186252import { Buffer } from "buffer" ;
0 commit comments