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 API and WebSocket authentication.
rtcConfigurationRTCConfigurationOptional RTCPeerConnection config, such as custom STUN or TURN servers.
fetchFetchLikeOptional fetch override used by space metadata and admission requests.
webSocketFactory(url: string) => WebSocketOptional websocket factory for tests, wrappers, or custom browser integrations.

Methods

SymbolReturnsDescription
new RadistClient(options)RadistClientBrowser-only constructor for creating call, room, and space handles.
call(callToken).connect({ channels })Promise<RadistConnection>Connects to a P2P call using a server-issued participant token.
room(roomToken).connect({ channels? })Promise<RadistRoomConnection>Connects to a multi-party SFU room using a server-issued room token.
space(slug).info()Promise<SpaceInfo>Reads safe space metadata including its name and admission type.
space(slug).connect({ name, password?, channels? })Promise<RadistRoomConnection>Runs persistent-space admission, then connects through the ordinary room API.
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 an API request or initial signaling handshake is unsuccessful.

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.call(callToken).connect({
  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 room(roomToken).connect() 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.room(roomToken).connect({
  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();