Client SDK
@radist-tech/client
Browser SDK for connecting with participant tokens, managing the WebRTC session lifecycle, and exchanging encrypted media or data between participants.
Install
Shell
npm install @radist-tech/clientChannels
Choose one or more channels when creating a connection. The browser WebRTC transport provides encrypted media and data via DTLS/SRTP and DTLS/SCTP.
| Channel | Use case | Notes |
|---|---|---|
| audio | Microphone streams | Requests getUserMedia audio and emits localstream and remotestream events. |
| video | Camera streams | Requests getUserMedia video and shares the resulting media tracks over WebRTC. |
| data | Messages and app state | Creates the managed RTCDataChannel named radist-data for text, JSON, or binary payloads. |
API reference
Constructor options
| Option | Type | Description |
|---|---|---|
| publicKey | string | Required project public key used for additional token minting and WebSocket authentication. |
| rtcConfiguration | RTCConfiguration | Optional RTCPeerConnection config, such as custom STUN or TURN servers. |
| fetch | FetchLike | Optional fetch override used by mintToken(). |
| webSocketFactory | (url: string) => WebSocket | Optional websocket factory for tests, wrappers, or custom browser integrations. |
Methods
| Symbol | Returns | Description |
|---|---|---|
| new RadistClient(options) | RadistClient | Browser-only constructor for minting tokens and creating managed connections. |
| mintToken({ callId }) | Promise<string> | Mints an additional participant token for an existing P2P call. |
| createConnection({ callToken, channels }) | Promise<RadistConnection> | Creates a connected RadistConnection with at least one encrypted WebRTC channel: audio, video, or data. |
| createRoomConnection({ roomToken, channels? }) | Promise<RadistRoomConnection> | Creates a connected room session for multi-party calls and participant stream events. |
| connection.on(event, listener) | () => void | Subscribes to a connection event and returns an unsubscribe function. |
| connection.off(event, listener) | void | Removes a listener registered with on(). |
| connection.reconnect() | Promise<void> | Reconnects an interrupted session using the stored callId, peerId, and reconnectToken. |
| connection.disconnect() | void | Sends a leave message when possible and closes the local session state. |
| RadistApiError | Error with status | Thrown when mintToken() or the initial API handshake receives an unsuccessful HTTP response. |
Connection events
| Event | Payload | Description |
|---|---|---|
| statechange | { state, status } | Connection lifecycle updates such as connecting, waiting-for-peer, or connected. |
| localstream | { stream } | Emitted after getUserMedia succeeds for audio or video channels. |
| remotestream | { stream } | Emitted when the remote MediaStream becomes available. |
| datachannel | { channel } | Emitted when the managed encrypted RTCDataChannel has been created or received. |
| error | { error, code? } | Raised for signaling, transport, or protocol errors. |
Connection properties
| Property | Type | Description |
|---|---|---|
| state | idle | connecting | waiting-for-peer | connected | disconnected | closed | error | Current high-level lifecycle state. |
| status | string | Human-readable status text for logs and UI. |
| callId, peerId, remotePeerId, reconnectToken | string | null | Session identity values populated after the signaling handshake succeeds. |
| role | host | guest | null | Peer role inferred from the signaling session. |
| canReconnect | boolean | True after an interrupted session still has reconnect metadata available. |
| peerConnection | RTCPeerConnection | null | Underlying WebRTC peer connection instance. |
| localStream, remoteStream | MediaStream | null | Current local and remote media streams. |
| dataChannel | RTCDataChannel | null | Managed Radist data channel labeled radist-data. |
Behavior notes
- The package expects browser APIs:
WebSocket,RTCPeerConnection, andnavigator.mediaDeviceswhen audio or video is requested. - At least one channel must be selected:
audio,video, ordata. - Use
canReconnectafter a disconnect to decide whether to callreconnect().
P2P example
Connect with a server-issued token, wire up stream and state events, and handle reconnection.
TypeScript
import { RadistClient } from '@radist-tech/client';
const radist = new RadistClient({
publicKey: 'rad_pk_abc123...'
});
const { callToken } = await fetch('/api/radist/session').then(
(response) => response.json() as Promise<{ callToken: string }>
);
const connection = await radist.createConnection({
callToken,
channels: ['audio', 'video', 'data']
});
connection.on('statechange', ({ state, status }) => {
console.log(state, status);
});
connection.on('remotestream', ({ stream }) => {
const video = document.querySelector('video#remote');
if (video) video.srcObject = stream;
});
connection.on('datachannel', ({ channel }) => {
channel.addEventListener('message', (e) => console.log(e.data));
});
// Later:
if (connection.canReconnect) {
await connection.reconnect();
}
connection.disconnect();Room example
Use createRoomConnection() with a backend-issued room token for multi-party calls.
TypeScript
import { RadistClient } from '@radist-tech/client';
const radist = new RadistClient({ publicKey: 'rad_pk_abc123...' });
const { roomToken } = await fetch('/api/radist/room-session').then(
(response) => response.json() as Promise<{ roomToken: string }>
);
const room = await radist.createRoomConnection({
roomToken,
channels: ['audio', 'video']
});
room.on('localstream', ({ stream }) => {
const local = document.querySelector('video#local');
if (local) local.srcObject = stream;
});
room.on('participantstream', ({ peerId, stream }) => {
console.log('participant stream', peerId, stream);
});
room.on('participantleft', ({ peerId }) => {
console.log('participant left', peerId);
});
room.disconnect();