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/client

Channels

Choose one or more channels when creating a connection. The browser WebRTC transport provides encrypted media and data via DTLS/SRTP and DTLS/SCTP.

ChannelUse caseNotes
audioMicrophone streamsRequests getUserMedia audio and emits localstream and remotestream events.
videoCamera streamsRequests getUserMedia video and shares the resulting media tracks over WebRTC.
dataMessages and app stateCreates the managed RTCDataChannel named radist-data for text, JSON, or binary payloads.

API reference

Constructor options

OptionTypeDescription
publicKeystringRequired project public key used for additional token minting and WebSocket authentication.
rtcConfigurationRTCConfigurationOptional RTCPeerConnection config, such as custom STUN or TURN servers.
fetchFetchLikeOptional fetch override used by mintToken().
webSocketFactory(url: string) => WebSocketOptional websocket factory for tests, wrappers, or custom browser integrations.

Methods

SymbolReturnsDescription
new RadistClient(options)RadistClientBrowser-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)() => voidSubscribes to a connection event and returns an unsubscribe function.
connection.off(event, listener)voidRemoves a listener registered with on().
connection.reconnect()Promise<void>Reconnects an interrupted session using the stored callId, peerId, and reconnectToken.
connection.disconnect()voidSends a leave message when possible and closes the local session state.
RadistApiErrorError with statusThrown when mintToken() or the initial API handshake receives an unsuccessful HTTP response.

Connection events

EventPayloadDescription
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

PropertyTypeDescription
stateidle | connecting | waiting-for-peer | connected | disconnected | closed | errorCurrent high-level lifecycle state.
statusstringHuman-readable status text for logs and UI.
callId, peerId, remotePeerId, reconnectTokenstring | nullSession identity values populated after the signaling handshake succeeds.
rolehost | guest | nullPeer role inferred from the signaling session.
canReconnectbooleanTrue after an interrupted session still has reconnect metadata available.
peerConnectionRTCPeerConnection | nullUnderlying WebRTC peer connection instance.
localStream, remoteStreamMediaStream | nullCurrent local and remote media streams.
dataChannelRTCDataChannel | nullManaged Radist data channel labeled radist-data.

Behavior notes

  • The package expects browser APIs: WebSocket, RTCPeerConnection, and navigator.mediaDevices when audio or video is requested.
  • At least one channel must be selected: audio, video, or data.
  • Use canReconnect after a disconnect to decide whether to call reconnect().

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();