@react-native-ohos/react-native-tcp-socket 6.3.1-rc.3 → 6.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.OpenSource +10 -10
- package/README.md +12 -12
- package/harmony/tcp_socket/BuildProfile.ets +16 -16
- package/harmony/tcp_socket/Index.ets +5 -5
- package/harmony/tcp_socket/build-profile.json5 +31 -31
- package/harmony/tcp_socket/hvigorfile.ts +6 -6
- package/harmony/tcp_socket/obfuscation-rules.txt +22 -22
- package/harmony/tcp_socket/oh-package.json5 +11 -11
- package/harmony/tcp_socket/src/main/cpp/CMakeLists.txt +8 -8
- package/harmony/tcp_socket/src/main/cpp/TcpSocketPackage.h +18 -18
- package/harmony/tcp_socket/src/main/cpp/generated/RNOH/generated/BaseReactNativeTcpSocketPackage.h +72 -72
- package/harmony/tcp_socket/src/main/cpp/generated/RNOH/generated/turbo_modules/TcpSocketModule.cpp +28 -28
- package/harmony/tcp_socket/src/main/cpp/generated/RNOH/generated/turbo_modules/TcpSocketModule.h +16 -16
- package/harmony/tcp_socket/src/main/cpp/generated/react/renderer/components/react_native_tcp_socket/ComponentDescriptors.h +24 -24
- package/harmony/tcp_socket/src/main/cpp/generated/react/renderer/components/react_native_tcp_socket/EventEmitters.cpp +16 -16
- package/harmony/tcp_socket/src/main/cpp/generated/react/renderer/components/react_native_tcp_socket/EventEmitters.h +17 -17
- package/harmony/tcp_socket/src/main/cpp/generated/react/renderer/components/react_native_tcp_socket/Props.cpp +19 -19
- package/harmony/tcp_socket/src/main/cpp/generated/react/renderer/components/react_native_tcp_socket/Props.h +18 -18
- package/harmony/tcp_socket/src/main/cpp/generated/react/renderer/components/react_native_tcp_socket/ShadowNodes.cpp +17 -17
- package/harmony/tcp_socket/src/main/cpp/generated/react/renderer/components/react_native_tcp_socket/ShadowNodes.h +23 -23
- package/harmony/tcp_socket/src/main/cpp/generated/react/renderer/components/react_native_tcp_socket/States.cpp +16 -16
- package/harmony/tcp_socket/src/main/cpp/generated/react/renderer/components/react_native_tcp_socket/States.h +18 -18
- package/harmony/tcp_socket/src/main/ets/Logger.ts +45 -45
- package/harmony/tcp_socket/src/main/ets/TcpEventListener.ts +120 -120
- package/harmony/tcp_socket/src/main/ets/TcpSocket.ts +16 -16
- package/harmony/tcp_socket/src/main/ets/TcpSocketClient.ts +443 -443
- package/harmony/tcp_socket/src/main/ets/TcpSocketPackage.ts +27 -27
- package/harmony/tcp_socket/src/main/ets/TcpSocketServer.ts +150 -150
- package/harmony/tcp_socket/src/main/ets/TcpSocketTurboModule.ts +224 -224
- package/harmony/tcp_socket/src/main/ets/generated/components/ts.ts +5 -5
- package/harmony/tcp_socket/src/main/ets/generated/index.ets +5 -5
- package/harmony/tcp_socket/src/main/ets/generated/ts.ts +6 -6
- package/harmony/tcp_socket/src/main/ets/generated/turboModules/TcpSocketModule.ts +38 -38
- package/harmony/tcp_socket/src/main/ets/generated/turboModules/ts.ts +5 -5
- package/harmony/tcp_socket/src/main/module.json5 +11 -11
- package/harmony/tcp_socket/src/main/resources/base/element/string.json +8 -8
- package/harmony/tcp_socket/src/main/resources/en_US/element/string.json +8 -8
- package/harmony/tcp_socket/src/main/resources/zh_CN/element/string.json +8 -8
- package/harmony/tcp_socket/src/ohosTest/ets/test/Ability.test.ets +34 -34
- package/harmony/tcp_socket/src/ohosTest/ets/test/List.test.ets +4 -4
- package/harmony/tcp_socket/src/ohosTest/module.json5 +13 -13
- package/harmony/tcp_socket/src/test/List.test.ets +4 -4
- package/harmony/tcp_socket/src/test/LocalUnit.test.ets +32 -32
- package/harmony/tcp_socket/ts.ts +6 -6
- package/harmony/tcp_socket.har +0 -0
- package/lib/types/Globals.d.ts +2 -2
- package/lib/types/Server.d.ts +137 -137
- package/lib/types/Socket.d.ts +272 -272
- package/lib/types/TLSServer.d.ts +28 -28
- package/lib/types/TLSSocket.d.ts +50 -50
- package/lib/types/index.d.ts +80 -80
- package/package.json +76 -76
- package/src/Globals.js +12 -12
- package/src/Server.js +271 -271
- package/src/Socket.js +513 -513
- package/src/TLSServer.js +70 -70
- package/src/TLSSocket.js +93 -93
- package/src/TcpSocketModule.ts +39 -39
- package/src/index.js +144 -144
package/lib/types/Socket.d.ts
CHANGED
|
@@ -1,272 +1,272 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @typedef {"ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex"} BufferEncoding
|
|
3
|
-
*
|
|
4
|
-
* @typedef {import('react-native').NativeEventEmitter} NativeEventEmitter
|
|
5
|
-
*
|
|
6
|
-
* @typedef {{address: string, family: string, port: number}} AddressInfo
|
|
7
|
-
*
|
|
8
|
-
* @typedef {{localAddress: string, localPort: number, remoteAddress: string, remotePort: number, remoteFamily: string}} NativeConnectionInfo
|
|
9
|
-
*
|
|
10
|
-
* @typedef {{
|
|
11
|
-
* port: number;
|
|
12
|
-
* host?: string;
|
|
13
|
-
* localAddress?: string,
|
|
14
|
-
* localPort?: number,
|
|
15
|
-
* interface?: 'wifi' | 'cellular' | 'ethernet',
|
|
16
|
-
* reuseAddress?: boolean,
|
|
17
|
-
* tls?: boolean,
|
|
18
|
-
* tlsCheckValidity?: boolean,
|
|
19
|
-
* tlsCert?: any,
|
|
20
|
-
* }} ConnectionOptions
|
|
21
|
-
*
|
|
22
|
-
* @typedef {object} ReadableEvents
|
|
23
|
-
* @property {() => void} pause
|
|
24
|
-
* @property {() => void} resume
|
|
25
|
-
*
|
|
26
|
-
* @typedef {object} SocketEvents
|
|
27
|
-
* @property {(had_error: boolean) => void} close
|
|
28
|
-
* @property {() => void} connect
|
|
29
|
-
* @property {(data: Buffer | string) => void} data
|
|
30
|
-
* @property {() => void} drain
|
|
31
|
-
* @property {(err: Error) => void} error
|
|
32
|
-
* @property {() => void} timeout
|
|
33
|
-
* @property {() => void} secureConnect
|
|
34
|
-
*
|
|
35
|
-
* @extends {EventEmitter<SocketEvents & ReadableEvents, any>}
|
|
36
|
-
*/
|
|
37
|
-
export default class Socket extends EventEmitter<SocketEvents & ReadableEvents, any> {
|
|
38
|
-
/** @package */
|
|
39
|
-
_id: number;
|
|
40
|
-
/** @private */
|
|
41
|
-
private _eventEmitter;
|
|
42
|
-
/** @type {EventEmitter<'written', any>} @private */
|
|
43
|
-
private _msgEvtEmitter;
|
|
44
|
-
/** @type {number} @private */
|
|
45
|
-
private _timeoutMsecs;
|
|
46
|
-
/** @type {number | undefined} @private */
|
|
47
|
-
private _timeout;
|
|
48
|
-
/** @private */
|
|
49
|
-
private _encoding;
|
|
50
|
-
/** @private */
|
|
51
|
-
private _msgId;
|
|
52
|
-
/** @private */
|
|
53
|
-
private _lastRcvMsgId;
|
|
54
|
-
/** @private */
|
|
55
|
-
private _lastSentMsgId;
|
|
56
|
-
/** @private */
|
|
57
|
-
private _paused;
|
|
58
|
-
/** @private */
|
|
59
|
-
private _resuming;
|
|
60
|
-
/** @private */
|
|
61
|
-
private _writeBufferSize;
|
|
62
|
-
/** @private */
|
|
63
|
-
private _bytesRead;
|
|
64
|
-
/** @private */
|
|
65
|
-
private _bytesWritten;
|
|
66
|
-
/** @private */
|
|
67
|
-
private _connecting;
|
|
68
|
-
/** @private */
|
|
69
|
-
private _pending;
|
|
70
|
-
/** @private */
|
|
71
|
-
private _destroyed;
|
|
72
|
-
/** @type {'opening' | 'open' | 'readOnly' | 'writeOnly'} @private */
|
|
73
|
-
private _readyState;
|
|
74
|
-
/** @type {{ id: number; data: string; }[]} @private */
|
|
75
|
-
private _pausedDataEvents;
|
|
76
|
-
readableHighWaterMark: number;
|
|
77
|
-
writableHighWaterMark: number;
|
|
78
|
-
writableNeedDrain: boolean;
|
|
79
|
-
localAddress: string | undefined;
|
|
80
|
-
localPort: number | undefined;
|
|
81
|
-
remoteAddress: string | undefined;
|
|
82
|
-
remotePort: number | undefined;
|
|
83
|
-
remoteFamily: string | undefined;
|
|
84
|
-
get readyState(): "opening" | "open" | "readOnly" | "writeOnly";
|
|
85
|
-
get destroyed(): boolean;
|
|
86
|
-
get pending(): boolean;
|
|
87
|
-
get connecting(): boolean;
|
|
88
|
-
get bytesWritten(): number;
|
|
89
|
-
get bytesRead(): number;
|
|
90
|
-
get timeout(): number | undefined;
|
|
91
|
-
/**
|
|
92
|
-
* @package
|
|
93
|
-
* @param {number} id
|
|
94
|
-
*/
|
|
95
|
-
_setId(id: number): void;
|
|
96
|
-
/**
|
|
97
|
-
* @package
|
|
98
|
-
* @param {NativeConnectionInfo} connectionInfo
|
|
99
|
-
*/
|
|
100
|
-
_setConnected(connectionInfo: NativeConnectionInfo): void;
|
|
101
|
-
/**
|
|
102
|
-
* @param {ConnectionOptions} options
|
|
103
|
-
* @param {() => void} [callback]
|
|
104
|
-
*/
|
|
105
|
-
connect(options: ConnectionOptions, callback?: (() => void) | undefined): Socket;
|
|
106
|
-
/**
|
|
107
|
-
* Sets the socket to timeout after `timeout` milliseconds of inactivity on the socket. By default `TcpSocket` do not have a timeout.
|
|
108
|
-
*
|
|
109
|
-
* When an idle timeout is triggered the socket will receive a `'timeout'` event but the connection will not be severed.
|
|
110
|
-
* The user must manually call `socket.end()` or `socket.destroy()` to end the connection.
|
|
111
|
-
*
|
|
112
|
-
* If `timeout` is 0, then the existing idle timeout is disabled.
|
|
113
|
-
*
|
|
114
|
-
* The optional `callback` parameter will be added as a one-time listener for the `'timeout'` event.
|
|
115
|
-
*
|
|
116
|
-
* @param {number} timeout
|
|
117
|
-
* @param {() => void} [callback]
|
|
118
|
-
*/
|
|
119
|
-
setTimeout(timeout: number, callback?: (() => void) | undefined): Socket;
|
|
120
|
-
/**
|
|
121
|
-
* @private
|
|
122
|
-
* @param {number} [timeout]
|
|
123
|
-
*/
|
|
124
|
-
private _activateTimer;
|
|
125
|
-
/**
|
|
126
|
-
* @private
|
|
127
|
-
*/
|
|
128
|
-
private _clearTimeout;
|
|
129
|
-
/**
|
|
130
|
-
* Set the encoding for the socket as a Readable Stream. By default, no encoding is assigned and stream data will be returned as `Buffer` objects.
|
|
131
|
-
* Setting an encoding causes the stream data to be returned as strings of the specified encoding rather than as Buffer objects.
|
|
132
|
-
*
|
|
133
|
-
* For instance, calling `socket.setEncoding('utf8')` will cause the output data to be interpreted as UTF-8 data, and passed as strings.
|
|
134
|
-
* Calling `socket.setEncoding('hex')` will cause the data to be encoded in hexadecimal string format.
|
|
135
|
-
*
|
|
136
|
-
* @param {BufferEncoding} [encoding]
|
|
137
|
-
*/
|
|
138
|
-
setEncoding(encoding?: "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex" | undefined): Socket;
|
|
139
|
-
/**
|
|
140
|
-
* Enable/disable the use of Nagle's algorithm. When a TCP connection is created, it will have Nagle's algorithm enabled.
|
|
141
|
-
*
|
|
142
|
-
* Nagle's algorithm delays data before it is sent via the network. It attempts to optimize throughput at the expense of latency.
|
|
143
|
-
*
|
|
144
|
-
* Passing `true` for `noDelay` or not passing an argument will disable Nagle's algorithm for the socket. Passing false for noDelay will enable Nagle's algorithm.
|
|
145
|
-
*
|
|
146
|
-
* @param {boolean} noDelay Default: `true`
|
|
147
|
-
*/
|
|
148
|
-
setNoDelay(noDelay?: boolean): Socket;
|
|
149
|
-
/**
|
|
150
|
-
* Enable/disable keep-alive functionality, and optionally set the initial delay before the first keepalive probe is sent on an idle socket.
|
|
151
|
-
*
|
|
152
|
-
* `initialDelay` is ignored.
|
|
153
|
-
*
|
|
154
|
-
* @param {boolean} enable Default: `false`
|
|
155
|
-
* @param {number} initialDelay ***IGNORED**. Default: `0`
|
|
156
|
-
*/
|
|
157
|
-
setKeepAlive(enable?: boolean, initialDelay?: number): Socket;
|
|
158
|
-
/**
|
|
159
|
-
* Returns the bound `address`, the address `family` name and `port` of the socket as reported
|
|
160
|
-
* by the operating system: `{ port: 12346, family: 'IPv4', address: '127.0.0.1' }`.
|
|
161
|
-
*
|
|
162
|
-
* @returns {AddressInfo | {}}
|
|
163
|
-
*/
|
|
164
|
-
address(): AddressInfo | {};
|
|
165
|
-
/**
|
|
166
|
-
* Half-closes the socket. i.e., it sends a FIN packet. It is possible the server will still send some data.
|
|
167
|
-
*
|
|
168
|
-
* @param {string | Buffer | Uint8Array} [data]
|
|
169
|
-
* @param {BufferEncoding} [encoding]
|
|
170
|
-
*/
|
|
171
|
-
end(data?: string | Buffer | Uint8Array | undefined, encoding?: "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex" | undefined): Socket;
|
|
172
|
-
/**
|
|
173
|
-
* Ensures that no more I/O activity happens on this socket. Destroys the stream and closes the connection.
|
|
174
|
-
*/
|
|
175
|
-
destroy(): Socket;
|
|
176
|
-
/**
|
|
177
|
-
* Sends data on the socket. The second parameter specifies the encoding in the case of a string — it defaults to UTF8 encoding.
|
|
178
|
-
*
|
|
179
|
-
* Returns `true` if the entire data was flushed successfully to the kernel buffer. Returns `false` if all or part of the data
|
|
180
|
-
* was queued in user memory. `'drain'` will be emitted when the buffer is again free.
|
|
181
|
-
*
|
|
182
|
-
* The optional callback parameter will be executed when the data is finally written out, which may not be immediately.
|
|
183
|
-
*
|
|
184
|
-
* @param {string | Buffer | Uint8Array} buffer
|
|
185
|
-
* @param {BufferEncoding} [encoding]
|
|
186
|
-
* @param {(err?: Error) => void} [cb]
|
|
187
|
-
*
|
|
188
|
-
* @return {boolean}
|
|
189
|
-
*/
|
|
190
|
-
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;
|
|
191
|
-
/**
|
|
192
|
-
* Pauses the reading of data. That is, `'data'` events will not be emitted. Useful to throttle back an upload.
|
|
193
|
-
*/
|
|
194
|
-
pause(): void;
|
|
195
|
-
/**
|
|
196
|
-
* Resumes reading after a call to `socket.pause()`.
|
|
197
|
-
*/
|
|
198
|
-
resume(): void;
|
|
199
|
-
ref(): void;
|
|
200
|
-
unref(): void;
|
|
201
|
-
/**
|
|
202
|
-
* @private
|
|
203
|
-
*/
|
|
204
|
-
private _recoverDataEventsAfterPause;
|
|
205
|
-
/**
|
|
206
|
-
* @private
|
|
207
|
-
*/
|
|
208
|
-
private _onDeviceDataEvt;
|
|
209
|
-
/**
|
|
210
|
-
* @private
|
|
211
|
-
*/
|
|
212
|
-
private _registerEvents;
|
|
213
|
-
_dataListener: import("react-native").EmitterSubscription | undefined;
|
|
214
|
-
_errorListener: import("react-native").EmitterSubscription | undefined;
|
|
215
|
-
_closeListener: import("react-native").EmitterSubscription | undefined;
|
|
216
|
-
_connectListener: import("react-native").EmitterSubscription | undefined;
|
|
217
|
-
_writtenListener: import("react-native").EmitterSubscription | undefined;
|
|
218
|
-
/**
|
|
219
|
-
* @package
|
|
220
|
-
*/
|
|
221
|
-
_unregisterEvents(): void;
|
|
222
|
-
/**
|
|
223
|
-
* @private
|
|
224
|
-
* @param {string | Buffer | Uint8Array} buffer
|
|
225
|
-
* @param {BufferEncoding} [encoding]
|
|
226
|
-
*/
|
|
227
|
-
private _generateSendBuffer;
|
|
228
|
-
/**
|
|
229
|
-
* @private
|
|
230
|
-
*/
|
|
231
|
-
private _setDisconnected;
|
|
232
|
-
}
|
|
233
|
-
export type BufferEncoding = "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex";
|
|
234
|
-
export type NativeEventEmitter = import("react-native").NativeEventEmitter;
|
|
235
|
-
export type AddressInfo = {
|
|
236
|
-
address: string;
|
|
237
|
-
family: string;
|
|
238
|
-
port: number;
|
|
239
|
-
};
|
|
240
|
-
export type NativeConnectionInfo = {
|
|
241
|
-
localAddress: string;
|
|
242
|
-
localPort: number;
|
|
243
|
-
remoteAddress: string;
|
|
244
|
-
remotePort: number;
|
|
245
|
-
remoteFamily: string;
|
|
246
|
-
};
|
|
247
|
-
export type ConnectionOptions = {
|
|
248
|
-
port: number;
|
|
249
|
-
host?: string | undefined;
|
|
250
|
-
localAddress?: string | undefined;
|
|
251
|
-
localPort?: number | undefined;
|
|
252
|
-
interface?: "wifi" | "cellular" | "ethernet" | undefined;
|
|
253
|
-
reuseAddress?: boolean | undefined;
|
|
254
|
-
tls?: boolean | undefined;
|
|
255
|
-
tlsCheckValidity?: boolean | undefined;
|
|
256
|
-
tlsCert?: any;
|
|
257
|
-
};
|
|
258
|
-
export type ReadableEvents = {
|
|
259
|
-
pause: () => void;
|
|
260
|
-
resume: () => void;
|
|
261
|
-
};
|
|
262
|
-
export type SocketEvents = {
|
|
263
|
-
close: (had_error: boolean) => void;
|
|
264
|
-
connect: () => void;
|
|
265
|
-
data: (data: Buffer | string) => void;
|
|
266
|
-
drain: () => void;
|
|
267
|
-
error: (err: Error) => void;
|
|
268
|
-
timeout: () => void;
|
|
269
|
-
secureConnect: () => void;
|
|
270
|
-
};
|
|
271
|
-
import EventEmitter from "eventemitter3";
|
|
272
|
-
import { Buffer } from "buffer";
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {"ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex"} BufferEncoding
|
|
3
|
+
*
|
|
4
|
+
* @typedef {import('react-native').NativeEventEmitter} NativeEventEmitter
|
|
5
|
+
*
|
|
6
|
+
* @typedef {{address: string, family: string, port: number}} AddressInfo
|
|
7
|
+
*
|
|
8
|
+
* @typedef {{localAddress: string, localPort: number, remoteAddress: string, remotePort: number, remoteFamily: string}} NativeConnectionInfo
|
|
9
|
+
*
|
|
10
|
+
* @typedef {{
|
|
11
|
+
* port: number;
|
|
12
|
+
* host?: string;
|
|
13
|
+
* localAddress?: string,
|
|
14
|
+
* localPort?: number,
|
|
15
|
+
* interface?: 'wifi' | 'cellular' | 'ethernet',
|
|
16
|
+
* reuseAddress?: boolean,
|
|
17
|
+
* tls?: boolean,
|
|
18
|
+
* tlsCheckValidity?: boolean,
|
|
19
|
+
* tlsCert?: any,
|
|
20
|
+
* }} ConnectionOptions
|
|
21
|
+
*
|
|
22
|
+
* @typedef {object} ReadableEvents
|
|
23
|
+
* @property {() => void} pause
|
|
24
|
+
* @property {() => void} resume
|
|
25
|
+
*
|
|
26
|
+
* @typedef {object} SocketEvents
|
|
27
|
+
* @property {(had_error: boolean) => void} close
|
|
28
|
+
* @property {() => void} connect
|
|
29
|
+
* @property {(data: Buffer | string) => void} data
|
|
30
|
+
* @property {() => void} drain
|
|
31
|
+
* @property {(err: Error) => void} error
|
|
32
|
+
* @property {() => void} timeout
|
|
33
|
+
* @property {() => void} secureConnect
|
|
34
|
+
*
|
|
35
|
+
* @extends {EventEmitter<SocketEvents & ReadableEvents, any>}
|
|
36
|
+
*/
|
|
37
|
+
export default class Socket extends EventEmitter<SocketEvents & ReadableEvents, any> {
|
|
38
|
+
/** @package */
|
|
39
|
+
_id: number;
|
|
40
|
+
/** @private */
|
|
41
|
+
private _eventEmitter;
|
|
42
|
+
/** @type {EventEmitter<'written', any>} @private */
|
|
43
|
+
private _msgEvtEmitter;
|
|
44
|
+
/** @type {number} @private */
|
|
45
|
+
private _timeoutMsecs;
|
|
46
|
+
/** @type {number | undefined} @private */
|
|
47
|
+
private _timeout;
|
|
48
|
+
/** @private */
|
|
49
|
+
private _encoding;
|
|
50
|
+
/** @private */
|
|
51
|
+
private _msgId;
|
|
52
|
+
/** @private */
|
|
53
|
+
private _lastRcvMsgId;
|
|
54
|
+
/** @private */
|
|
55
|
+
private _lastSentMsgId;
|
|
56
|
+
/** @private */
|
|
57
|
+
private _paused;
|
|
58
|
+
/** @private */
|
|
59
|
+
private _resuming;
|
|
60
|
+
/** @private */
|
|
61
|
+
private _writeBufferSize;
|
|
62
|
+
/** @private */
|
|
63
|
+
private _bytesRead;
|
|
64
|
+
/** @private */
|
|
65
|
+
private _bytesWritten;
|
|
66
|
+
/** @private */
|
|
67
|
+
private _connecting;
|
|
68
|
+
/** @private */
|
|
69
|
+
private _pending;
|
|
70
|
+
/** @private */
|
|
71
|
+
private _destroyed;
|
|
72
|
+
/** @type {'opening' | 'open' | 'readOnly' | 'writeOnly'} @private */
|
|
73
|
+
private _readyState;
|
|
74
|
+
/** @type {{ id: number; data: string; }[]} @private */
|
|
75
|
+
private _pausedDataEvents;
|
|
76
|
+
readableHighWaterMark: number;
|
|
77
|
+
writableHighWaterMark: number;
|
|
78
|
+
writableNeedDrain: boolean;
|
|
79
|
+
localAddress: string | undefined;
|
|
80
|
+
localPort: number | undefined;
|
|
81
|
+
remoteAddress: string | undefined;
|
|
82
|
+
remotePort: number | undefined;
|
|
83
|
+
remoteFamily: string | undefined;
|
|
84
|
+
get readyState(): "opening" | "open" | "readOnly" | "writeOnly";
|
|
85
|
+
get destroyed(): boolean;
|
|
86
|
+
get pending(): boolean;
|
|
87
|
+
get connecting(): boolean;
|
|
88
|
+
get bytesWritten(): number;
|
|
89
|
+
get bytesRead(): number;
|
|
90
|
+
get timeout(): number | undefined;
|
|
91
|
+
/**
|
|
92
|
+
* @package
|
|
93
|
+
* @param {number} id
|
|
94
|
+
*/
|
|
95
|
+
_setId(id: number): void;
|
|
96
|
+
/**
|
|
97
|
+
* @package
|
|
98
|
+
* @param {NativeConnectionInfo} connectionInfo
|
|
99
|
+
*/
|
|
100
|
+
_setConnected(connectionInfo: NativeConnectionInfo): void;
|
|
101
|
+
/**
|
|
102
|
+
* @param {ConnectionOptions} options
|
|
103
|
+
* @param {() => void} [callback]
|
|
104
|
+
*/
|
|
105
|
+
connect(options: ConnectionOptions, callback?: (() => void) | undefined): Socket;
|
|
106
|
+
/**
|
|
107
|
+
* Sets the socket to timeout after `timeout` milliseconds of inactivity on the socket. By default `TcpSocket` do not have a timeout.
|
|
108
|
+
*
|
|
109
|
+
* When an idle timeout is triggered the socket will receive a `'timeout'` event but the connection will not be severed.
|
|
110
|
+
* The user must manually call `socket.end()` or `socket.destroy()` to end the connection.
|
|
111
|
+
*
|
|
112
|
+
* If `timeout` is 0, then the existing idle timeout is disabled.
|
|
113
|
+
*
|
|
114
|
+
* The optional `callback` parameter will be added as a one-time listener for the `'timeout'` event.
|
|
115
|
+
*
|
|
116
|
+
* @param {number} timeout
|
|
117
|
+
* @param {() => void} [callback]
|
|
118
|
+
*/
|
|
119
|
+
setTimeout(timeout: number, callback?: (() => void) | undefined): Socket;
|
|
120
|
+
/**
|
|
121
|
+
* @private
|
|
122
|
+
* @param {number} [timeout]
|
|
123
|
+
*/
|
|
124
|
+
private _activateTimer;
|
|
125
|
+
/**
|
|
126
|
+
* @private
|
|
127
|
+
*/
|
|
128
|
+
private _clearTimeout;
|
|
129
|
+
/**
|
|
130
|
+
* Set the encoding for the socket as a Readable Stream. By default, no encoding is assigned and stream data will be returned as `Buffer` objects.
|
|
131
|
+
* Setting an encoding causes the stream data to be returned as strings of the specified encoding rather than as Buffer objects.
|
|
132
|
+
*
|
|
133
|
+
* For instance, calling `socket.setEncoding('utf8')` will cause the output data to be interpreted as UTF-8 data, and passed as strings.
|
|
134
|
+
* Calling `socket.setEncoding('hex')` will cause the data to be encoded in hexadecimal string format.
|
|
135
|
+
*
|
|
136
|
+
* @param {BufferEncoding} [encoding]
|
|
137
|
+
*/
|
|
138
|
+
setEncoding(encoding?: "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex" | undefined): Socket;
|
|
139
|
+
/**
|
|
140
|
+
* Enable/disable the use of Nagle's algorithm. When a TCP connection is created, it will have Nagle's algorithm enabled.
|
|
141
|
+
*
|
|
142
|
+
* Nagle's algorithm delays data before it is sent via the network. It attempts to optimize throughput at the expense of latency.
|
|
143
|
+
*
|
|
144
|
+
* Passing `true` for `noDelay` or not passing an argument will disable Nagle's algorithm for the socket. Passing false for noDelay will enable Nagle's algorithm.
|
|
145
|
+
*
|
|
146
|
+
* @param {boolean} noDelay Default: `true`
|
|
147
|
+
*/
|
|
148
|
+
setNoDelay(noDelay?: boolean): Socket;
|
|
149
|
+
/**
|
|
150
|
+
* Enable/disable keep-alive functionality, and optionally set the initial delay before the first keepalive probe is sent on an idle socket.
|
|
151
|
+
*
|
|
152
|
+
* `initialDelay` is ignored.
|
|
153
|
+
*
|
|
154
|
+
* @param {boolean} enable Default: `false`
|
|
155
|
+
* @param {number} initialDelay ***IGNORED**. Default: `0`
|
|
156
|
+
*/
|
|
157
|
+
setKeepAlive(enable?: boolean, initialDelay?: number): Socket;
|
|
158
|
+
/**
|
|
159
|
+
* Returns the bound `address`, the address `family` name and `port` of the socket as reported
|
|
160
|
+
* by the operating system: `{ port: 12346, family: 'IPv4', address: '127.0.0.1' }`.
|
|
161
|
+
*
|
|
162
|
+
* @returns {AddressInfo | {}}
|
|
163
|
+
*/
|
|
164
|
+
address(): AddressInfo | {};
|
|
165
|
+
/**
|
|
166
|
+
* Half-closes the socket. i.e., it sends a FIN packet. It is possible the server will still send some data.
|
|
167
|
+
*
|
|
168
|
+
* @param {string | Buffer | Uint8Array} [data]
|
|
169
|
+
* @param {BufferEncoding} [encoding]
|
|
170
|
+
*/
|
|
171
|
+
end(data?: string | Buffer | Uint8Array | undefined, encoding?: "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex" | undefined): Socket;
|
|
172
|
+
/**
|
|
173
|
+
* Ensures that no more I/O activity happens on this socket. Destroys the stream and closes the connection.
|
|
174
|
+
*/
|
|
175
|
+
destroy(): Socket;
|
|
176
|
+
/**
|
|
177
|
+
* Sends data on the socket. The second parameter specifies the encoding in the case of a string — it defaults to UTF8 encoding.
|
|
178
|
+
*
|
|
179
|
+
* Returns `true` if the entire data was flushed successfully to the kernel buffer. Returns `false` if all or part of the data
|
|
180
|
+
* was queued in user memory. `'drain'` will be emitted when the buffer is again free.
|
|
181
|
+
*
|
|
182
|
+
* The optional callback parameter will be executed when the data is finally written out, which may not be immediately.
|
|
183
|
+
*
|
|
184
|
+
* @param {string | Buffer | Uint8Array} buffer
|
|
185
|
+
* @param {BufferEncoding} [encoding]
|
|
186
|
+
* @param {(err?: Error) => void} [cb]
|
|
187
|
+
*
|
|
188
|
+
* @return {boolean}
|
|
189
|
+
*/
|
|
190
|
+
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;
|
|
191
|
+
/**
|
|
192
|
+
* Pauses the reading of data. That is, `'data'` events will not be emitted. Useful to throttle back an upload.
|
|
193
|
+
*/
|
|
194
|
+
pause(): void;
|
|
195
|
+
/**
|
|
196
|
+
* Resumes reading after a call to `socket.pause()`.
|
|
197
|
+
*/
|
|
198
|
+
resume(): void;
|
|
199
|
+
ref(): void;
|
|
200
|
+
unref(): void;
|
|
201
|
+
/**
|
|
202
|
+
* @private
|
|
203
|
+
*/
|
|
204
|
+
private _recoverDataEventsAfterPause;
|
|
205
|
+
/**
|
|
206
|
+
* @private
|
|
207
|
+
*/
|
|
208
|
+
private _onDeviceDataEvt;
|
|
209
|
+
/**
|
|
210
|
+
* @private
|
|
211
|
+
*/
|
|
212
|
+
private _registerEvents;
|
|
213
|
+
_dataListener: import("react-native").EmitterSubscription | undefined;
|
|
214
|
+
_errorListener: import("react-native").EmitterSubscription | undefined;
|
|
215
|
+
_closeListener: import("react-native").EmitterSubscription | undefined;
|
|
216
|
+
_connectListener: import("react-native").EmitterSubscription | undefined;
|
|
217
|
+
_writtenListener: import("react-native").EmitterSubscription | undefined;
|
|
218
|
+
/**
|
|
219
|
+
* @package
|
|
220
|
+
*/
|
|
221
|
+
_unregisterEvents(): void;
|
|
222
|
+
/**
|
|
223
|
+
* @private
|
|
224
|
+
* @param {string | Buffer | Uint8Array} buffer
|
|
225
|
+
* @param {BufferEncoding} [encoding]
|
|
226
|
+
*/
|
|
227
|
+
private _generateSendBuffer;
|
|
228
|
+
/**
|
|
229
|
+
* @private
|
|
230
|
+
*/
|
|
231
|
+
private _setDisconnected;
|
|
232
|
+
}
|
|
233
|
+
export type BufferEncoding = "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex";
|
|
234
|
+
export type NativeEventEmitter = import("react-native").NativeEventEmitter;
|
|
235
|
+
export type AddressInfo = {
|
|
236
|
+
address: string;
|
|
237
|
+
family: string;
|
|
238
|
+
port: number;
|
|
239
|
+
};
|
|
240
|
+
export type NativeConnectionInfo = {
|
|
241
|
+
localAddress: string;
|
|
242
|
+
localPort: number;
|
|
243
|
+
remoteAddress: string;
|
|
244
|
+
remotePort: number;
|
|
245
|
+
remoteFamily: string;
|
|
246
|
+
};
|
|
247
|
+
export type ConnectionOptions = {
|
|
248
|
+
port: number;
|
|
249
|
+
host?: string | undefined;
|
|
250
|
+
localAddress?: string | undefined;
|
|
251
|
+
localPort?: number | undefined;
|
|
252
|
+
interface?: "wifi" | "cellular" | "ethernet" | undefined;
|
|
253
|
+
reuseAddress?: boolean | undefined;
|
|
254
|
+
tls?: boolean | undefined;
|
|
255
|
+
tlsCheckValidity?: boolean | undefined;
|
|
256
|
+
tlsCert?: any;
|
|
257
|
+
};
|
|
258
|
+
export type ReadableEvents = {
|
|
259
|
+
pause: () => void;
|
|
260
|
+
resume: () => void;
|
|
261
|
+
};
|
|
262
|
+
export type SocketEvents = {
|
|
263
|
+
close: (had_error: boolean) => void;
|
|
264
|
+
connect: () => void;
|
|
265
|
+
data: (data: Buffer | string) => void;
|
|
266
|
+
drain: () => void;
|
|
267
|
+
error: (err: Error) => void;
|
|
268
|
+
timeout: () => void;
|
|
269
|
+
secureConnect: () => void;
|
|
270
|
+
};
|
|
271
|
+
import EventEmitter from "eventemitter3";
|
|
272
|
+
import { Buffer } from "buffer";
|
package/lib/types/TLSServer.d.ts
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @typedef {object} TLSServerOptions
|
|
3
|
-
* @property {any} keystore
|
|
4
|
-
*
|
|
5
|
-
* @extends {Server}
|
|
6
|
-
*/
|
|
7
|
-
export default class TLSServer extends Server {
|
|
8
|
-
/**
|
|
9
|
-
* @param {(socket: TLSSocket) => void} [secureConnectionListener] Automatically set as a listener for the `'secureConnection'` event.
|
|
10
|
-
*/
|
|
11
|
-
constructor(secureConnectionListener?: ((socket: TLSSocket) => void) | undefined);
|
|
12
|
-
/**
|
|
13
|
-
* @param {TLSServerOptions} options TLS server options
|
|
14
|
-
*/
|
|
15
|
-
setSecureContext(options: TLSServerOptions): void;
|
|
16
|
-
/** @private */
|
|
17
|
-
private _options;
|
|
18
|
-
/**
|
|
19
|
-
* @private
|
|
20
|
-
*/
|
|
21
|
-
private _registerTLSEvents;
|
|
22
|
-
_secureConnectionListener: import("react-native").EmitterSubscription | undefined;
|
|
23
|
-
}
|
|
24
|
-
export type TLSServerOptions = {
|
|
25
|
-
keystore: any;
|
|
26
|
-
};
|
|
27
|
-
import Server from "./Server";
|
|
28
|
-
import TLSSocket from "./TLSSocket";
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {object} TLSServerOptions
|
|
3
|
+
* @property {any} keystore
|
|
4
|
+
*
|
|
5
|
+
* @extends {Server}
|
|
6
|
+
*/
|
|
7
|
+
export default class TLSServer extends Server {
|
|
8
|
+
/**
|
|
9
|
+
* @param {(socket: TLSSocket) => void} [secureConnectionListener] Automatically set as a listener for the `'secureConnection'` event.
|
|
10
|
+
*/
|
|
11
|
+
constructor(secureConnectionListener?: ((socket: TLSSocket) => void) | undefined);
|
|
12
|
+
/**
|
|
13
|
+
* @param {TLSServerOptions} options TLS server options
|
|
14
|
+
*/
|
|
15
|
+
setSecureContext(options: TLSServerOptions): void;
|
|
16
|
+
/** @private */
|
|
17
|
+
private _options;
|
|
18
|
+
/**
|
|
19
|
+
* @private
|
|
20
|
+
*/
|
|
21
|
+
private _registerTLSEvents;
|
|
22
|
+
_secureConnectionListener: import("react-native").EmitterSubscription | undefined;
|
|
23
|
+
}
|
|
24
|
+
export type TLSServerOptions = {
|
|
25
|
+
keystore: any;
|
|
26
|
+
};
|
|
27
|
+
import Server from "./Server";
|
|
28
|
+
import TLSSocket from "./TLSSocket";
|