react-native-nitro-dgram 0.1.4 β†’ 0.1.5

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/README.md ADDED
@@ -0,0 +1,107 @@
1
+ # react-native-nitro-dgram πŸš€
2
+
3
+ Ultra-high-performance Node.js `dgram` (UDP) implementation for React Native. Powered by **Nitro Modules** (C++/JSI) and a robust **Rust core** for maximum efficiency and low latency.
4
+
5
+ [![license](https://img.shields.io/badge/license-ISC-blue.svg)](https://github.com/iwater/react-native-nitro-dgram/blob/main/LICENSE)
6
+ [![platform](https://img.shields.io/badge/platform-ios%20%7C%20android-lightgrey.svg)]()
7
+ [![compatibility](https://img.shields.io/badge/Node.js-100%25%20dgram-green.svg)]()
8
+ [δΈ­ζ–‡ζ–‡ζ‘£](./README_zh.md)
9
+
10
+ ## Why Nitro Dgram?
11
+
12
+ - **100% API Compatibility**: Drop-in replacement for Node's `dgram`. Move your server/client logic from Node to Mobile without changing a single line.
13
+ - **Nitro Powered**: Leveraging the next-gen Nitro Modules (JSI) for direct C++ to JS communication, bypassing the heavy React Native Bridge.
14
+ - **Rust Reliability**: The core socket logic is written in Rust, ensuring maximum safety, performance, and low-latency networking.
15
+ - **Modern Features**: Built-in support for `AbortSignal`, `AsyncDispose`, and `BlockList`.
16
+
17
+ ## Features
18
+
19
+ - [x] **Full dgram API**: `udp4` & `udp6` support.
20
+ - [x] **Connected Sockets**: Using `connect()` for dedicated peer communication.
21
+ - [x] **Multicast**: Full support for joining/dropping groups, including **SSM (Source-Specific Multicast)**.
22
+ - [x] **Scatter-Gather I/O**: Send multiple buffers in a single syscall via `send([buf1, buf2], ...)`.
23
+ - [x] **Queue Monitoring**: Real-time tracking of pending send bytes and packet counts.
24
+ - [x] **Security**: Integrated `BlockList` for IP-level filtering.
25
+ - [x] **Resource Management**: Native `AbortSignal` integration and `Symbol.asyncDispose`.
26
+
27
+ ## Installation
28
+
29
+ ```bash
30
+ yarn add react-native-nitro-dgram react-native-nitro-buffer
31
+ # or
32
+ npm install react-native-nitro-dgram react-native-nitro-buffer
33
+ ```
34
+
35
+ ## Quick Start
36
+
37
+ ```typescript
38
+ import { createSocket } from 'react-native-nitro-dgram';
39
+ import { Buffer } from 'react-native-nitro-buffer';
40
+
41
+ const server = createSocket('udp4');
42
+
43
+ server.on('message', (msg, rinfo) => {
44
+ console.log(`Received ${msg.length} bytes from ${rinfo.address}:${rinfo.port}`);
45
+ // Echo back
46
+ server.send(msg, rinfo.port, rinfo.address);
47
+ });
48
+
49
+ server.on('listening', () => {
50
+ const address = server.address();
51
+ console.log(`Server listening on ${address.address}:${address.port}`);
52
+ });
53
+
54
+ server.bind(41234);
55
+ ```
56
+
57
+ ## Advanced Usage
58
+
59
+ ### Source-Specific Multicast (SSM)
60
+
61
+ ```typescript
62
+ const socket = createSocket('udp4');
63
+ socket.bind(12345, () => {
64
+ // Join a group only from a specific source
65
+ socket.addSourceSpecificMembership('192.168.1.100', '232.0.0.1');
66
+ });
67
+ ```
68
+
69
+ ### Sending Multiple Buffers (Scatter-Gather)
70
+
71
+ ```typescript
72
+ const part1 = Buffer.from('Hello ');
73
+ const part2 = Buffer.from('World!');
74
+
75
+ // Sends both buffers in a single efficient native operation
76
+ socket.send([part1, part2], 41234, '127.0.0.1');
77
+ ```
78
+
79
+ ### Queue Monitoring
80
+
81
+ ```typescript
82
+ // Useful for implementing backpressure or monitoring throughput
83
+ const pendingPackets = socket.getSendQueueCount();
84
+ const pendingBytes = socket.getSendQueueSize();
85
+ ```
86
+
87
+ ## Architecture
88
+
89
+ ```mermaid
90
+ graph LR
91
+ JS[JavaScript App] -- JSI --> Nitro[Nitro Modules C++]
92
+ Nitro -- FFI --> Rust[Rust Core]
93
+ Rust -- System --> OS[iOS/Android Network Stack]
94
+ ```
95
+
96
+ ## Comparison
97
+
98
+ | Feature | `react-native-udp` (Bridge) | `react-native-nitro-dgram` |
99
+ | :--- | :--- | :--- |
100
+ | **Communication** | Async Bridge (JSON/Base64) | Synchronous JSI (Ultra-Fast) |
101
+ | **Buffer Handling** | Base64 Encoding | Direct Memory Access |
102
+ | **Compatibility** | Partial | 100% Node.js Dgram |
103
+ | **Core Engine** | Native Java/ObjC | Zero-Cost Rust |
104
+
105
+ ## License
106
+
107
+ ISC
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-nitro-dgram",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "πŸš€ Ultra-high-performance Node.js dgram (UDP) implementation for React Native. Powered by Nitro Modules and a robust Rust core for maximum efficiency and low latency.",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",
@@ -56,4 +56,4 @@
56
56
  "nitrogen/",
57
57
  "*.podspec"
58
58
  ]
59
- }
59
+ }
@@ -33,9 +33,7 @@ Pod::Spec.new do |s|
33
33
  "\"$(PODS_TARGET_SRCROOT)/nitrogen/generated/shared\"",
34
34
  "\"$(PODS_TARGET_SRCROOT)/nitrogen/generated/ios/c++\"",
35
35
  "\"$(PODS_TARGET_SRCROOT)/nitrogen/generated/ios\"",
36
- "\"$(PODS_TARGET_SRCROOT)/cpp\"",
37
- "\"$(PODS_TARGET_SRCROOT)/ios/Frameworks/RustCUdp.xcframework/ios-arm64/RustCUdp.framework/Headers\"",
38
- "\"$(PODS_TARGET_SRCROOT)/ios/Frameworks/RustCUdp.xcframework/ios-arm64_x86_64-simulator/RustCUdp.framework/Headers\""
36
+ "\"$(PODS_TARGET_SRCROOT)/cpp\""
39
37
  ],
40
38
  "OTHER_SWIFT_FLAGS" => "-cxx-interoperability-mode=default"
41
39
  }