TalkerClient

Frontend API for real-time push-to-talk communication. Use this class in your browser application to enable PTT features.

Constructor

TypeScript
import { TalkerClient } from '@talker-network/talker-sdk';

const client = new TalkerClient({
  userAuthToken: string,    // Required: From backend
  userId: string,           // Required: From backend (filters own broadcasts)
  a_username: string,       // Required: From backend
  a_password: string,       // Required: From backend
  baseUrl?: string,         // Optional: API base URL
  socketUrl?: string,       // Optional: Socket.IO URL
  loggerConfig?: {          // Optional: Logger configuration
    level?: LogLevel,       // DEBUG, INFO, WARN, ERROR, OFF
    enableConsole?: boolean,
    customHandler?: (entry: LogEntry) => void,
  },
});
Auto-Connect

Connection to servers starts automatically on initialization. Monitor status via getConnectionStatus() or the connection_change event.

Connection Methods

Method Description Returns
getConnectionStatus() Get connection status { connected: boolean, status: ConnectionStatus }
isFullyConnected() Check if ready for PTT boolean
connect() Manually trigger connection void
reconnect() Force reconnection Promise<boolean>
disconnect() Disconnect from all services Promise<void>
TypeScript
// Check connection status
const { connected, status } = talker.getConnectionStatus();
// status: 'connected' | 'connecting' | 'disconnected'

// Check if ready for PTT
if (talker.isFullyConnected()) {
  console.log('Ready to talk!');
}

// Force reconnection
const success = await talker.reconnect();

// Disconnect when done
await talker.disconnect();

Push-to-Talk Methods

Method Description Returns
startTalking(channelId) Start recording and streaming Promise<StartTalkingResult>
stopTalking(channelId?) Stop recording Promise<void>
isTalking() Check if currently talking boolean

StartTalkingResult

TypeScript
interface StartTalkingResult {
  success: boolean;
  code: 'success' | 'already_talking' | 'not_connected' | 'no_user_id' | 'channel_busy' | 'error';
  message: string;
}
Code Success Description
success true PTT started successfully
already_talking true Already in a PTT session (no action needed)
not_connected false Not connected, auto-reconnecting in background
no_user_id false User ID not set
channel_busy false Channel is busy, someone else is talking
error false Other error (check message)
TypeScript
// PTT flow with deterministic handling
const result = await talker.startTalking('channel-id');

if (!result.success) {
  switch (result.code) {
    case 'not_connected':
      // Show "Connecting..." UI, retry after connection_change event
      break;
    case 'channel_busy':
      // Someone else is talking on this channel
      showToast('Channel is busy. Please wait...');
      break;
    case 'no_user_id':
      // Developer error - userId not provided
      console.error(result.message);
      break;
    case 'error':
      // Show error to user
      alert(result.message);
      break;
  }
}

// Release button
await talker.stopTalking();

Audio Control Methods

Method Description Returns
setSpeakerEnabled(enabled) Enable/disable audio playback void
setVolume(volume) Set playback volume (0-1) void
setMicrophoneEnabled(enabled) Enable/disable microphone void
getAudioLevel() Get current mic input level (0-1) number
unlockAudio() Unlock audio context (required for iOS/Safari) Promise<void>
TypeScript
// Volume control
talker.setVolume(0.8);

// Mute speaker
talker.setSpeakerEnabled(false);

// Mute microphone
talker.setMicrophoneEnabled(false);

// Get mic level for UI visualization
const level = talker.getAudioLevel();

// Unlock audio on iOS/Safari (call on user interaction)
document.addEventListener('click', () => {
  talker.unlockAudio();
}, { once: true });

Audio Device Selection

Method Description Returns
getAudioInputDevices() List available microphones Promise<MediaDeviceInfo[]>
getAudioOutputDevices() List available speakers Promise<MediaDeviceInfo[]>
setAudioInputDevice(deviceId) Select microphone Promise<void>
setAudioOutputDevice(deviceId) Select speaker Promise<void>
TypeScript
// List and select devices
const microphones = await talker.getAudioInputDevices();
await talker.setAudioInputDevice(microphones[1].deviceId);

const speakers = await talker.getAudioOutputDevices();
await talker.setAudioOutputDevice(speakers[0].deviceId);

Playback Queue Methods

The SDK automatically queues incoming broadcasts and plays them in order.

Method Description Returns
pauseQueue() Pause queue (current playback continues) void
resumeQueue() Resume queue processing void
stopPlaybackAndPause() Stop current playback and pause queue void
getPlaybackQueueLength() Get number of pending broadcasts number
getCurrentlyPlaying() Get currently playing broadcast BroadcastStartEvent | null
TypeScript
// Pause incoming broadcasts while user is busy
talker.pauseQueue();

// Later, resume
talker.resumeQueue();

// Need immediate silence
talker.stopPlaybackAndPause();

// Check queue status
console.log(`${talker.getPlaybackQueueLength()} broadcasts waiting`);

// Get current broadcast
const playing = talker.getCurrentlyPlaying();
if (playing) {
  console.log(`Now playing from ${playing.senderName}`);
}

Channel Methods

Method Description Returns
getChannels(workspaceId?) Get channels list Promise<Channel[]>
createChannel(config) Create a channel Promise<{ channelId, channelName }>
leaveChannel(channelId) Leave a channel Promise<void>
addParticipant(channelId, userId) Add user to channel Promise<void>
removeParticipant(channelId, userId) Remove user from channel Promise<void>
addAdmin(channelId, userId) Make user admin Promise<void>
removeAdmin(channelId, userId) Remove admin privileges Promise<void>
updateChannelName(channelId, name) Rename channel Promise<void>

Live Status Methods

Live status indicates a user's availability for real-time audio communication in a channel. When a user is "live", they can send and receive audio instantly. A channel becomes live when at least one participant is live.

Method Description Returns
goLive(channelId) Set yourself as live in a channel Promise<void>
dropFromLive(channelId) Remove yourself from live in a channel Promise<void>
isLive(channelId) Check if you are live in a channel boolean
TypeScript
// Go live in a channel (available for real-time audio)
await talker.goLive('channel-id');

// Check your live status
if (talker.isLive('channel-id')) {
  console.log('You are live and can send/receive audio');
}

// Drop from live (no longer available for real-time audio)
await talker.dropFromLive('channel-id');

// Listen for channel live status changes
talker.on('room_live_status', (event) => {
  // Channel goes live when first participant goes live
  // Channel drops from live when last participant drops
  console.log(`Channel ${event.channelId} is ${event.live ? 'live' : 'not live'}`);
});

// Listen for participant live status changes
talker.on('room_participant_live_status', (event) => {
  console.log(`User ${event.participantId} is ${event.live ? 'live' : 'not live'}`);
});

User Methods

Method Description Returns
setUserId(userId) Set current user ID void
getUserId() Get current user ID string | null
getAllUsers() Get all workspace users Promise<UserInfo[]>

Messaging

Method Description Returns
sendMessage(channelId, content) Send text/file message Promise<void>
TypeScript
// Send text message
await talker.sendMessage('channel-id', { text: 'Hello!' });

// Send file
await talker.sendMessage('channel-id', {
  file: fileInput.files[0],
  description: 'Photo from today',
});

Event Methods

Subscribe to events using on() and unsubscribe with off().

TypeScript
// Subscribe to an event
const handler = (event) => console.log(event);
talker.on('broadcast_start', handler);

// Unsubscribe
talker.off('broadcast_start', handler);

See the Events page for a complete list of available events.