react-native-tcp-windows 0.2.0 → 0.2.2
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/lib/commonjs/ReactNativeTcpWindows.js.map +1 -1
- package/lib/commonjs/index.js +37 -37
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/ReactNativeTcpWindows.js.map +1 -1
- package/lib/module/index.js +37 -37
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/commonjs/ReactNativeTcpWindows.d.ts.map +1 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -0
- package/lib/typescript/module/ReactNativeTcpWindows.d.ts.map +1 -0
- package/lib/typescript/module/index.d.ts.map +1 -0
- package/package.json +205 -204
- package/src/ReactNativeTcpWindows.ts +14 -14
- package/src/index.tsx +124 -124
- package/windows/ExperimentalFeatures.props +33 -33
- package/windows/ReactNativeTcpWindows/ReactNativeTcpWindows.cpp +206 -206
- package/windows/ReactNativeTcpWindows/ReactNativeTcpWindows.def +3 -3
- package/windows/ReactNativeTcpWindows/ReactNativeTcpWindows.h +83 -83
- package/windows/ReactNativeTcpWindows/ReactNativeTcpWindows.vcxproj +145 -145
- package/windows/ReactNativeTcpWindows/ReactNativeTcpWindows.vcxproj.filters +43 -43
- package/windows/ReactNativeTcpWindows/ReactPackageProvider.cpp +20 -20
- package/windows/ReactNativeTcpWindows/ReactPackageProvider.h +24 -24
- package/windows/ReactNativeTcpWindows/ReactPackageProvider.idl +9 -9
- package/windows/ReactNativeTcpWindows/TcpSocket.cpp +564 -564
- package/windows/ReactNativeTcpWindows/codegen/NativeReactNativeTcpWindowsSpec.g.h +71 -71
- package/windows/ReactNativeTcpWindows/packages.lock.json +59 -59
- package/windows/ReactNativeTcpWindows/pch.cpp +1 -1
- package/windows/ReactNativeTcpWindows/pch.h +30 -30
- package/windows/ReactNativeTcpWindows/resource.h +5 -5
- package/windows/ReactNativeTcpWindows/targetver.h +8 -8
- package/windows/ReactNativeTcpWindows.sln +43 -43
- package/lib/typescript/commonjs/src/ReactNativeTcpWindows.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/__tests__/index.test.d.ts +0 -1
- package/lib/typescript/commonjs/src/__tests__/index.test.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/index.d.ts.map +0 -1
- package/lib/typescript/module/src/ReactNativeTcpWindows.d.ts.map +0 -1
- package/lib/typescript/module/src/__tests__/index.test.d.ts +0 -1
- package/lib/typescript/module/src/__tests__/index.test.d.ts.map +0 -1
- package/lib/typescript/module/src/index.d.ts.map +0 -1
- /package/lib/typescript/commonjs/{src/ReactNativeTcpWindows.d.ts → ReactNativeTcpWindows.d.ts} +0 -0
- /package/lib/typescript/commonjs/{src/index.d.ts → index.d.ts} +0 -0
- /package/lib/typescript/module/{src/ReactNativeTcpWindows.d.ts → ReactNativeTcpWindows.d.ts} +0 -0
- /package/lib/typescript/module/{src/index.d.ts → index.d.ts} +0 -0
package/src/index.tsx
CHANGED
@@ -1,124 +1,124 @@
|
|
1
|
-
import { NativeEventEmitter } from 'react-native';
|
2
|
-
import TcpSocketWindows from './ReactNativeTcpWindows';
|
3
|
-
|
4
|
-
export const eventEmitter = new NativeEventEmitter(TcpSocketWindows);
|
5
|
-
export { TcpSocketWindows };
|
6
|
-
// Event types for better type safety
|
7
|
-
export const TCP_SOCKET_EVENTS = {
|
8
|
-
DATA_RECEIVED: 'TcpSocketDataReceived',
|
9
|
-
CLIENT_CONNECTED: 'TcpSocketClientConnected',
|
10
|
-
CLIENT_DISCONNECTED: 'TcpSocketClientDisconnected',
|
11
|
-
CONNECTION_STATUS_CHANGED: 'TcpSocketConnectionStatusChanged',
|
12
|
-
} as const;
|
13
|
-
|
14
|
-
export type TcpSocketEvent =
|
15
|
-
(typeof TCP_SOCKET_EVENTS)[keyof typeof TCP_SOCKET_EVENTS];
|
16
|
-
|
17
|
-
// Event data interfaces
|
18
|
-
export interface DataReceivedEvent {
|
19
|
-
data: number[];
|
20
|
-
}
|
21
|
-
|
22
|
-
export interface ClientConnectedEvent {
|
23
|
-
clientAddress: string;
|
24
|
-
}
|
25
|
-
|
26
|
-
export interface ClientDisconnectedEvent {
|
27
|
-
clientAddress: string;
|
28
|
-
}
|
29
|
-
|
30
|
-
export interface ConnectionStatusChangedEvent {
|
31
|
-
connected: boolean;
|
32
|
-
message: string;
|
33
|
-
}
|
34
|
-
|
35
|
-
/**
|
36
|
-
* Connect to a TCP server as a client
|
37
|
-
* @param address Server IP address (e.g., "192.168.1.100")
|
38
|
-
* @param port Server port number
|
39
|
-
* @returns Promise that resolves with success message
|
40
|
-
*/
|
41
|
-
export function connectToServer(
|
42
|
-
address: string,
|
43
|
-
port: number
|
44
|
-
): Promise<string> {
|
45
|
-
return TcpSocketWindows.connectToServer(address, port);
|
46
|
-
}
|
47
|
-
|
48
|
-
/**
|
49
|
-
* Start a TCP server to accept client connections
|
50
|
-
* @param port Port number to listen on
|
51
|
-
* @returns Promise that resolves with success message
|
52
|
-
*/
|
53
|
-
export function startServer(port: number): Promise<string> {
|
54
|
-
return TcpSocketWindows.startServer(port);
|
55
|
-
}
|
56
|
-
|
57
|
-
/**
|
58
|
-
* Close the current connection (client or server)
|
59
|
-
* @returns Promise that resolves with success message
|
60
|
-
*/
|
61
|
-
export function closeConnection(): Promise<string> {
|
62
|
-
return TcpSocketWindows.closeConnection();
|
63
|
-
}
|
64
|
-
|
65
|
-
/**
|
66
|
-
* Write data to the TCP connection
|
67
|
-
* For clients: sends to the connected server
|
68
|
-
* For servers: sends to all connected clients
|
69
|
-
* @param data Array of bytes to send (0-255)
|
70
|
-
* @returns Promise that resolves with success status
|
71
|
-
*/
|
72
|
-
export function write(data: number[]): Promise<boolean> {
|
73
|
-
return TcpSocketWindows.write(data);
|
74
|
-
}
|
75
|
-
|
76
|
-
/**
|
77
|
-
* Get the current connection status
|
78
|
-
* @returns Promise that resolves with connection status object
|
79
|
-
*/
|
80
|
-
export function getConnectionStatus(): Promise<boolean> {
|
81
|
-
return TcpSocketWindows.getConnectionStatus();
|
82
|
-
}
|
83
|
-
|
84
|
-
/**
|
85
|
-
* Write a string as UTF-8 bytes
|
86
|
-
* @param text String to send
|
87
|
-
* @returns Promise that resolves with success status
|
88
|
-
*/
|
89
|
-
export function writeString(text: string): Promise<boolean> {
|
90
|
-
const encoder = new TextEncoder();
|
91
|
-
const bytes = Array.from(encoder.encode(text));
|
92
|
-
return write(bytes);
|
93
|
-
}
|
94
|
-
|
95
|
-
/**
|
96
|
-
* Write JSON data as UTF-8 bytes
|
97
|
-
* @param data Object to serialize and send
|
98
|
-
* @returns Promise that resolves with success status
|
99
|
-
*/
|
100
|
-
export function writeJson(data: any): Promise<boolean> {
|
101
|
-
const jsonString = JSON.stringify(data);
|
102
|
-
return writeString(jsonString);
|
103
|
-
}
|
104
|
-
|
105
|
-
/**
|
106
|
-
* Convenience function to convert received byte array to string
|
107
|
-
* @param data Byte array from DataReceivedEvent
|
108
|
-
* @returns Decoded UTF-8 string
|
109
|
-
*/
|
110
|
-
export function bytesToString(data: number[]): string {
|
111
|
-
const uint8Array = new Uint8Array(data);
|
112
|
-
const decoder = new TextDecoder();
|
113
|
-
return decoder.decode(uint8Array);
|
114
|
-
}
|
115
|
-
|
116
|
-
/**
|
117
|
-
* Convenience function to convert received byte array to JSON
|
118
|
-
* @param data Byte array from DataReceivedEvent
|
119
|
-
* @returns Parsed JSON object
|
120
|
-
*/
|
121
|
-
export function bytesToJson(data: number[]): any {
|
122
|
-
const jsonString = bytesToString(data);
|
123
|
-
return JSON.parse(jsonString);
|
124
|
-
}
|
1
|
+
import { NativeEventEmitter } from 'react-native';
|
2
|
+
import TcpSocketWindows from './ReactNativeTcpWindows';
|
3
|
+
|
4
|
+
export const eventEmitter = new NativeEventEmitter(TcpSocketWindows);
|
5
|
+
export { TcpSocketWindows };
|
6
|
+
// Event types for better type safety
|
7
|
+
export const TCP_SOCKET_EVENTS = {
|
8
|
+
DATA_RECEIVED: 'TcpSocketDataReceived',
|
9
|
+
CLIENT_CONNECTED: 'TcpSocketClientConnected',
|
10
|
+
CLIENT_DISCONNECTED: 'TcpSocketClientDisconnected',
|
11
|
+
CONNECTION_STATUS_CHANGED: 'TcpSocketConnectionStatusChanged',
|
12
|
+
} as const;
|
13
|
+
|
14
|
+
export type TcpSocketEvent =
|
15
|
+
(typeof TCP_SOCKET_EVENTS)[keyof typeof TCP_SOCKET_EVENTS];
|
16
|
+
|
17
|
+
// Event data interfaces
|
18
|
+
export interface DataReceivedEvent {
|
19
|
+
data: number[];
|
20
|
+
}
|
21
|
+
|
22
|
+
export interface ClientConnectedEvent {
|
23
|
+
clientAddress: string;
|
24
|
+
}
|
25
|
+
|
26
|
+
export interface ClientDisconnectedEvent {
|
27
|
+
clientAddress: string;
|
28
|
+
}
|
29
|
+
|
30
|
+
export interface ConnectionStatusChangedEvent {
|
31
|
+
connected: boolean;
|
32
|
+
message: string;
|
33
|
+
}
|
34
|
+
|
35
|
+
/**
|
36
|
+
* Connect to a TCP server as a client
|
37
|
+
* @param address Server IP address (e.g., "192.168.1.100")
|
38
|
+
* @param port Server port number
|
39
|
+
* @returns Promise that resolves with success message
|
40
|
+
*/
|
41
|
+
export function connectToServer(
|
42
|
+
address: string,
|
43
|
+
port: number
|
44
|
+
): Promise<string> {
|
45
|
+
return TcpSocketWindows.connectToServer(address, port);
|
46
|
+
}
|
47
|
+
|
48
|
+
/**
|
49
|
+
* Start a TCP server to accept client connections
|
50
|
+
* @param port Port number to listen on
|
51
|
+
* @returns Promise that resolves with success message
|
52
|
+
*/
|
53
|
+
export function startServer(port: number): Promise<string> {
|
54
|
+
return TcpSocketWindows.startServer(port);
|
55
|
+
}
|
56
|
+
|
57
|
+
/**
|
58
|
+
* Close the current connection (client or server)
|
59
|
+
* @returns Promise that resolves with success message
|
60
|
+
*/
|
61
|
+
export function closeConnection(): Promise<string> {
|
62
|
+
return TcpSocketWindows.closeConnection();
|
63
|
+
}
|
64
|
+
|
65
|
+
/**
|
66
|
+
* Write data to the TCP connection
|
67
|
+
* For clients: sends to the connected server
|
68
|
+
* For servers: sends to all connected clients
|
69
|
+
* @param data Array of bytes to send (0-255)
|
70
|
+
* @returns Promise that resolves with success status
|
71
|
+
*/
|
72
|
+
export function write(data: number[]): Promise<boolean> {
|
73
|
+
return TcpSocketWindows.write(data);
|
74
|
+
}
|
75
|
+
|
76
|
+
/**
|
77
|
+
* Get the current connection status
|
78
|
+
* @returns Promise that resolves with connection status object
|
79
|
+
*/
|
80
|
+
export function getConnectionStatus(): Promise<boolean> {
|
81
|
+
return TcpSocketWindows.getConnectionStatus();
|
82
|
+
}
|
83
|
+
|
84
|
+
/**
|
85
|
+
* Write a string as UTF-8 bytes
|
86
|
+
* @param text String to send
|
87
|
+
* @returns Promise that resolves with success status
|
88
|
+
*/
|
89
|
+
export function writeString(text: string): Promise<boolean> {
|
90
|
+
const encoder = new TextEncoder();
|
91
|
+
const bytes = Array.from(encoder.encode(text));
|
92
|
+
return write(bytes);
|
93
|
+
}
|
94
|
+
|
95
|
+
/**
|
96
|
+
* Write JSON data as UTF-8 bytes
|
97
|
+
* @param data Object to serialize and send
|
98
|
+
* @returns Promise that resolves with success status
|
99
|
+
*/
|
100
|
+
export function writeJson(data: any): Promise<boolean> {
|
101
|
+
const jsonString = JSON.stringify(data);
|
102
|
+
return writeString(jsonString);
|
103
|
+
}
|
104
|
+
|
105
|
+
/**
|
106
|
+
* Convenience function to convert received byte array to string
|
107
|
+
* @param data Byte array from DataReceivedEvent
|
108
|
+
* @returns Decoded UTF-8 string
|
109
|
+
*/
|
110
|
+
export function bytesToString(data: number[]): string {
|
111
|
+
const uint8Array = new Uint8Array(data);
|
112
|
+
const decoder = new TextDecoder();
|
113
|
+
return decoder.decode(uint8Array);
|
114
|
+
}
|
115
|
+
|
116
|
+
/**
|
117
|
+
* Convenience function to convert received byte array to JSON
|
118
|
+
* @param data Byte array from DataReceivedEvent
|
119
|
+
* @returns Parsed JSON object
|
120
|
+
*/
|
121
|
+
export function bytesToJson(data: number[]): any {
|
122
|
+
const jsonString = bytesToString(data);
|
123
|
+
return JSON.parse(jsonString);
|
124
|
+
}
|
@@ -1,33 +1,33 @@
|
|
1
|
-
<?xml version="1.0" encoding="utf-8"?>
|
2
|
-
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
3
|
-
|
4
|
-
<PropertyGroup Label="Microsoft.ReactNative Experimental Features">
|
5
|
-
<!--
|
6
|
-
Required for building a New Architecture project.
|
7
|
-
|
8
|
-
Library projects can change this value to test against Old and New
|
9
|
-
Architectures when building the library project's local sln file.
|
10
|
-
|
11
|
-
Otherwise this value will be decided by the consuming RNW app.
|
12
|
-
|
13
|
-
See https://microsoft.github.io/react-native-windows/docs/new-architecture
|
14
|
-
-->
|
15
|
-
<RnwNewArch>true</RnwNewArch>
|
16
|
-
|
17
|
-
<!--
|
18
|
-
Changes compilation to assume use of Microsoft.ReactNative NuGet packages
|
19
|
-
instead of building the framework from source. Defaults to true.
|
20
|
-
|
21
|
-
This is set during library project creation and is used when building
|
22
|
-
the library project's local sln file.
|
23
|
-
|
24
|
-
Otherwise this value will be decided by the consuming RNW app.
|
25
|
-
|
26
|
-
See https://microsoft.github.io/react-native-windows/docs/nuget
|
27
|
-
-->
|
28
|
-
<UseExperimentalNuget>true</UseExperimentalNuget>
|
29
|
-
|
30
|
-
<ReactExperimentalFeaturesSet>true</ReactExperimentalFeaturesSet>
|
31
|
-
</PropertyGroup>
|
32
|
-
|
33
|
-
</Project>
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
3
|
+
|
4
|
+
<PropertyGroup Label="Microsoft.ReactNative Experimental Features">
|
5
|
+
<!--
|
6
|
+
Required for building a New Architecture project.
|
7
|
+
|
8
|
+
Library projects can change this value to test against Old and New
|
9
|
+
Architectures when building the library project's local sln file.
|
10
|
+
|
11
|
+
Otherwise this value will be decided by the consuming RNW app.
|
12
|
+
|
13
|
+
See https://microsoft.github.io/react-native-windows/docs/new-architecture
|
14
|
+
-->
|
15
|
+
<RnwNewArch>true</RnwNewArch>
|
16
|
+
|
17
|
+
<!--
|
18
|
+
Changes compilation to assume use of Microsoft.ReactNative NuGet packages
|
19
|
+
instead of building the framework from source. Defaults to true.
|
20
|
+
|
21
|
+
This is set during library project creation and is used when building
|
22
|
+
the library project's local sln file.
|
23
|
+
|
24
|
+
Otherwise this value will be decided by the consuming RNW app.
|
25
|
+
|
26
|
+
See https://microsoft.github.io/react-native-windows/docs/nuget
|
27
|
+
-->
|
28
|
+
<UseExperimentalNuget>true</UseExperimentalNuget>
|
29
|
+
|
30
|
+
<ReactExperimentalFeaturesSet>true</ReactExperimentalFeaturesSet>
|
31
|
+
</PropertyGroup>
|
32
|
+
|
33
|
+
</Project>
|