@react-native-ohos/react-native-tcp-socket 6.3.1-rc.2 → 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.
Files changed (61) hide show
  1. package/LICENSE +21 -21
  2. package/README.OpenSource +10 -10
  3. package/README.md +12 -12
  4. package/harmony/tcp_socket/BuildProfile.ets +16 -16
  5. package/harmony/tcp_socket/Index.ets +5 -5
  6. package/harmony/tcp_socket/build-profile.json5 +31 -31
  7. package/harmony/tcp_socket/hvigorfile.ts +6 -6
  8. package/harmony/tcp_socket/obfuscation-rules.txt +22 -22
  9. package/harmony/tcp_socket/oh-package.json5 +11 -11
  10. package/harmony/tcp_socket/src/main/cpp/CMakeLists.txt +8 -8
  11. package/harmony/tcp_socket/src/main/cpp/TcpSocketPackage.h +18 -18
  12. package/harmony/tcp_socket/src/main/cpp/generated/RNOH/generated/BaseReactNativeTcpSocketPackage.h +72 -72
  13. package/harmony/tcp_socket/src/main/cpp/generated/RNOH/generated/turbo_modules/TcpSocketModule.cpp +28 -28
  14. package/harmony/tcp_socket/src/main/cpp/generated/RNOH/generated/turbo_modules/TcpSocketModule.h +16 -16
  15. package/harmony/tcp_socket/src/main/cpp/generated/react/renderer/components/react_native_tcp_socket/ComponentDescriptors.h +24 -24
  16. package/harmony/tcp_socket/src/main/cpp/generated/react/renderer/components/react_native_tcp_socket/EventEmitters.cpp +16 -16
  17. package/harmony/tcp_socket/src/main/cpp/generated/react/renderer/components/react_native_tcp_socket/EventEmitters.h +17 -17
  18. package/harmony/tcp_socket/src/main/cpp/generated/react/renderer/components/react_native_tcp_socket/Props.cpp +19 -19
  19. package/harmony/tcp_socket/src/main/cpp/generated/react/renderer/components/react_native_tcp_socket/Props.h +18 -18
  20. package/harmony/tcp_socket/src/main/cpp/generated/react/renderer/components/react_native_tcp_socket/ShadowNodes.cpp +17 -17
  21. package/harmony/tcp_socket/src/main/cpp/generated/react/renderer/components/react_native_tcp_socket/ShadowNodes.h +23 -23
  22. package/harmony/tcp_socket/src/main/cpp/generated/react/renderer/components/react_native_tcp_socket/States.cpp +16 -16
  23. package/harmony/tcp_socket/src/main/cpp/generated/react/renderer/components/react_native_tcp_socket/States.h +18 -18
  24. package/harmony/tcp_socket/src/main/ets/Logger.ts +45 -45
  25. package/harmony/tcp_socket/src/main/ets/TcpEventListener.ts +120 -120
  26. package/harmony/tcp_socket/src/main/ets/TcpSocket.ts +16 -16
  27. package/harmony/tcp_socket/src/main/ets/TcpSocketClient.ts +443 -443
  28. package/harmony/tcp_socket/src/main/ets/TcpSocketPackage.ts +27 -27
  29. package/harmony/tcp_socket/src/main/ets/TcpSocketServer.ts +150 -150
  30. package/harmony/tcp_socket/src/main/ets/TcpSocketTurboModule.ts +224 -224
  31. package/harmony/tcp_socket/src/main/ets/generated/components/ts.ts +5 -5
  32. package/harmony/tcp_socket/src/main/ets/generated/index.ets +5 -5
  33. package/harmony/tcp_socket/src/main/ets/generated/ts.ts +6 -6
  34. package/harmony/tcp_socket/src/main/ets/generated/turboModules/TcpSocketModule.ts +38 -38
  35. package/harmony/tcp_socket/src/main/ets/generated/turboModules/ts.ts +5 -5
  36. package/harmony/tcp_socket/src/main/module.json5 +11 -11
  37. package/harmony/tcp_socket/src/main/resources/base/element/string.json +8 -8
  38. package/harmony/tcp_socket/src/main/resources/en_US/element/string.json +8 -8
  39. package/harmony/tcp_socket/src/main/resources/zh_CN/element/string.json +8 -8
  40. package/harmony/tcp_socket/src/ohosTest/ets/test/Ability.test.ets +34 -34
  41. package/harmony/tcp_socket/src/ohosTest/ets/test/List.test.ets +4 -4
  42. package/harmony/tcp_socket/src/ohosTest/module.json5 +13 -13
  43. package/harmony/tcp_socket/src/test/List.test.ets +4 -4
  44. package/harmony/tcp_socket/src/test/LocalUnit.test.ets +32 -32
  45. package/harmony/tcp_socket/ts.ts +6 -6
  46. package/harmony/tcp_socket.har +0 -0
  47. package/lib/types/Globals.d.ts +2 -2
  48. package/lib/types/Server.d.ts +138 -138
  49. package/lib/types/Socket.d.ts +272 -276
  50. package/lib/types/TLSServer.d.ts +28 -47
  51. package/lib/types/TLSSocket.d.ts +50 -50
  52. package/lib/types/index.d.ts +81 -81
  53. package/package.json +76 -76
  54. package/src/Globals.js +12 -12
  55. package/src/Server.js +271 -271
  56. package/src/Socket.js +513 -513
  57. package/src/TLSServer.js +70 -70
  58. package/src/TLSSocket.js +93 -93
  59. package/src/TcpSocketModule.ts +39 -39
  60. package/src/index.js +144 -144
  61. package/lib/types/TcpSocketModule.d.ts +0 -18
