@rajeev02/network
v0.2.2
Published
Connectivity-aware networking layer — real-time status, adaptive quality, priority request queue, HTTP cache, gzip compression
Maintainers
Readme
@rajeev02/network
Connectivity-aware networking layer with real-time status monitoring, adaptive quality suggestions, persistent priority request queue, HTTP cache, and gzip compression.
Powered by a Rust core (rajeev-network-core) compiled to native (iOS/Android via UniFFI) and WASM (Web).
Platform Support
| Platform | Engine | Binding |
| -------------------- | ------------ | --------------- |
| iOS 16+ | Rust → UniFFI | Swift |
| Android 7+ (API 24) | Rust → UniFFI | Kotlin |
| Web | Rust → WASM | wasm-bindgen |
| watchOS 9+ / Wear OS | Rust → UniFFI | Native |
| Android Auto | Rust → UniFFI | Kotlin |
Installation
npm install @rajeev02/networkQuick Start
import { RajeevNetwork } from '@rajeev02/network';
const network = new RajeevNetwork({
appId: 'my-app',
dbDir: '/data/network',
enableQueue: true,
enableCache: true,
autoCompress: true,
});
// Update connectivity status
network.updateStatus('wifi', 50000, 30, false);
// Adaptive suggestions
const timeout = network.getSuggestedTimeoutMs(); // 10000
const quality = network.getSuggestedImageQuality(); // { quality: 'High', ... }
// Request queue (offline-first)
const id = network.enqueueRequest(
'POST', 'https://api.example.com/data',
'{"Content-Type":"application/json"}',
JSON.stringify({ key: 'value' }),
'high', true, 'api'
);
// HTTP cache
network.cacheResponse('GET', '/api/users', 200, '{}', data, 300);
const cached = network.getCached('GET', '/api/users');
// Compression
import { compressString, shouldCompress } from '@rajeev02/network';
if (shouldCompress(payload)) {
const compressed = compressString(payload);
}API Reference
| Method | Description |
|--------|-------------|
| updateStatus(type, kbps, rtt, saveData) | Update network connectivity |
| getStatus() | Get current network state |
| getSuggestedTimeoutMs() | Adaptive timeout based on quality |
| getSuggestedImageQuality() | Adaptive image quality suggestion |
| recordTransfer(bytes, ms) | Record transfer for bandwidth estimation |
| getEstimatedBandwidthKbps() | EWMA bandwidth estimate |
| enqueueRequest(...) | Add to priority offline queue |
| dequeueRequest() | Get next request to send |
| completeRequest(id) | Mark request completed |
| failRequest(id) | Schedule retry with backoff |
| getCached(method, url) | Retrieve cached response |
| cacheResponse(...) | Cache an HTTP response |
| getCacheStats() | Cache hit/miss statistics |
| cleanup() | Remove expired entries |
License
MIT © Rajeev Kumar Joshi
