React Native

React Native SDK

A thin layer over the JavaScript SDK: the protocol is implemented once, in the core, and this package adds the one thing React Native needs on top of it — reacting to the app lifecycle.

Installation

npm install @raucheacho/konet-js @raucheacho/konet-rn

The core is a peer dependency, so there is a single copy of the protocol at runtime and core fixes apply without republishing this package.

No native module and no linking step: React Native provides the WebSocket global the core builds on.

Quick Start

import { createNativeClient } from '@raucheacho/konet-rn'
 
const client = createNativeClient('wss://konet.example.com/socket', {
  token: session.konetToken,
})
 
const map = client.channel('room:team-42:map')
await map.subscribe()
 
map.on('pos', (p) => updateMarker(p))
map.send('pos', { lat, lng, ts: Date.now() })

Channels, presence, send errors and options are the core API — see the JavaScript SDK.

What It Adds

React Native suspends timers while an app is backgrounded. An app can return to the foreground believing it is connected long after the server timed the socket out at 45s, because no close event ever fired in the frozen process.

KonetNativeClient subscribes to AppState and calls the core's checkConnection() on every return to the foreground: it probes the socket and reconnects if the probe goes unanswered. Channels are re-joined automatically.

That is the entire delta. If you already manage the lifecycle yourself, use KonetClient from the core and call checkConnection() where it fits.

Binary Frames & Floor Control

They work on a phone exactly as in a browser, with no native module: React Native's WebSocket supports binaryType = "arraybuffer", so the JavaScript core handles the framing.

const channel = client.channel('room:team-42:ptt')
await channel.subscribe()
 
channel.on('a', (data: Uint8Array) => { /* an incoming frame */ })
 
await channel.acquireFloor()
channel.sendBinary('a', frame)
await channel.releaseFloor()

Encoding the audio itself is a separate problem — React Native has no Opus — and is not part of this SDK. See the protocol page.

Client Options

interface KonetNativeClientOptions extends KonetClientOptions {
  appState?: AppStateLike | null   // override or disable AppState wiring
}

appState defaults to React Native's AppState. Pass null to opt out of foreground checks; pass your own implementation to drive the client from a different lifecycle source, or in tests.

Background Execution

Keeping a socket alive while the app is backgrounded is an app-level concern, not an SDK one, and the platforms differ sharply:

  • Android — a foreground service keeps the process, and the socket, alive. Declare the service types you actually use (location, microphone), plus FOREGROUND_SERVICE_MICROPHONE on Android 14+.
  • iOS — the OS suspends the app seconds after backgrounding, with no general-purpose exemption for holding a socket open. Waking on incoming data requires a push: the PushToTalk framework (iOS 16+, needs the com.apple.developer.push-to-talk entitlement) for walkie-talkie apps, or PushKit + CallKit for call-shaped ones.

This SDK's job is to recover cleanly once your app runs again.