@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/src/index.js
CHANGED
|
@@ -1,145 +1,145 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
import Server from './Server';
|
|
4
|
-
import Socket from './Socket';
|
|
5
|
-
import TLSServer from './TLSServer';
|
|
6
|
-
import TLSSocket from './TLSSocket';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @typedef {object} ServerOptions
|
|
10
|
-
* @property {boolean} [noDelay]
|
|
11
|
-
* @property {boolean} [keepAlive]
|
|
12
|
-
* @property {number} [keepAliveInitialDelay]
|
|
13
|
-
* @property {boolean} [allowHalfOpen]
|
|
14
|
-
* @property {boolean} [pauseOnConnect]
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Creates a new TCP server.
|
|
19
|
-
*
|
|
20
|
-
* @param {ServerOptions | ((socket: Socket) => void)} [options] An options object or a connection listener
|
|
21
|
-
* @param {(socket: Socket) => void} [connectionListener] A listener for the 'connection' event
|
|
22
|
-
* @returns {Server}
|
|
23
|
-
*/
|
|
24
|
-
function createServer(options, connectionListener) {
|
|
25
|
-
return new Server(options, connectionListener);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* @param {import('./TLSServer').TLSServerOptions} options
|
|
30
|
-
* @param {(socket: TLSSocket) => void} connectionListener
|
|
31
|
-
* @returns {TLSServer}
|
|
32
|
-
*/
|
|
33
|
-
function createTLSServer(options, connectionListener) {
|
|
34
|
-
const server = new TLSServer(connectionListener);
|
|
35
|
-
server.setSecureContext(options);
|
|
36
|
-
return server;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* The `callback` function, if specified, will be added as a listener for the `'secureConnect'` event.
|
|
41
|
-
*
|
|
42
|
-
* @param {import('./TLSSocket').TLSSocketOptions & import('./Socket').ConnectionOptions} options
|
|
43
|
-
* @param {() => void} [callback]
|
|
44
|
-
* @returns {TLSSocket}
|
|
45
|
-
*/
|
|
46
|
-
function connectTLS(options, callback) {
|
|
47
|
-
const socket = new Socket();
|
|
48
|
-
const tlsSocket = new TLSSocket(socket, options);
|
|
49
|
-
socket.once('connect', () => tlsSocket.emit('secureConnect'));
|
|
50
|
-
if (callback) tlsSocket.once('secureConnect', callback);
|
|
51
|
-
socket.connect(options);
|
|
52
|
-
return tlsSocket;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* @param {import('./Socket').ConnectionOptions} options
|
|
57
|
-
* @param {() => void} callback
|
|
58
|
-
* @returns {Socket}
|
|
59
|
-
*/
|
|
60
|
-
function createConnection(options, callback) {
|
|
61
|
-
const tcpSocket = new Socket();
|
|
62
|
-
return tcpSocket.connect(options, callback);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// IPv4 Segment
|
|
66
|
-
const v4Seg = '(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])';
|
|
67
|
-
const v4Str = `(${v4Seg}[.]){3}${v4Seg}`;
|
|
68
|
-
const IPv4Reg = new RegExp(`^${v4Str}$`);
|
|
69
|
-
|
|
70
|
-
// IPv6 Segment
|
|
71
|
-
const v6Seg = '(?:[0-9a-fA-F]{1,4})';
|
|
72
|
-
const IPv6Reg = new RegExp(
|
|
73
|
-
'^(' +
|
|
74
|
-
`(?:${v6Seg}:){7}(?:${v6Seg}|:)|` +
|
|
75
|
-
`(?:${v6Seg}:){6}(?:${v4Str}|:${v6Seg}|:)|` +
|
|
76
|
-
`(?:${v6Seg}:){5}(?::${v4Str}|(:${v6Seg}){1,2}|:)|` +
|
|
77
|
-
`(?:${v6Seg}:){4}(?:(:${v6Seg}){0,1}:${v4Str}|(:${v6Seg}){1,3}|:)|` +
|
|
78
|
-
`(?:${v6Seg}:){3}(?:(:${v6Seg}){0,2}:${v4Str}|(:${v6Seg}){1,4}|:)|` +
|
|
79
|
-
`(?:${v6Seg}:){2}(?:(:${v6Seg}){0,3}:${v4Str}|(:${v6Seg}){1,5}|:)|` +
|
|
80
|
-
`(?:${v6Seg}:){1}(?:(:${v6Seg}){0,4}:${v4Str}|(:${v6Seg}){1,6}|:)|` +
|
|
81
|
-
`(?::((?::${v6Seg}){0,5}:${v4Str}|(?::${v6Seg}){1,7}|:))` +
|
|
82
|
-
')(%[0-9a-zA-Z-.:]{1,})?$'
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Returns `true` if input is a version 4 IP address, otherwise returns `false`.
|
|
87
|
-
*
|
|
88
|
-
* @param {string} input
|
|
89
|
-
*/
|
|
90
|
-
function isIPv4(input) {
|
|
91
|
-
return IPv4Reg.test(input);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Returns `true` if input is a version 6 IP address, otherwise returns `false`.
|
|
96
|
-
*
|
|
97
|
-
* @param {string} input
|
|
98
|
-
*/
|
|
99
|
-
function isIPv6(input) {
|
|
100
|
-
return IPv6Reg.test(input);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Tests if input is an IP address. Returns `0` for invalid strings, returns `4` for IP version 4 addresses, and returns `6` for IP version 6 addresses.
|
|
105
|
-
*
|
|
106
|
-
* @param {string} input
|
|
107
|
-
*/
|
|
108
|
-
function isIP(input) {
|
|
109
|
-
if (isIPv4(input)) return 4;
|
|
110
|
-
else if (isIPv6(input)) return 6;
|
|
111
|
-
return 0;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export default {
|
|
115
|
-
connect: createConnection,
|
|
116
|
-
createServer,
|
|
117
|
-
createConnection,
|
|
118
|
-
createTLSServer,
|
|
119
|
-
connectTLS,
|
|
120
|
-
isIP,
|
|
121
|
-
isIPv4,
|
|
122
|
-
isIPv6,
|
|
123
|
-
Server,
|
|
124
|
-
Socket,
|
|
125
|
-
TLSServer,
|
|
126
|
-
TLSSocket,
|
|
127
|
-
hasIdentity: TLSSocket.hasIdentity,
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
// @ts-ignore
|
|
131
|
-
module.exports = {
|
|
132
|
-
connect: createConnection,
|
|
133
|
-
createServer,
|
|
134
|
-
createConnection,
|
|
135
|
-
createTLSServer,
|
|
136
|
-
connectTLS,
|
|
137
|
-
isIP,
|
|
138
|
-
isIPv4,
|
|
139
|
-
isIPv6,
|
|
140
|
-
Server,
|
|
141
|
-
Socket,
|
|
142
|
-
TLSServer,
|
|
143
|
-
TLSSocket,
|
|
144
|
-
hasIdentity: TLSSocket.hasIdentity,
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
import Server from './Server';
|
|
4
|
+
import Socket from './Socket';
|
|
5
|
+
import TLSServer from './TLSServer';
|
|
6
|
+
import TLSSocket from './TLSSocket';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @typedef {object} ServerOptions
|
|
10
|
+
* @property {boolean} [noDelay]
|
|
11
|
+
* @property {boolean} [keepAlive]
|
|
12
|
+
* @property {number} [keepAliveInitialDelay]
|
|
13
|
+
* @property {boolean} [allowHalfOpen]
|
|
14
|
+
* @property {boolean} [pauseOnConnect]
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Creates a new TCP server.
|
|
19
|
+
*
|
|
20
|
+
* @param {ServerOptions | ((socket: Socket) => void)} [options] An options object or a connection listener
|
|
21
|
+
* @param {(socket: Socket) => void} [connectionListener] A listener for the 'connection' event
|
|
22
|
+
* @returns {Server}
|
|
23
|
+
*/
|
|
24
|
+
function createServer(options, connectionListener) {
|
|
25
|
+
return new Server(options, connectionListener);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @param {import('./TLSServer').TLSServerOptions} options
|
|
30
|
+
* @param {(socket: TLSSocket) => void} connectionListener
|
|
31
|
+
* @returns {TLSServer}
|
|
32
|
+
*/
|
|
33
|
+
function createTLSServer(options, connectionListener) {
|
|
34
|
+
const server = new TLSServer(connectionListener);
|
|
35
|
+
server.setSecureContext(options);
|
|
36
|
+
return server;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The `callback` function, if specified, will be added as a listener for the `'secureConnect'` event.
|
|
41
|
+
*
|
|
42
|
+
* @param {import('./TLSSocket').TLSSocketOptions & import('./Socket').ConnectionOptions} options
|
|
43
|
+
* @param {() => void} [callback]
|
|
44
|
+
* @returns {TLSSocket}
|
|
45
|
+
*/
|
|
46
|
+
function connectTLS(options, callback) {
|
|
47
|
+
const socket = new Socket();
|
|
48
|
+
const tlsSocket = new TLSSocket(socket, options);
|
|
49
|
+
socket.once('connect', () => tlsSocket.emit('secureConnect'));
|
|
50
|
+
if (callback) tlsSocket.once('secureConnect', callback);
|
|
51
|
+
socket.connect(options);
|
|
52
|
+
return tlsSocket;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @param {import('./Socket').ConnectionOptions} options
|
|
57
|
+
* @param {() => void} callback
|
|
58
|
+
* @returns {Socket}
|
|
59
|
+
*/
|
|
60
|
+
function createConnection(options, callback) {
|
|
61
|
+
const tcpSocket = new Socket();
|
|
62
|
+
return tcpSocket.connect(options, callback);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// IPv4 Segment
|
|
66
|
+
const v4Seg = '(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])';
|
|
67
|
+
const v4Str = `(${v4Seg}[.]){3}${v4Seg}`;
|
|
68
|
+
const IPv4Reg = new RegExp(`^${v4Str}$`);
|
|
69
|
+
|
|
70
|
+
// IPv6 Segment
|
|
71
|
+
const v6Seg = '(?:[0-9a-fA-F]{1,4})';
|
|
72
|
+
const IPv6Reg = new RegExp(
|
|
73
|
+
'^(' +
|
|
74
|
+
`(?:${v6Seg}:){7}(?:${v6Seg}|:)|` +
|
|
75
|
+
`(?:${v6Seg}:){6}(?:${v4Str}|:${v6Seg}|:)|` +
|
|
76
|
+
`(?:${v6Seg}:){5}(?::${v4Str}|(:${v6Seg}){1,2}|:)|` +
|
|
77
|
+
`(?:${v6Seg}:){4}(?:(:${v6Seg}){0,1}:${v4Str}|(:${v6Seg}){1,3}|:)|` +
|
|
78
|
+
`(?:${v6Seg}:){3}(?:(:${v6Seg}){0,2}:${v4Str}|(:${v6Seg}){1,4}|:)|` +
|
|
79
|
+
`(?:${v6Seg}:){2}(?:(:${v6Seg}){0,3}:${v4Str}|(:${v6Seg}){1,5}|:)|` +
|
|
80
|
+
`(?:${v6Seg}:){1}(?:(:${v6Seg}){0,4}:${v4Str}|(:${v6Seg}){1,6}|:)|` +
|
|
81
|
+
`(?::((?::${v6Seg}){0,5}:${v4Str}|(?::${v6Seg}){1,7}|:))` +
|
|
82
|
+
')(%[0-9a-zA-Z-.:]{1,})?$'
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Returns `true` if input is a version 4 IP address, otherwise returns `false`.
|
|
87
|
+
*
|
|
88
|
+
* @param {string} input
|
|
89
|
+
*/
|
|
90
|
+
function isIPv4(input) {
|
|
91
|
+
return IPv4Reg.test(input);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Returns `true` if input is a version 6 IP address, otherwise returns `false`.
|
|
96
|
+
*
|
|
97
|
+
* @param {string} input
|
|
98
|
+
*/
|
|
99
|
+
function isIPv6(input) {
|
|
100
|
+
return IPv6Reg.test(input);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Tests if input is an IP address. Returns `0` for invalid strings, returns `4` for IP version 4 addresses, and returns `6` for IP version 6 addresses.
|
|
105
|
+
*
|
|
106
|
+
* @param {string} input
|
|
107
|
+
*/
|
|
108
|
+
function isIP(input) {
|
|
109
|
+
if (isIPv4(input)) return 4;
|
|
110
|
+
else if (isIPv6(input)) return 6;
|
|
111
|
+
return 0;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export default {
|
|
115
|
+
connect: createConnection,
|
|
116
|
+
createServer,
|
|
117
|
+
createConnection,
|
|
118
|
+
createTLSServer,
|
|
119
|
+
connectTLS,
|
|
120
|
+
isIP,
|
|
121
|
+
isIPv4,
|
|
122
|
+
isIPv6,
|
|
123
|
+
Server,
|
|
124
|
+
Socket,
|
|
125
|
+
TLSServer,
|
|
126
|
+
TLSSocket,
|
|
127
|
+
hasIdentity: TLSSocket.hasIdentity,
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
// @ts-ignore
|
|
131
|
+
module.exports = {
|
|
132
|
+
connect: createConnection,
|
|
133
|
+
createServer,
|
|
134
|
+
createConnection,
|
|
135
|
+
createTLSServer,
|
|
136
|
+
connectTLS,
|
|
137
|
+
isIP,
|
|
138
|
+
isIPv4,
|
|
139
|
+
isIPv6,
|
|
140
|
+
Server,
|
|
141
|
+
Socket,
|
|
142
|
+
TLSServer,
|
|
143
|
+
TLSSocket,
|
|
144
|
+
hasIdentity: TLSSocket.hasIdentity,
|
|
145
145
|
};
|