@react-native-ohos/react-native-tcp-socket 6.2.1-rc.1 → 6.2.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/Index.ets +8 -8
- 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 +10 -10
- package/harmony/tcp_socket/src/main/cpp/TcpSocketPackage.h +26 -26
- package/harmony/tcp_socket/src/main/cpp/generated/RNOH/generated/BaseReactNativeTcpSocketPackage.h +65 -65
- 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 +22 -22
- package/harmony/tcp_socket/src/main/cpp/generated/react/renderer/components/react_native_tcp_socket/EventEmitters.cpp +18 -18
- package/harmony/tcp_socket/src/main/cpp/generated/react/renderer/components/react_native_tcp_socket/EventEmitters.h +19 -19
- package/harmony/tcp_socket/src/main/cpp/generated/react/renderer/components/react_native_tcp_socket/Props.cpp +21 -21
- package/harmony/tcp_socket/src/main/cpp/generated/react/renderer/components/react_native_tcp_socket/Props.h +20 -20
- package/harmony/tcp_socket/src/main/cpp/generated/react/renderer/components/react_native_tcp_socket/ShadowNodes.cpp +19 -19
- package/harmony/tcp_socket/src/main/cpp/generated/react/renderer/components/react_native_tcp_socket/ShadowNodes.h +25 -25
- package/harmony/tcp_socket/src/main/cpp/generated/react/renderer/components/react_native_tcp_socket/States.cpp +18 -18
- package/harmony/tcp_socket/src/main/cpp/generated/react/renderer/components/react_native_tcp_socket/States.h +22 -22
- 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.ets +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.ets +6 -6
- package/harmony/tcp_socket.har +0 -0
- package/lib/types/Globals.d.ts +1 -1
- package/lib/types/Server.d.ts +3 -3
- package/lib/types/Socket.d.ts +15 -11
- package/lib/types/TcpSocketModule.d.ts +18 -0
- package/package.json +90 -90
- package/src/Globals.js +12 -12
- package/src/Server.js +185 -185
- 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 +131 -131
|
@@ -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: GenerateEventEmitterH.js
|
|
9
|
-
*/
|
|
10
|
-
#pragma once
|
|
11
|
-
|
|
12
|
-
#include <react/renderer/components/view/ViewEventEmitter.h>
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
namespace facebook {
|
|
16
|
-
namespace react {
|
|
17
|
-
|
|
18
|
-
} // namespace react
|
|
19
|
-
} // namespace facebook
|
|
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 {
|
|
16
|
+
namespace react {
|
|
17
|
+
|
|
18
|
+
} // namespace react
|
|
19
|
+
} // namespace facebook
|
|
@@ -1,21 +1,21 @@
|
|
|
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 <react/renderer/components/react_native_tcp_socket/Props.h>
|
|
12
|
-
#include <react/renderer/core/PropsParserContext.h>
|
|
13
|
-
#include <react/renderer/core/propsConversions.h>
|
|
14
|
-
|
|
15
|
-
namespace facebook {
|
|
16
|
-
namespace react {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
} // namespace react
|
|
21
|
-
} // namespace facebook
|
|
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 <react/renderer/components/react_native_tcp_socket/Props.h>
|
|
12
|
+
#include <react/renderer/core/PropsParserContext.h>
|
|
13
|
+
#include <react/renderer/core/propsConversions.h>
|
|
14
|
+
|
|
15
|
+
namespace facebook {
|
|
16
|
+
namespace react {
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
} // namespace react
|
|
21
|
+
} // namespace facebook
|
|
@@ -1,20 +1,20 @@
|
|
|
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 {
|
|
15
|
-
namespace react {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
} // namespace react
|
|
20
|
-
} // namespace facebook
|
|
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 {
|
|
15
|
+
namespace react {
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
} // namespace react
|
|
20
|
+
} // namespace facebook
|
|
@@ -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: GenerateShadowNodeCpp.js
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
#include <react/renderer/components/react_native_tcp_socket/ShadowNodes.h>
|
|
12
|
-
|
|
13
|
-
namespace facebook {
|
|
14
|
-
namespace react {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
} // namespace react
|
|
19
|
-
} // namespace facebook
|
|
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 <react/renderer/components/react_native_tcp_socket/ShadowNodes.h>
|
|
12
|
+
|
|
13
|
+
namespace facebook {
|
|
14
|
+
namespace react {
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
} // namespace react
|
|
19
|
+
} // namespace facebook
|
|
@@ -1,25 +1,25 @@
|
|
|
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 <react/renderer/components/react_native_tcp_socket/EventEmitters.h>
|
|
14
|
-
#include <react/renderer/components/react_native_tcp_socket/Props.h>
|
|
15
|
-
#include <react/renderer/components/react_native_tcp_socket/States.h>
|
|
16
|
-
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
|
|
17
|
-
#include <jsi/jsi.h>
|
|
18
|
-
|
|
19
|
-
namespace facebook {
|
|
20
|
-
namespace react {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
} // namespace react
|
|
25
|
-
} // namespace facebook
|
|
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 <react/renderer/components/react_native_tcp_socket/EventEmitters.h>
|
|
14
|
+
#include <react/renderer/components/react_native_tcp_socket/Props.h>
|
|
15
|
+
#include <react/renderer/components/react_native_tcp_socket/States.h>
|
|
16
|
+
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
|
|
17
|
+
#include <jsi/jsi.h>
|
|
18
|
+
|
|
19
|
+
namespace facebook {
|
|
20
|
+
namespace react {
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
} // namespace react
|
|
25
|
+
} // namespace facebook
|
|
@@ -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: GenerateStateCpp.js
|
|
9
|
-
*/
|
|
10
|
-
#include <react/renderer/components/react_native_tcp_socket/States.h>
|
|
11
|
-
|
|
12
|
-
namespace facebook {
|
|
13
|
-
namespace react {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
} // namespace react
|
|
18
|
-
} // namespace facebook
|
|
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 <react/renderer/components/react_native_tcp_socket/States.h>
|
|
11
|
+
|
|
12
|
+
namespace facebook {
|
|
13
|
+
namespace react {
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
} // namespace react
|
|
18
|
+
} // namespace facebook
|
|
@@ -1,23 +1,23 @@
|
|
|
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
|
-
#include <react/renderer/mapbuffer/MapBuffer.h>
|
|
14
|
-
#include <react/renderer/mapbuffer/MapBufferBuilder.h>
|
|
15
|
-
#endif
|
|
16
|
-
|
|
17
|
-
namespace facebook {
|
|
18
|
-
namespace react {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
} // namespace react
|
|
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
|
+
#include <react/renderer/mapbuffer/MapBuffer.h>
|
|
14
|
+
#include <react/renderer/mapbuffer/MapBufferBuilder.h>
|
|
15
|
+
#endif
|
|
16
|
+
|
|
17
|
+
namespace facebook {
|
|
18
|
+
namespace react {
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
} // namespace react
|
|
23
23
|
} // namespace facebook
|
|
@@ -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
|
}
|