package/src/TLSServer.js CHANGED
@@ -1,70 +1,70 @@
1
- 'use strict';
2
-
3
- import { Image } from 'react-native';
4
- import Server from './Server';
5
- import TLSSocket from './TLSSocket';
6
-
7
- /**
8
- * @typedef {object} TLSServerOptions
9
- * @property {any} keystore
10
- *
11
- * @extends {Server}
12
- */
13
- export default class TLSServer extends Server {
14
- /**
15
- * @param {(socket: TLSSocket) => void} [secureConnectionListener] Automatically set as a listener for the `'secureConnection'` event.
16
- */
17
- constructor(secureConnectionListener) {
18
- super();
19
- if (secureConnectionListener) this.on('secureConnection', secureConnectionListener);
20
- this._registerTLSEvents();
21
- }
22
-
23
- /**
24
- * @param {TLSServerOptions} options TLS server options
25
- */
26
- setSecureContext(options) {
27
- /** @private */
28
- this._options = { ...options };
29
- this._options.keystore = Image.resolveAssetSource(this._options.keystore).uri;
30
- }
31
-
32
- /**
33
- * Start a server listening for connections.
34
- *
35
- * This function is asynchronous. When the server starts listening, the `'listening'` event will be emitted.
36
- * The last parameter `callback` will be added as a listener for the `'listening'` event.
37
- *
38
- * The `server.listen()` method can be called again if and only if there was an error during the first
39
- * `server.listen()` call or `server.close()` has been called. Otherwise, an `ERR_SERVER_ALREADY_LISTEN`
40
- * error will be thrown.
41
- *
42
- * @param {{ port: number; host: string; reuseAddress?: boolean}} options
43
- * @param {() => void} [callback]
44
- * @override
45
- */
46
- listen(options, callback) {
47
- const newOptions = { ...options };
48
- // @ts-ignore
49
- newOptions['tls'] = this._options;
50
- return super.listen(newOptions, callback);
51
- }
52
-
53
- /**
54
- * @private
55
- */
56
- _registerTLSEvents() {
57
- this._secureConnectionListener = this._eventEmitter.addListener(
58
- 'secureConnection',
59
- (evt) => {
60
- if (evt.id !== this._id) return;
61
- const standardSocket = this._buildSocket(evt.info);
62
- standardSocket._unregisterEvents();
63
- const tlsSocket = new TLSSocket(standardSocket);
64
- this._addConnection(tlsSocket);
65
- this.emit('connection', standardSocket);
66
- this.emit('secureConnection', tlsSocket);
67
- }
68
- );
69
- }
70
- }
1
+ 'use strict';
2
+
3
+ import { Image } from 'react-native';
4
+ import Server from './Server';
5
+ import TLSSocket from './TLSSocket';
6
+
7
+ /**
8
+ * @typedef {object} TLSServerOptions
9
+ * @property {any} keystore
10
+ *
11
+ * @extends {Server}
12
+ */
13
+ export default class TLSServer extends Server {
14
+ /**
15
+ * @param {(socket: TLSSocket) => void} [secureConnectionListener] Automatically set as a listener for the `'secureConnection'` event.
16
+ */
17
+ constructor(secureConnectionListener) {
18
+ super();
19
+ if (secureConnectionListener) this.on('secureConnection', secureConnectionListener);
20
+ this._registerTLSEvents();
21
+ }
22
+
23
+ /**
24
+ * @param {TLSServerOptions} options TLS server options
25
+ */
26
+ setSecureContext(options) {
27
+ /** @private */
28
+ this._options = { ...options };
29
+ this._options.keystore = Image.resolveAssetSource(this._options.keystore).uri;
30
+ }
31
+
32
+ /**
33
+ * Start a server listening for connections.
34
+ *
35
+ * This function is asynchronous. When the server starts listening, the `'listening'` event will be emitted.
36
+ * The last parameter `callback` will be added as a listener for the `'listening'` event.
37
+ *
38
+ * The `server.listen()` method can be called again if and only if there was an error during the first
39
+ * `server.listen()` call or `server.close()` has been called. Otherwise, an `ERR_SERVER_ALREADY_LISTEN`
40
+ * error will be thrown.
41
+ *
42
+ * @param {{ port: number; host: string; reuseAddress?: boolean}} options
43
+ * @param {() => void} [callback]
44
+ * @override
45
+ */
46
+ listen(options, callback) {
47
+ const newOptions = { ...options };
48
+ // @ts-ignore
49
+ newOptions['tls'] = this._options;
50
+ return super.listen(newOptions, callback);
51
+ }
52
+
53
+ /**
54
+ * @private
55
+ */
56
+ _registerTLSEvents() {
57
+ this._secureConnectionListener = this._eventEmitter.addListener(
58
+ 'secureConnection',
59
+ (evt) => {
60
+ if (evt.id !== this._id) return;
61
+ const standardSocket = this._buildSocket(evt.info);
62
+ standardSocket._unregisterEvents();
63
+ const tlsSocket = new TLSSocket(standardSocket);
64
+ this._addConnection(tlsSocket);
65
+ this.emit('connection', standardSocket);
66
+ this.emit('secureConnection', tlsSocket);
67
+ }
68
+ );
69
+ }
70
+ }
package/src/TLSSocket.js CHANGED
@@ -1,93 +1,93 @@
1
- 'use strict';
2
-
3
- import { Image, NativeModules, TurboModuleRegistry } from 'react-native';
4
- const Sockets = TurboModuleRegistry ? TurboModuleRegistry.get('TcpSocketModule') : NativeModules.TcpSockets;
5
- import Socket from './Socket';
6
-
7
- /**
8
- * @typedef {object} TLSSocketOptions
9
- * @property {any} [ca]
10
- * @property {any} [key]
11
- * @property {any} [cert]
12
- * @property {string} [androidKeyStore]
13
- * @property {string} [certAlias]
14
- * @property {string} [keyAlias]
15
- * @property {string[]} [resolvedKeys]
16
- *
17
- * @extends {Socket}
18
- */
19
- export default class TLSSocket extends Socket {
20
- /**
21
- * @param {Socket} socket Any instance of `Socket`.
22
- * @param {TLSSocketOptions} [options] Options for the TLS socket.
23
- */
24
- constructor(socket, options = {}) {
25
- super();
26
- /** @private */
27
- this._options = { ...options };
28
- TLSSocket.resolveAssetIfNeeded(this._options, 'ca');
29
- TLSSocket.resolveAssetIfNeeded(this._options, 'key');
30
- TLSSocket.resolveAssetIfNeeded(this._options, 'cert');
31
-
32
- /** @private */
33
- this._socket = socket;
34
- // @ts-ignore
35
- this._setId(this._socket._id);
36
- this._startTLS();
37
- if (socket.pending || socket.connecting) socket.once('connect', () => this._initialize());
38
- else this._initialize();
39
- }
40
-
41
- /**
42
- * @private
43
- */
44
- _initialize() {
45
- // Avoid calling twice destroy() if an error occurs
46
- this._socket._errorListener?.remove();
47
- this.on('error', (error) => this._socket.emit('error', error));
48
- this._setConnected({
49
- // @ts-ignore
50
- localAddress: this._socket.localAddress,
51
- // @ts-ignore
52
- localPort: this._socket.localPort,
53
- // @ts-ignore
54
- remoteAddress: this._socket.remoteAddress,
55
- // @ts-ignore
56
- remotePort: this._socket.remotePort,
57
- // @ts-ignore
58
- remoteFamily: this._socket.remoteFamily,
59
- });
60
- }
61
-
62
- /**
63
- * @private
64
- */
65
- _startTLS() {
66
- Sockets.startTLS(this._id, this._options);
67
- }
68
-
69
- getCertificate() {
70
- return Sockets.getCertificate(this._id);
71
- }
72
-
73
- getPeerCertificate() {
74
- return Sockets.getPeerCertificate(this._id);
75
- }
76
-
77
- /**
78
- * @private
79
- * Resolves the asset source if necessary and registers the resolved key.
80
- * @param {TLSSocketOptions} options The options object containing the source to be resolved.
81
- * @param {'ca' | 'key' | 'cert'} key The key name being resolved.
82
- */
83
- static resolveAssetIfNeeded(options, key) {
84
- const source = options[key];
85
- if (source && typeof source !== 'string') {
86
- if (!options.resolvedKeys) {
87
- options.resolvedKeys = [];
88
- }
89
- options.resolvedKeys.push(key);
90
- options[key] = Image.resolveAssetSource(source).uri;
91
- }
92
- }
93
- }
1
+ 'use strict';
2
+
3
+ import { Image, NativeModules, TurboModuleRegistry } from 'react-native';
4
+ const Sockets = TurboModuleRegistry ? TurboModuleRegistry.get('TcpSocketModule') : NativeModules.TcpSockets;
5
+ import Socket from './Socket';
6
+
7
+ /**
8
+ * @typedef {object} TLSSocketOptions
9
+ * @property {any} [ca]
10
+ * @property {any} [key]
11
+ * @property {any} [cert]
12
+ * @property {string} [androidKeyStore]
13
+ * @property {string} [certAlias]
14
+ * @property {string} [keyAlias]
15
+ * @property {string[]} [resolvedKeys]
16
+ *
17
+ * @extends {Socket}
18
+ */
19
+ export default class TLSSocket extends Socket {
20
+ /**
21
+ * @param {Socket} socket Any instance of `Socket`.
22
+ * @param {TLSSocketOptions} [options] Options for the TLS socket.
23
+ */
24
+ constructor(socket, options = {}) {
25
+ super();
26
+ /** @private */
27
+ this._options = { ...options };
28
+ TLSSocket.resolveAssetIfNeeded(this._options, 'ca');
29
+ TLSSocket.resolveAssetIfNeeded(this._options, 'key');
30
+ TLSSocket.resolveAssetIfNeeded(this._options, 'cert');
31
+
32
+ /** @private */
33
+ this._socket = socket;
34
+ // @ts-ignore
35
+ this._setId(this._socket._id);
36
+ this._startTLS();
37
+ if (socket.pending || socket.connecting) socket.once('connect', () => this._initialize());
38
+ else this._initialize();
39
+ }
40
+
41
+ /**
42
+ * @private
43
+ */
44
+ _initialize() {
45
+ // Avoid calling twice destroy() if an error occurs
46
+ this._socket._errorListener?.remove();
47
+ this.on('error', (error) => this._socket.emit('error', error));
48
+ this._setConnected({
49
+ // @ts-ignore
50
+ localAddress: this._socket.localAddress,
51
+ // @ts-ignore
52
+ localPort: this._socket.localPort,
53
+ // @ts-ignore
54
+ remoteAddress: this._socket.remoteAddress,
55
+ // @ts-ignore
56
+ remotePort: this._socket.remotePort,
57
+ // @ts-ignore
58
+ remoteFamily: this._socket.remoteFamily,
59
+ });
60
+ }
61
+
62
+ /**
63
+ * @private
64
+ */
65
+ _startTLS() {
66
+ Sockets.startTLS(this._id, this._options);
67
+ }
68
+
69
+ getCertificate() {
70
+ return Sockets.getCertificate(this._id);
71
+ }
72
+
73
+ getPeerCertificate() {
74
+ return Sockets.getPeerCertificate(this._id);
75
+ }
76
+
77
+ /**
78
+ * @private
79
+ * Resolves the asset source if necessary and registers the resolved key.
80
+ * @param {TLSSocketOptions} options The options object containing the source to be resolved.
81
+ * @param {'ca' | 'key' | 'cert'} key The key name being resolved.
82
+ */
83
+ static resolveAssetIfNeeded(options, key) {
84
+ const source = options[key];
85
+ if (source && typeof source !== 'string') {
86
+ if (!options.resolvedKeys) {
87
+ options.resolvedKeys = [];
88
+ }
89
+ options.resolvedKeys.push(key);
90
+ options[key] = Image.resolveAssetSource(source).uri;
91
+ }
92
+ }
93
+ }
@@ -1,40 +1,40 @@
1
- /*
2
- * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3
- * Use of this source code is governed by a MIT license that can be
4
- * found in the LICENSE file.
5
- */
6
-
7
- import type { TurboModule } from 'react-native/Libraries/TurboModule/RCTExport';
8
- import { TurboModuleRegistry } from 'react-native';
9
-
10
- export interface Spec extends TurboModule {
11
-
12
- listen(cId: number, options: Object): void;
13
-
14
- close(cid: number): void;
15
-
16
- destroy(cid: number): void;
17
-
18
- end(cid: number): void;
19
-
20
- pause(cid: number): void;
21
-
22
- resume(cid: number): void;
23
-
24
- connect(cId: number, host: string, port: number, options: Object): void;
25
-
26
- startTLS(cId: number, tlsOptions: Object): void;
27
-
28
- write(cId: number, base64String: string, msgId: number): void;
29
-
30
- setNoDelay(cId: number, noDelay: boolean): void;
31
-
32
- setKeepAlive(cId: number, enable: boolean, initialDelay: number): void;
33
-
34
- getPeerCertificate(cId: number): Promise<string>;
35
-
36
- getCertificate(cId: number): Promise<string>;
37
- }
38
-
39
-
1
+ /*
2
+ * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3
+ * Use of this source code is governed by a MIT license that can be
4
+ * found in the LICENSE file.
5
+ */
6
+
7
+ import type { TurboModule } from 'react-native/Libraries/TurboModule/RCTExport';
8
+ import { TurboModuleRegistry } from 'react-native';
9
+
10
+ export interface Spec extends TurboModule {
11
+
12
+ listen(cId: number, options: Object): void;
13
+
14
+ close(cid: number): void;
15
+
16
+ destroy(cid: number): void;
17
+
18
+ end(cid: number): void;
19
+
20
+ pause(cid: number): void;
21
+
22
+ resume(cid: number): void;
23
+
24
+ connect(cId: number, host: string, port: number, options: Object): void;
25
+
26
+ startTLS(cId: number, tlsOptions: Object): void;
27
+
28
+ write(cId: number, base64String: string, msgId: number): void;
29
+
30
+ setNoDelay(cId: number, noDelay: boolean): void;
31
+
32
+ setKeepAlive(cId: number, enable: boolean, initialDelay: number): void;
33
+
34
+ getPeerCertificate(cId: number): Promise<string>;
35
+
36
+ getCertificate(cId: number): Promise<string>;
37
+ }
38
+
39
+
40
40
  export default TurboModuleRegistry.get<Spec>('TcpSocketModule') as Spec | null;