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.
Files changed (42) hide show
  1. package/lib/commonjs/ReactNativeTcpWindows.js.map +1 -1
  2. package/lib/commonjs/index.js +37 -37
  3. package/lib/commonjs/index.js.map +1 -1
  4. package/lib/module/ReactNativeTcpWindows.js.map +1 -1
  5. package/lib/module/index.js +37 -37
  6. package/lib/module/index.js.map +1 -1
  7. package/lib/typescript/commonjs/ReactNativeTcpWindows.d.ts.map +1 -0
  8. package/lib/typescript/commonjs/index.d.ts.map +1 -0
  9. package/lib/typescript/module/ReactNativeTcpWindows.d.ts.map +1 -0
  10. package/lib/typescript/module/index.d.ts.map +1 -0
  11. package/package.json +205 -204
  12. package/src/ReactNativeTcpWindows.ts +14 -14
  13. package/src/index.tsx +124 -124
  14. package/windows/ExperimentalFeatures.props +33 -33
  15. package/windows/ReactNativeTcpWindows/ReactNativeTcpWindows.cpp +206 -206
  16. package/windows/ReactNativeTcpWindows/ReactNativeTcpWindows.def +3 -3
  17. package/windows/ReactNativeTcpWindows/ReactNativeTcpWindows.h +83 -83
  18. package/windows/ReactNativeTcpWindows/ReactNativeTcpWindows.vcxproj +145 -145
  19. package/windows/ReactNativeTcpWindows/ReactNativeTcpWindows.vcxproj.filters +43 -43
  20. package/windows/ReactNativeTcpWindows/ReactPackageProvider.cpp +20 -20
  21. package/windows/ReactNativeTcpWindows/ReactPackageProvider.h +24 -24
  22. package/windows/ReactNativeTcpWindows/ReactPackageProvider.idl +9 -9
  23. package/windows/ReactNativeTcpWindows/TcpSocket.cpp +564 -564
  24. package/windows/ReactNativeTcpWindows/codegen/NativeReactNativeTcpWindowsSpec.g.h +71 -71
  25. package/windows/ReactNativeTcpWindows/packages.lock.json +59 -59
  26. package/windows/ReactNativeTcpWindows/pch.cpp +1 -1
  27. package/windows/ReactNativeTcpWindows/pch.h +30 -30
  28. package/windows/ReactNativeTcpWindows/resource.h +5 -5
  29. package/windows/ReactNativeTcpWindows/targetver.h +8 -8
  30. package/windows/ReactNativeTcpWindows.sln +43 -43
  31. package/lib/typescript/commonjs/src/ReactNativeTcpWindows.d.ts.map +0 -1
  32. package/lib/typescript/commonjs/src/__tests__/index.test.d.ts +0 -1
  33. package/lib/typescript/commonjs/src/__tests__/index.test.d.ts.map +0 -1
  34. package/lib/typescript/commonjs/src/index.d.ts.map +0 -1
  35. package/lib/typescript/module/src/ReactNativeTcpWindows.d.ts.map +0 -1
  36. package/lib/typescript/module/src/__tests__/index.test.d.ts +0 -1
  37. package/lib/typescript/module/src/__tests__/index.test.d.ts.map +0 -1
  38. package/lib/typescript/module/src/index.d.ts.map +0 -1
  39. /package/lib/typescript/commonjs/{src/ReactNativeTcpWindows.d.ts → ReactNativeTcpWindows.d.ts} +0 -0
  40. /package/lib/typescript/commonjs/{src/index.d.ts → index.d.ts} +0 -0
  41. /package/lib/typescript/module/{src/ReactNativeTcpWindows.d.ts → ReactNativeTcpWindows.d.ts} +0 -0
  42. /package/lib/typescript/module/{src/index.d.ts → index.d.ts} +0 -0
