@react-native-ohos/react-native-tcp-socket 6.3.1 → 6.4.0-bate.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 (60) 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 +17 -17
  5. package/harmony/tcp_socket/Index.ets +9 -6
  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 → TcpSocketPackage.ets} +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 → ts.ets} +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 +137 -137
  49. package/lib/types/Socket.d.ts +272 -272
  50. package/lib/types/TLSServer.d.ts +28 -28
  51. package/lib/types/TLSSocket.d.ts +50 -50
  52. package/lib/types/index.d.ts +80 -80
  53. package/package.json +83 -77
  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
@@ -1,16 +1,16 @@
1
-
2
- /**
3
- * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
- *
5
- * Do not edit this file as changes may cause incorrect behavior and will be lost
6
- * once the code is regenerated.
7
- *
8
- * @generated by codegen project: GenerateEventEmitterCpp.js
9
- */
10
-
11
- #include "EventEmitters.h"
12
-
13
-
14
- namespace facebook::react {
15
-
16
- } // namespace facebook::react
1
+
2
+ /**
3
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
+ *
5
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
6
+ * once the code is regenerated.
7
+ *
8
+ * @generated by codegen project: GenerateEventEmitterCpp.js
9
+ */
10
+
11
+ #include "EventEmitters.h"
12
+
13
+
14
+ namespace facebook::react {
15
+
16
+ } // namespace facebook::react
@@ -1,17 +1,17 @@
1
-
2
- /**
3
- * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
- *
5
- * Do not edit this file as changes may cause incorrect behavior and will be lost
6
- * once the code is regenerated.
7
- *
8
- * @generated by codegen project: GenerateEventEmitterH.js
9
- */
10
- #pragma once
11
-
12
- #include <react/renderer/components/view/ViewEventEmitter.h>
13
-
14
-
15
- namespace facebook::react {
16
-
17
- } // namespace facebook::react
1
+
2
+ /**
3
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
+ *
5
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
6
+ * once the code is regenerated.
7
+ *
8
+ * @generated by codegen project: GenerateEventEmitterH.js
9
+ */
10
+ #pragma once
11
+
12
+ #include <react/renderer/components/view/ViewEventEmitter.h>
13
+
14
+
15
+ namespace facebook::react {
16
+
17
+ } // namespace facebook::react
@@ -1,19 +1,19 @@
1
-
2
- /**
3
- * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
- *
5
- * Do not edit this file as changes may cause incorrect behavior and will be lost
6
- * once the code is regenerated.
7
- *
8
- * @generated by codegen project: GeneratePropsCpp.js
9
- */
10
-
11
- #include "Props.h"
12
- #include <react/renderer/core/PropsParserContext.h>
13
- #include <react/renderer/core/propsConversions.h>
14
-
15
- namespace facebook::react {
16
-
17
-
18
-
19
- } // namespace facebook::react
1
+
2
+ /**
3
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
+ *
5
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
6
+ * once the code is regenerated.
7
+ *
8
+ * @generated by codegen project: GeneratePropsCpp.js
9
+ */
10
+
11
+ #include "Props.h"
12
+ #include <react/renderer/core/PropsParserContext.h>
13
+ #include <react/renderer/core/propsConversions.h>
14
+
15
+ namespace facebook::react {
16
+
17
+
18
+
19
+ } // namespace facebook::react
@@ -1,18 +1,18 @@
1
-
2
- /**
3
- * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
- *
5
- * Do not edit this file as changes may cause incorrect behavior and will be lost
6
- * once the code is regenerated.
7
- *
8
- * @generated by codegen project: GeneratePropsH.js
9
- */
10
- #pragma once
11
-
12
-
13
-
14
- namespace facebook::react {
15
-
16
-
17
-
18
- } // namespace facebook::react
1
+
2
+ /**
3
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
+ *
5
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
6
+ * once the code is regenerated.
7
+ *
8
+ * @generated by codegen project: GeneratePropsH.js
9
+ */
10
+ #pragma once
11
+
12
+
13
+
14
+ namespace facebook::react {
15
+
16
+
17
+
18
+ } // namespace facebook::react
@@ -1,17 +1,17 @@
1
-
2
- /**
3
- * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
- *
5
- * Do not edit this file as changes may cause incorrect behavior and will be lost
6
- * once the code is regenerated.
7
- *
8
- * @generated by codegen project: GenerateShadowNodeCpp.js
9
- */
10
-
11
- #include "ShadowNodes.h"
12
-
13
- namespace facebook::react {
14
-
15
-
16
-
17
- } // namespace facebook::react
1
+
2
+ /**
3
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
+ *
5
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
6
+ * once the code is regenerated.
7
+ *
8
+ * @generated by codegen project: GenerateShadowNodeCpp.js
9
+ */
10
+
11
+ #include "ShadowNodes.h"
12
+
13
+ namespace facebook::react {
14
+
15
+
16
+
17
+ } // namespace facebook::react
@@ -1,23 +1,23 @@
1
-
2
- /**
3
- * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
- *
5
- * Do not edit this file as changes may cause incorrect behavior and will be lost
6
- * once the code is regenerated.
7
- *
8
- * @generated by codegen project: GenerateShadowNodeH.js
9
- */
10
-
11
- #pragma once
12
-
13
- #include "EventEmitters.h"
14
- #include "Props.h"
15
- #include "States.h"
16
- #include <react/renderer/components/view/ConcreteViewShadowNode.h>
17
- #include <jsi/jsi.h>
18
-
19
- namespace facebook::react {
20
-
21
-
22
-
23
- } // namespace facebook::react
1
+
2
+ /**
3
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
+ *
5
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
6
+ * once the code is regenerated.
7
+ *
8
+ * @generated by codegen project: GenerateShadowNodeH.js
9
+ */
10
+
11
+ #pragma once
12
+
13
+ #include "EventEmitters.h"
14
+ #include "Props.h"
15
+ #include "States.h"
16
+ #include <react/renderer/components/view/ConcreteViewShadowNode.h>
17
+ #include <jsi/jsi.h>
18
+
19
+ namespace facebook::react {
20
+
21
+
22
+
23
+ } // namespace facebook::react
@@ -1,16 +1,16 @@
1
-
2
- /**
3
- * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
- *
5
- * Do not edit this file as changes may cause incorrect behavior and will be lost
6
- * once the code is regenerated.
7
- *
8
- * @generated by codegen project: GenerateStateCpp.js
9
- */
10
- #include "States.h"
11
-
12
- namespace facebook::react {
13
-
14
-
15
-
16
- } // namespace facebook::react
1
+
2
+ /**
3
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
+ *
5
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
6
+ * once the code is regenerated.
7
+ *
8
+ * @generated by codegen project: GenerateStateCpp.js
9
+ */
10
+ #include "States.h"
11
+
12
+ namespace facebook::react {
13
+
14
+
15
+
16
+ } // namespace facebook::react
@@ -1,19 +1,19 @@
1
- /**
2
- * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
3
- *
4
- * Do not edit this file as changes may cause incorrect behavior and will be lost
5
- * once the code is regenerated.
6
- *
7
- * @generated by codegen project: GenerateStateH.js
8
- */
9
- #pragma once
10
-
11
- #ifdef ANDROID
12
- #include <folly/dynamic.h>
13
- #endif
14
-
15
- namespace facebook::react {
16
-
17
-
18
-
1
+ /**
2
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
3
+ *
4
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
5
+ * once the code is regenerated.
6
+ *
7
+ * @generated by codegen project: GenerateStateH.js
8
+ */
9
+ #pragma once
10
+
11
+ #ifdef ANDROID
12
+ #include <folly/dynamic.h>
13
+ #endif
14
+
15
+ namespace facebook::react {
16
+
17
+
18
+
19
19
  } // namespace facebook::react
@@ -1,46 +1,46 @@
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 hilog from '@ohos.hilog';
8
-
9
- class Logger {
10
- private domain: number;
11
- private prefix: string;
12
- private format: string = '%{public}s, %{public}s';
13
- private isDebug: boolean;
14
-
15
- /**
16
- * constructor.
17
- *
18
- * @param Prefix Identifies the log tag.
19
- * @param domain Domain Indicates the service domain, which is a hexadecimal integer ranging from 0x0 to 0xFFFFF.
20
- */
21
- constructor(prefix: string = 'RNCToolbarAndroid', domain: number = 0xFF00, isDebug = false) {
22
- this.prefix = prefix;
23
- this.domain = domain;
24
- this.isDebug = isDebug;
25
- }
26
-
27
- debug(...args: string[]): void {
28
- if (this.isDebug) {
29
- hilog.debug(this.domain, this.prefix, this.format, args);
30
- }
31
- }
32
-
33
- info(...args: string[]): void {
34
- hilog.info(this.domain, this.prefix, this.format, args);
35
- }
36
-
37
- warn(...args: string[]): void {
38
- hilog.warn(this.domain, this.prefix, this.format, args);
39
- }
40
-
41
- error(...args: string[]): void {
42
- hilog.error(this.domain, this.prefix, this.format, args);
43
- }
44
- }
45
-
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 hilog from '@ohos.hilog';
8
+
9
+ class Logger {
10
+ private domain: number;
11
+ private prefix: string;
12
+ private format: string = '%{public}s, %{public}s';
13
+ private isDebug: boolean;
14
+
15
+ /**
16
+ * constructor.
17
+ *
18
+ * @param Prefix Identifies the log tag.
19
+ * @param domain Domain Indicates the service domain, which is a hexadecimal integer ranging from 0x0 to 0xFFFFF.
20
+ */
21
+ constructor(prefix: string = 'RNCToolbarAndroid', domain: number = 0xFF00, isDebug = false) {
22
+ this.prefix = prefix;
23
+ this.domain = domain;
24
+ this.isDebug = isDebug;
25
+ }
26
+
27
+ debug(...args: string[]): void {
28
+ if (this.isDebug) {
29
+ hilog.debug(this.domain, this.prefix, this.format, args);
30
+ }
31
+ }
32
+
33
+ info(...args: string[]): void {
34
+ hilog.info(this.domain, this.prefix, this.format, args);
35
+ }
36
+
37
+ warn(...args: string[]): void {
38
+ hilog.warn(this.domain, this.prefix, this.format, args);
39
+ }
40
+
41
+ error(...args: string[]): void {
42
+ hilog.error(this.domain, this.prefix, this.format, args);
43
+ }
44
+ }
45
+
46
46
  export default new Logger('RNTextSizeTurboModule', 0xFF00, false)
@@ -1,121 +1,121 @@
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
- import { RNInstance, TurboModuleContext } from '@rnoh/react-native-openharmony/ts';
7
- import { TcpSocketClient } from './TcpSocketClient'
8
- import { TcpSocketServer } from './TcpSocketServer'
9
- import { socket } from '@kit.NetworkKit';
10
-
11
- export class TcpEventListener {
12
- private rnInstance?: RNInstance;
13
-
14
- constructor(ctx: TurboModuleContext) {
15
- this.rnInstance = ctx.rnInstance;
16
- }
17
-
18
- async onConnection(serverId: number, clientId: number, connection: socket.TCPSocketConnection) {
19
- let localAddress = await connection?.getLocalAddress() as socket.NetAddress;
20
- let remoteAddress = await connection?.getRemoteAddress() as socket.NetAddress;
21
- let localFamily = remoteAddress.family === 2 ? "IPv6" : "IPv4"
22
- this.sendEvent("connection", {
23
- "id": serverId,
24
- "info": {
25
- "id": clientId,
26
- "connection": {
27
- "localAddress": localAddress.address,
28
- "localPort": localAddress.port,
29
- "remoteAddress": remoteAddress.address,
30
- "remotePort": remoteAddress.port,
31
- "remoteFamily": localFamily
32
- }
33
- }
34
- });
35
- }
36
-
37
- async onSecureConnection(serverId: number, clientId: number, connection: socket.TLSSocketConnection) {
38
- let localAddress = await connection?.getLocalAddress() as socket.NetAddress;
39
- let remoteAddress = await connection?.getRemoteAddress() as socket.NetAddress;
40
- let remoteFamily = remoteAddress.family === 2 ? "IPv6" : "IPv4"
41
- this.sendEvent("secureConnection", {
42
- "id": serverId,
43
- "info": {
44
- "id": clientId,
45
- "connection": {
46
- "localAddress": localAddress.address,
47
- "localPort": localAddress.port,
48
- "remoteAddress": remoteAddress.address,
49
- "remotePort": remoteAddress.port,
50
- "remoteFamily": remoteFamily
51
- }
52
- }
53
- });
54
- }
55
-
56
-
57
- async onConnect(cid: number, client: TcpSocketClient) {
58
- let tcpSocket: socket.TCPSocket | socket.TLSSocket | socket.TCPSocketConnection | socket.TLSSocketConnection | undefined =
59
- client.getSocket();
60
- let localAddress = await tcpSocket?.getLocalAddress() as socket.NetAddress;
61
- let remoteAddress = await tcpSocket?.getRemoteAddress() as socket.NetAddress;
62
- let remoteFamily = remoteAddress.family === 2 ? "IPv6" : "IPv4"
63
- this.sendEvent("connect", {
64
- "id": cid,
65
- "connection": {
66
- "localAddress": localAddress.address,
67
- "localPort": localAddress.port,
68
- "remoteAddress": remoteAddress.address,
69
- "remotePort": remoteAddress.port,
70
- "remoteFamily": remoteFamily
71
- }
72
- });
73
- }
74
-
75
- async onListen(cId: number, tcpSocketServer: TcpSocketServer) {
76
- let serverSocket: socket.TCPSocketServer | socket.TLSSocketServer = tcpSocketServer.getServerSocket();
77
- let address: socket.NetAddress = await serverSocket.getLocalAddress();
78
- let localFamily = address.family === 2 ? "IPv6" : "IPv4"
79
- this.sendEvent("listening", {
80
- "id": cId,
81
- "connection": {
82
- "localAddress": address.address,
83
- "localPort": address.port,
84
- "localFamily": localFamily
85
- }
86
- });
87
- }
88
-
89
- onData(id: number,data:string) {
90
- this.sendEvent("data", {
91
- "id": id,
92
- "data": data
93
- });
94
- }
95
-
96
- onWritten(id: number, msgId: number, error: string) {
97
- this.sendEvent("written", {
98
- "id": id,
99
- "msgId": msgId,
100
- "error": error
101
- });
102
- }
103
-
104
- onClose(id: number, error: string) {
105
- this.sendEvent("close", {
106
- "id": id,
107
- "hadError": error ? true : false
108
- });
109
- }
110
-
111
- onError(id: number, error: string): void {
112
- this.sendEvent("error", {
113
- "id": id,
114
- "error": error
115
- });
116
- }
117
-
118
- private sendEvent(eventName: string, params: object): void {
119
- this.rnInstance?.emitDeviceEvent(eventName, params);
120
- }
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
+ import { RNInstance, TurboModuleContext } from '@rnoh/react-native-openharmony/ts';
7
+ import { TcpSocketClient } from './TcpSocketClient'
8
+ import { TcpSocketServer } from './TcpSocketServer'
9
+ import { socket } from '@kit.NetworkKit';
10
+
11
+ export class TcpEventListener {
12
+ private rnInstance?: RNInstance;
13
+
14
+ constructor(ctx: TurboModuleContext) {
15
+ this.rnInstance = ctx.rnInstance;
16
+ }
17
+
18
+ async onConnection(serverId: number, clientId: number, connection: socket.TCPSocketConnection) {
19
+ let localAddress = await connection?.getLocalAddress() as socket.NetAddress;
20
+ let remoteAddress = await connection?.getRemoteAddress() as socket.NetAddress;
21
+ let localFamily = remoteAddress.family === 2 ? "IPv6" : "IPv4"
22
+ this.sendEvent("connection", {
23
+ "id": serverId,
24
+ "info": {
25
+ "id": clientId,
26
+ "connection": {
27
+ "localAddress": localAddress.address,
28
+ "localPort": localAddress.port,
29
+ "remoteAddress": remoteAddress.address,
30
+ "remotePort": remoteAddress.port,
31
+ "remoteFamily": localFamily
32
+ }
33
+ }
34
+ });
35
+ }
36
+
37
+ async onSecureConnection(serverId: number, clientId: number, connection: socket.TLSSocketConnection) {
38
+ let localAddress = await connection?.getLocalAddress() as socket.NetAddress;
39
+ let remoteAddress = await connection?.getRemoteAddress() as socket.NetAddress;
40
+ let remoteFamily = remoteAddress.family === 2 ? "IPv6" : "IPv4"
41
+ this.sendEvent("secureConnection", {
42
+ "id": serverId,
43
+ "info": {
44
+ "id": clientId,
45
+ "connection": {
46
+ "localAddress": localAddress.address,
47
+ "localPort": localAddress.port,
48
+ "remoteAddress": remoteAddress.address,
49
+ "remotePort": remoteAddress.port,
50
+ "remoteFamily": remoteFamily
51
+ }
52
+ }
53
+ });
54
+ }
55
+
56
+
57
+ async onConnect(cid: number, client: TcpSocketClient) {
58
+ let tcpSocket: socket.TCPSocket | socket.TLSSocket | socket.TCPSocketConnection | socket.TLSSocketConnection | undefined =
59
+ client.getSocket();
60
+ let localAddress = await tcpSocket?.getLocalAddress() as socket.NetAddress;
61
+ let remoteAddress = await tcpSocket?.getRemoteAddress() as socket.NetAddress;
62
+ let remoteFamily = remoteAddress.family === 2 ? "IPv6" : "IPv4"
63
+ this.sendEvent("connect", {
64
+ "id": cid,
65
+ "connection": {
66
+ "localAddress": localAddress.address,
67
+ "localPort": localAddress.port,
68
+ "remoteAddress": remoteAddress.address,
69
+ "remotePort": remoteAddress.port,
70
+ "remoteFamily": remoteFamily
71
+ }
72
+ });
73
+ }
74
+
75
+ async onListen(cId: number, tcpSocketServer: TcpSocketServer) {
76
+ let serverSocket: socket.TCPSocketServer | socket.TLSSocketServer = tcpSocketServer.getServerSocket();
77
+ let address: socket.NetAddress = await serverSocket.getLocalAddress();
78
+ let localFamily = address.family === 2 ? "IPv6" : "IPv4"
79
+ this.sendEvent("listening", {
80
+ "id": cId,
81
+ "connection": {
82
+ "localAddress": address.address,
83
+ "localPort": address.port,
84
+ "localFamily": localFamily
85
+ }
86
+ });
87
+ }
88
+
89
+ onData(id: number,data:string) {
90
+ this.sendEvent("data", {
91
+ "id": id,
92
+ "data": data
93
+ });
94
+ }
95
+
96
+ onWritten(id: number, msgId: number, error: string) {
97
+ this.sendEvent("written", {
98
+ "id": id,
99
+ "msgId": msgId,
100
+ "error": error
101
+ });
102
+ }
103
+
104
+ onClose(id: number, error: string) {
105
+ this.sendEvent("close", {
106
+ "id": id,
107
+ "hadError": error ? true : false
108
+ });
109
+ }
110
+
111
+ onError(id: number, error: string): void {
112
+ this.sendEvent("error", {
113
+ "id": id,
114
+ "error": error
115
+ });
116
+ }
117
+
118
+ private sendEvent(eventName: string, params: object): void {
119
+ this.rnInstance?.emitDeviceEvent(eventName, params);
120
+ }
121
121
  }
@@ -1,17 +1,17 @@
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
- export class TcpSocket {
8
- private id: number;
9
-
10
- constructor(id: number) {
11
- this.id = id;
12
- }
13
-
14
- getId(): number {
15
- return this.id;
16
- }
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
+ export class TcpSocket {
8
+ private id: number;
9
+
10
+ constructor(id: number) {
11
+ this.id = id;
12
+ }
13
+
14
+ getId(): number {
15
+ return this.id;
16
+ }
17
17
  }