@@ -1,206 +1,206 @@
1
- #include "pch.h"
2
- #include "ReactNativeTcpWindows.h"
3
- #include "TcpSocket.h"
4
- namespace winrt::ReactNativeTcpWindows
5
- {
6
-
7
- // See https://microsoft.github.io/react-native-windows/docs/native-platform for help writing native modules
8
-
9
- void ReactNativeTcpWindows::Initialize(React::ReactContext const &reactContext) noexcept {
10
- m_context = reactContext;
11
- OutputDebugStringA("ReactNativeTcpWindows::Initialize called\n");
12
- // m_tcpSocket = std::make_unique<TcpSocket>("127.0.0.1", 1234, TcpSocket::ConnectionType::Client);
13
- if (m_tcpSocket) {
14
- m_tcpSocket->close();
15
- m_tcpSocket.reset();
16
- OutputDebugStringA("Existing TcpSocket instance closed during Initialize\n");
17
- }
18
- }
19
-
20
- ReactNativeTcpWindows::~ReactNativeTcpWindows() {
21
- OutputDebugStringA("ReactNativeTcpWindows destructor called\n");
22
-
23
- if (m_tcpSocket) {
24
- m_tcpSocket->close(); // Calls TcpSocket::close
25
- m_tcpSocket.reset(); // Triggers TcpSocket destructor
26
- }
27
- }
28
-
29
- // double ReactNativeTcpWindows::multiply(double a, double b) noexcept {
30
- // return a * b;
31
- // }
32
- void ReactNativeTcpWindows::connectToServer(std::string address, double port,
33
- React::ReactPromise<std::string> &&promise) noexcept {
34
- try {
35
- OutputDebugStringA(("Connecting to TCP server:\n"
36
- "Address: " + address + "\n"
37
- "Port: " + std::to_string(static_cast<int>(port)) + "\n").c_str());
38
-
39
- // Close existing connection if any
40
- if (m_tcpSocket) {
41
- m_tcpSocket->close();
42
- m_tcpSocket.reset();
43
- }
44
-
45
- m_tcpSocket = std::make_unique<TcpSocket>(address, static_cast<int>(port), TcpSocket::ConnectionType::Client);
46
-
47
- // Set up callbacks
48
- m_tcpSocket->setDataReceivedCallback([this](const std::vector<uint8_t>& data) {
49
- OnDataReceived(data);
50
- });
51
-
52
- m_tcpSocket->setConnectionStatusCallback([this, promise](bool connected, const std::string& message) {
53
- OnConnectionStatusChanged(connected, message);
54
- if (connected) {
55
- promise.Resolve("Connected to server successfully");
56
- } else {
57
- promise.Reject(React::ReactError{"Error", message});
58
- }
59
- });
60
-
61
- // Attempt connection
62
- if (!m_tcpSocket->connect()) {
63
- promise.Reject(React::ReactError{"Error", "Failed to initiate connection"});
64
- }
65
- // Note: Promise will be resolved/rejected in the connection status callback
66
-
67
- } catch (const std::exception& e) {
68
- promise.Reject(React::ReactError{"Error", e.what()});
69
- }
70
- }
71
-
72
- void ReactNativeTcpWindows::startServer(double port,
73
- React::ReactPromise<std::string> &&promise) noexcept {
74
- try {
75
- OutputDebugStringA(("Starting TCP server on port: " + std::to_string(static_cast<int>(port)) + "\n").c_str());
76
-
77
- // Close existing connection if any
78
- if (m_tcpSocket) {
79
- m_tcpSocket->close();
80
- m_tcpSocket.reset();
81
- }
82
-
83
- m_tcpSocket = std::make_unique<TcpSocket>("0.0.0.0", static_cast<int>(port), TcpSocket::ConnectionType::Server);
84
-
85
- // Set up callbacks
86
- m_tcpSocket->setDataReceivedCallback([this](const std::vector<uint8_t>& data) {
87
- OnDataReceived(data);
88
- });
89
-
90
- m_tcpSocket->setClientConnectedCallback([this](const std::string& clientAddress) {
91
- OnClientConnected(clientAddress);
92
- });
93
-
94
- m_tcpSocket->setClientDisconnectedCallback([this](const std::string& clientAddress) {
95
- OnClientDisconnected(clientAddress);
96
- });
97
-
98
- m_tcpSocket->setConnectionStatusCallback([this](bool connected, const std::string& message) {
99
- OnConnectionStatusChanged(connected, message);
100
- });
101
-
102
- if (m_tcpSocket->startServer()) {
103
- promise.Resolve("TCP server started successfully on port " + std::to_string(static_cast<int>(port)));
104
- } else {
105
- promise.Reject(React::ReactError{"Error", "Failed to start TCP server"});
106
- }
107
-
108
- } catch (const std::exception& e) {
109
- promise.Reject(React::ReactError{"Error", e.what()});
110
- }
111
- }
112
-
113
- void ReactNativeTcpWindows::closeConnection(React::ReactPromise<std::string> &&promise) noexcept {
114
- try {
115
- OutputDebugStringA("Called Close Connection for TCP socket...\n");
116
- if (m_tcpSocket) {
117
- OutputDebugStringA("Closing TCP socket...\n");
118
- m_tcpSocket->close();
119
- m_tcpSocket.reset();
120
- promise.Resolve("Connection closed successfully");
121
- } else {
122
- OutputDebugStringA("No active TCP socket to close.\n");
123
- promise.Reject(React::ReactError{ "Error", "No connection open" });
124
- }
125
- } catch (const std::exception& e) {
126
- std::string errorMsg = std::string("Exception in closeConnection: ") + e.what();
127
- OutputDebugStringA(errorMsg.c_str());
128
- promise.Reject(React::ReactError{"Exception", errorMsg});
129
- } catch (...) {
130
- OutputDebugStringA("Unknown exception in closeConnection\n");
131
- promise.Reject(React::ReactError{"Exception", "Unknown exception in closeConnection"});
132
- }
133
- }
134
-
135
- void ReactNativeTcpWindows::write(std::vector<double> const& data,
136
- React::ReactPromise<bool> &&promise) noexcept {
137
- if (!m_tcpSocket) {
138
- promise.Reject("No connection open");
139
- return;
140
- }
141
-
142
- std::vector<uint8_t> byteData;
143
- byteData.reserve(data.size());
144
- for (const auto& value : data) {
145
- byteData.push_back(static_cast<uint8_t>(value));
146
- }
147
-
148
- promise.Resolve(m_tcpSocket->write(byteData));
149
- }
150
-
151
- void ReactNativeTcpWindows::getConnectionStatus(
152
- React::ReactPromise<bool> &&promise
153
- ) noexcept {
154
- bool isConnected = m_tcpSocket ? m_tcpSocket->isConnected() : false;
155
- promise.Resolve(isConnected);
156
- }
157
- void ReactNativeTcpWindows::OnDataReceived(const std::vector<uint8_t>& data) {
158
- if (m_context) {
159
- auto eventData = winrt::Microsoft::ReactNative::JSValueObject();
160
- winrt::Microsoft::ReactNative::JSValueArray jsDataArray;
161
- for (auto byte : data) {
162
- jsDataArray.push_back(static_cast<int>(byte));
163
- }
164
-
165
- eventData["data"] = std::move(jsDataArray);
166
-
167
- m_context.EmitJSEvent(L"RCTDeviceEventEmitter", L"TcpSocketDataReceived", eventData);
168
- }
169
- }
170
-
171
- void ReactNativeTcpWindows::OnClientConnected(const std::string& clientAddress) {
172
- if (m_context) {
173
- auto eventData = winrt::Microsoft::ReactNative::JSValueObject();
174
- eventData["clientAddress"] = clientAddress;
175
-
176
- m_context.EmitJSEvent(L"RCTDeviceEventEmitter", L"TcpSocketClientConnected", eventData);
177
- }
178
- }
179
-
180
- void ReactNativeTcpWindows::OnClientDisconnected(const std::string& clientAddress) {
181
- if (m_context) {
182
- auto eventData = winrt::Microsoft::ReactNative::JSValueObject();
183
- eventData["clientAddress"] = clientAddress;
184
-
185
- m_context.EmitJSEvent(L"RCTDeviceEventEmitter", L"TcpSocketClientDisconnected", eventData);
186
- }
187
- }
188
-
189
- void ReactNativeTcpWindows::OnConnectionStatusChanged(bool connected, const std::string& message) {
190
- if (m_context) {
191
- auto eventData = winrt::Microsoft::ReactNative::JSValueObject();
192
- eventData["connected"] = connected;
193
- eventData["message"] = message;
194
-
195
- m_context.EmitJSEvent(L"RCTDeviceEventEmitter", L"TcpSocketConnectionStatusChanged", eventData);
196
- }
197
- }
198
-
199
- void ReactNativeTcpWindows::addListener(std::string eventType) noexcept {
200
- // Event listener management - can be implemented if needed
201
- }
202
-
203
- void ReactNativeTcpWindows::removeListeners(double count) noexcept {
204
- // Event listener management - can be implemented if needed
205
- }
206
- } // namespace winrt::ReactNativeTcpWindows
1
+ #include "pch.h"
2
+ #include "ReactNativeTcpWindows.h"
3
+ #include "TcpSocket.h"
4
+ namespace winrt::ReactNativeTcpWindows
5
+ {
6
+
7
+ // See https://microsoft.github.io/react-native-windows/docs/native-platform for help writing native modules
8
+
9
+ void ReactNativeTcpWindows::Initialize(React::ReactContext const &reactContext) noexcept {
10
+ m_context = reactContext;
11
+ OutputDebugStringA("ReactNativeTcpWindows::Initialize called\n");
12
+ // m_tcpSocket = std::make_unique<TcpSocket>("127.0.0.1", 1234, TcpSocket::ConnectionType::Client);
13
+ if (m_tcpSocket) {
14
+ m_tcpSocket->close();
15
+ m_tcpSocket.reset();
16
+ OutputDebugStringA("Existing TcpSocket instance closed during Initialize\n");
17
+ }
18
+ }
19
+
20
+ ReactNativeTcpWindows::~ReactNativeTcpWindows() {
21
+ OutputDebugStringA("ReactNativeTcpWindows destructor called\n");
22
+
23
+ if (m_tcpSocket) {
24
+ m_tcpSocket->close(); // Calls TcpSocket::close
25
+ m_tcpSocket.reset(); // Triggers TcpSocket destructor
26
+ }
27
+ }
28
+
29
+ // double ReactNativeTcpWindows::multiply(double a, double b) noexcept {
30
+ // return a * b;
31
+ // }
32
+ void ReactNativeTcpWindows::connectToServer(std::string address, double port,
33
+ React::ReactPromise<std::string> &&promise) noexcept {
34
+ try {
35
+ OutputDebugStringA(("Connecting to TCP server:\n"
36
+ "Address: " + address + "\n"
37
+ "Port: " + std::to_string(static_cast<int>(port)) + "\n").c_str());
38
+
39
+ // Close existing connection if any
40
+ if (m_tcpSocket) {
41
+ m_tcpSocket->close();
42
+ m_tcpSocket.reset();
43
+ }
44
+
45
+ m_tcpSocket = std::make_unique<TcpSocket>(address, static_cast<int>(port), TcpSocket::ConnectionType::Client);
46
+
47
+ // Set up callbacks
48
+ m_tcpSocket->setDataReceivedCallback([this](const std::vector<uint8_t>& data) {
49
+ OnDataReceived(data);
50
+ });
51
+
52
+ m_tcpSocket->setConnectionStatusCallback([this, promise](bool connected, const std::string& message) {
53
+ OnConnectionStatusChanged(connected, message);
54
+ if (connected) {
55
+ promise.Resolve("Connected to server successfully");
56
+ } else {
57
+ promise.Reject(React::ReactError{"Error", message});
58
+ }
59
+ });
60
+
61
+ // Attempt connection
62
+ if (!m_tcpSocket->connect()) {
63
+ promise.Reject(React::ReactError{"Error", "Failed to initiate connection"});
64
+ }
65
+ // Note: Promise will be resolved/rejected in the connection status callback
66
+
67
+ } catch (const std::exception& e) {
68
+ promise.Reject(React::ReactError{"Error", e.what()});
69
+ }
70
+ }
71
+
72
+ void ReactNativeTcpWindows::startServer(double port,
73
+ React::ReactPromise<std::string> &&promise) noexcept {
74
+ try {
75
+ OutputDebugStringA(("Starting TCP server on port: " + std::to_string(static_cast<int>(port)) + "\n").c_str());
76
+
77
+ // Close existing connection if any
78
+ if (m_tcpSocket) {
79
+ m_tcpSocket->close();
80
+ m_tcpSocket.reset();
81
+ }
82
+
83
+ m_tcpSocket = std::make_unique<TcpSocket>("0.0.0.0", static_cast<int>(port), TcpSocket::ConnectionType::Server);
84
+
85
+ // Set up callbacks
86
+ m_tcpSocket->setDataReceivedCallback([this](const std::vector<uint8_t>& data) {
87
+ OnDataReceived(data);
88
+ });
89
+
90
+ m_tcpSocket->setClientConnectedCallback([this](const std::string& clientAddress) {
91
+ OnClientConnected(clientAddress);
92
+ });
93
+
94
+ m_tcpSocket->setClientDisconnectedCallback([this](const std::string& clientAddress) {
95
+ OnClientDisconnected(clientAddress);
96
+ });
97
+
98
+ m_tcpSocket->setConnectionStatusCallback([this](bool connected, const std::string& message) {
99
+ OnConnectionStatusChanged(connected, message);
100
+ });
101
+
102
+ if (m_tcpSocket->startServer()) {
103
+ promise.Resolve("TCP server started successfully on port " + std::to_string(static_cast<int>(port)));
104
+ } else {
105
+ promise.Reject(React::ReactError{"Error", "Failed to start TCP server"});
106
+ }
107
+
108
+ } catch (const std::exception& e) {
109
+ promise.Reject(React::ReactError{"Error", e.what()});
110
+ }
111
+ }
112
+
113
+ void ReactNativeTcpWindows::closeConnection(React::ReactPromise<std::string> &&promise) noexcept {
114
+ try {
115
+ OutputDebugStringA("Called Close Connection for TCP socket...\n");
116
+ if (m_tcpSocket) {
117
+ OutputDebugStringA("Closing TCP socket...\n");
118
+ m_tcpSocket->close();
119
+ m_tcpSocket.reset();
120
+ promise.Resolve("Connection closed successfully");
121
+ } else {
122
+ OutputDebugStringA("No active TCP socket to close.\n");
123
+ promise.Reject(React::ReactError{ "Error", "No connection open" });
124
+ }
125
+ } catch (const std::exception& e) {
126
+ std::string errorMsg = std::string("Exception in closeConnection: ") + e.what();
127
+ OutputDebugStringA(errorMsg.c_str());
128
+ promise.Reject(React::ReactError{"Exception", errorMsg});
129
+ } catch (...) {
130
+ OutputDebugStringA("Unknown exception in closeConnection\n");
131
+ promise.Reject(React::ReactError{"Exception", "Unknown exception in closeConnection"});
132
+ }
133
+ }
134
+
135
+ void ReactNativeTcpWindows::write(std::vector<double> const& data,
136
+ React::ReactPromise<bool> &&promise) noexcept {
137
+ if (!m_tcpSocket) {
138
+ promise.Reject("No connection open");
139
+ return;
140
+ }
141
+
142
+ std::vector<uint8_t> byteData;
143
+ byteData.reserve(data.size());
144
+ for (const auto& value : data) {
145
+ byteData.push_back(static_cast<uint8_t>(value));
146
+ }
147
+
148
+ promise.Resolve(m_tcpSocket->write(byteData));
149
+ }
150
+
151
+ void ReactNativeTcpWindows::getConnectionStatus(
152
+ React::ReactPromise<bool> &&promise
153
+ ) noexcept {
154
+ bool isConnected = m_tcpSocket ? m_tcpSocket->isConnected() : false;
155
+ promise.Resolve(isConnected);
156
+ }
157
+ void ReactNativeTcpWindows::OnDataReceived(const std::vector<uint8_t>& data) {
158
+ if (m_context) {
159
+ auto eventData = winrt::Microsoft::ReactNative::JSValueObject();
160
+ winrt::Microsoft::ReactNative::JSValueArray jsDataArray;
161
+ for (auto byte : data) {
162
+ jsDataArray.push_back(static_cast<int>(byte));
163
+ }
164
+
165
+ eventData["data"] = std::move(jsDataArray);
166
+
167
+ m_context.EmitJSEvent(L"RCTDeviceEventEmitter", L"TcpSocketDataReceived", eventData);
168
+ }
169
+ }
170
+
171
+ void ReactNativeTcpWindows::OnClientConnected(const std::string& clientAddress) {
172
+ if (m_context) {
173
+ auto eventData = winrt::Microsoft::ReactNative::JSValueObject();
174
+ eventData["clientAddress"] = clientAddress;
175
+
176
+ m_context.EmitJSEvent(L"RCTDeviceEventEmitter", L"TcpSocketClientConnected", eventData);
177
+ }
178
+ }
179
+
180
+ void ReactNativeTcpWindows::OnClientDisconnected(const std::string& clientAddress) {
181
+ if (m_context) {
182
+ auto eventData = winrt::Microsoft::ReactNative::JSValueObject();
183
+ eventData["clientAddress"] = clientAddress;
184
+
185
+ m_context.EmitJSEvent(L"RCTDeviceEventEmitter", L"TcpSocketClientDisconnected", eventData);
186
+ }
187
+ }
188
+
189
+ void ReactNativeTcpWindows::OnConnectionStatusChanged(bool connected, const std::string& message) {
190
+ if (m_context) {
191
+ auto eventData = winrt::Microsoft::ReactNative::JSValueObject();
192
+ eventData["connected"] = connected;
193
+ eventData["message"] = message;
194
+
195
+ m_context.EmitJSEvent(L"RCTDeviceEventEmitter", L"TcpSocketConnectionStatusChanged", eventData);
196
+ }
197
+ }
198
+
199
+ void ReactNativeTcpWindows::addListener(std::string eventType) noexcept {
200
+ // Event listener management - can be implemented if needed
201
+ }
202
+
203
+ void ReactNativeTcpWindows::removeListeners(double count) noexcept {
204
+ // Event listener management - can be implemented if needed
205
+ }
206
+ } // namespace winrt::ReactNativeTcpWindows
@@ -1,3 +1,3 @@
1
- EXPORTS
2
- DllCanUnloadNow = WINRT_CanUnloadNow PRIVATE
3
- DllGetActivationFactory = WINRT_GetActivationFactory PRIVATE
1
+ EXPORTS
2
+ DllCanUnloadNow = WINRT_CanUnloadNow PRIVATE
3
+ DllGetActivationFactory = WINRT_GetActivationFactory PRIVATE
@@ -1,83 +1,83 @@
1
- #pragma once
2
-
3
- #include "pch.h"
4
- #include "resource.h"
5
- #include "TcpSocket.h"
6
-
7
- #if __has_include("codegen/NativeReactNativeTcpWindowsDataTypes.g.h")
8
- #include "codegen/NativeReactNativeTcpWindowsDataTypes.g.h"
9
- #endif
10
- #include "codegen/NativeReactNativeTcpWindowsSpec.g.h"
11
-
12
- #include "NativeModules.h"
13
-
14
-
15
- namespace winrt::ReactNativeTcpWindows
16
- {
17
-
18
- // See https://microsoft.github.io/react-native-windows/docs/native-platform for help writing native modules
19
-
20
- REACT_MODULE(ReactNativeTcpWindows)
21
-
22
- struct ReactNativeTcpWindows
23
- {
24
- using ModuleSpec = ReactNativeTcpWindowsCodegen::ReactNativeTcpWindowsSpec;
25
-
26
- REACT_INIT(Initialize)
27
- void Initialize(React::ReactContext const &reactContext) noexcept;
28
-
29
- ~ReactNativeTcpWindows(); // Add this to the struct
30
-
31
- // REACT_SYNC_METHOD(multiply)
32
- // double multiply(double a, double b) noexcept;
33
-
34
- REACT_METHOD(connectToServer)
35
- void connectToServer(std::string address, double port,
36
- React::ReactPromise<std::string> &&promise) noexcept;
37
-
38
- REACT_METHOD(startServer)
39
- void startServer(double port,
40
- React::ReactPromise<std::string> &&promise) noexcept;
41
-
42
- REACT_METHOD(closeConnection)
43
- void closeConnection(React::ReactPromise<std::string> &&promise) noexcept;
44
-
45
- REACT_METHOD(write)
46
- void write(std::vector<double> const& data, React::ReactPromise<bool> &&promise) noexcept;
47
-
48
- // REACT_METHOD(getConnectionStatus)
49
- // void getConnectionStatus(React::ReactPromise<winrt::Microsoft::ReactNative::JSValueObject> &&promise) noexcept;
50
-
51
-
52
- REACT_METHOD(getConnectionStatus)
53
- void getConnectionStatus(React::ReactPromise<bool> &&promise) noexcept;
54
-
55
- REACT_METHOD(addListener)
56
- void addListener(std::string eventType) noexcept;
57
-
58
- REACT_METHOD(removeListeners)
59
- void removeListeners(double count) noexcept;
60
-
61
- void OnDataReceived(const std::vector<uint8_t>& data);
62
- void OnClientConnected(const std::string& clientAddress);
63
- void OnClientDisconnected(const std::string& clientAddress);
64
- void OnConnectionStatusChanged(bool connected, const std::string& message);
65
-
66
- private:
67
- React::ReactContext m_context;
68
- std::unique_ptr<TcpSocket> m_tcpSocket;
69
- };
70
- // {
71
- // using ModuleSpec = ReactNativeTcpWindowsCodegen::ReactNativeTcpWindowsSpec;
72
-
73
- // REACT_INIT(Initialize)
74
- // void Initialize(React::ReactContext const &reactContext) noexcept;
75
-
76
- // REACT_SYNC_METHOD(multiply)
77
- // double multiply(double a, double b) noexcept;
78
-
79
- // private:
80
- // React::ReactContext m_context;
81
- // };
82
-
83
- } // namespace winrt::ReactNativeTcpWindows
1
+ #pragma once
2
+
3
+ #include "pch.h"
4
+ #include "resource.h"
5
+ #include "TcpSocket.h"
6
+
7
+ #if __has_include("codegen/NativeReactNativeTcpWindowsDataTypes.g.h")
8
+ #include "codegen/NativeReactNativeTcpWindowsDataTypes.g.h"
9
+ #endif
10
+ #include "codegen/NativeReactNativeTcpWindowsSpec.g.h"
11
+
12
+ #include "NativeModules.h"
13
+
14
+
15
+ namespace winrt::ReactNativeTcpWindows
16
+ {
17
+
18
+ // See https://microsoft.github.io/react-native-windows/docs/native-platform for help writing native modules
19
+
20
+ REACT_MODULE(ReactNativeTcpWindows)
21
+
22
+ struct ReactNativeTcpWindows
23
+ {
24
+ using ModuleSpec = ReactNativeTcpWindowsCodegen::ReactNativeTcpWindowsSpec;
25
+
26
+ REACT_INIT(Initialize)
27
+ void Initialize(React::ReactContext const &reactContext) noexcept;
28
+
29
+ ~ReactNativeTcpWindows(); // Add this to the struct
30
+
31
+ // REACT_SYNC_METHOD(multiply)
32
+ // double multiply(double a, double b) noexcept;
33
+
34
+ REACT_METHOD(connectToServer)
35
+ void connectToServer(std::string address, double port,
36
+ React::ReactPromise<std::string> &&promise) noexcept;
37
+
38
+ REACT_METHOD(startServer)
39
+ void startServer(double port,
40
+ React::ReactPromise<std::string> &&promise) noexcept;
41
+
42
+ REACT_METHOD(closeConnection)
43
+ void closeConnection(React::ReactPromise<std::string> &&promise) noexcept;
44
+
45
+ REACT_METHOD(write)
46
+ void write(std::vector<double> const& data, React::ReactPromise<bool> &&promise) noexcept;
47
+
48
+ // REACT_METHOD(getConnectionStatus)
49
+ // void getConnectionStatus(React::ReactPromise<winrt::Microsoft::ReactNative::JSValueObject> &&promise) noexcept;
50
+
51
+
52
+ REACT_METHOD(getConnectionStatus)
53
+ void getConnectionStatus(React::ReactPromise<bool> &&promise) noexcept;
54
+
55
+ REACT_METHOD(addListener)
56
+ void addListener(std::string eventType) noexcept;
57
+
58
+ REACT_METHOD(removeListeners)
59
+ void removeListeners(double count) noexcept;
60
+
61
+ void OnDataReceived(const std::vector<uint8_t>& data);
62
+ void OnClientConnected(const std::string& clientAddress);
63
+ void OnClientDisconnected(const std::string& clientAddress);
64
+ void OnConnectionStatusChanged(bool connected, const std::string& message);
65
+
66
+ private:
67
+ React::ReactContext m_context;
68
+ std::unique_ptr<TcpSocket> m_tcpSocket;
69
+ };
70
+ // {
71
+ // using ModuleSpec = ReactNativeTcpWindowsCodegen::ReactNativeTcpWindowsSpec;
72
+
73
+ // REACT_INIT(Initialize)
74
+ // void Initialize(React::ReactContext const &reactContext) noexcept;
75
+
76
+ // REACT_SYNC_METHOD(multiply)
77
+ // double multiply(double a, double b) noexcept;
78
+
79
+ // private:
80
+ // React::ReactContext m_context;
81
+ // };
82
+
83
+ } // namespace winrt::ReactNativeTcpWindows