TalkerClient
API for real-time push-to-talk communication. Use this class to enable PTT features in your application.
TalkerClient includes a built-in audio player that automatically plays incoming broadcasts. Received broadcasts are queued and played in order — no manual audio setup is needed. You can control playback, select audio devices, and adjust volume using the methods documented below.
Constructor
import { TalkerClient } from '@talker-network/talker-sdk';
const client = new TalkerClient({
userAuthToken: string, // Required: From TalkerAdmin
userId: string, // Required: From TalkerAdmin (filters own broadcasts)
a_username: string, // Required: From TalkerAdmin
a_password: string, // Required: From TalkerAdmin
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,
},
});
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> |
// 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
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) |
// 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> |
// 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> |
// 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 |
// 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() |
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 |
// 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('channel_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('channel_participant_live_status', (event) => {
console.log(`User ${event.participantMobileNo} 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[]> |
Stream Capturing
Access raw audio streams for custom processing, visualization, speech-to-text, or recording.
Incoming Audio Stream
The audio_received event provides raw PCM audio data from incoming broadcasts.
| Property |
Value |
| Format |
PCM (raw samples) |
| Bit Depth |
16-bit signed integer |
| Sample Rate |
16000 Hz |
| Channels |
1 (mono) |
// Access raw incoming audio
talker.on('audio_received', (pcmData: ArrayBuffer) => {
const samples = new Int16Array(pcmData);
// Example: Audio visualization
let sum = 0;
for (let i = 0; i < samples.length; i++) {
sum += Math.abs(samples[i]);
}
const level = sum / samples.length / 32768;
updateWaveform(level);
});
// Example: Recording to WAV
const audioChunks: Int16Array[] = [];
talker.on('broadcast_start', () => {
audioChunks.length = 0; // Clear previous
});
talker.on('audio_received', (pcmData: ArrayBuffer) => {
audioChunks.push(new Int16Array(pcmData));
});
talker.on('broadcast_end', () => {
const wavBlob = createWavFile(audioChunks, 16000);
saveRecording(wavBlob);
});
// Example: Speech-to-text integration
talker.on('audio_received', (pcmData: ArrayBuffer) => {
speechRecognizer.feedAudio(pcmData);
});
The SDK automatically plays received audio through the speaker. The audio_received event provides a copy of the raw data for additional processing without affecting playback.
Messaging
| Method |
Description |
Returns |
sendMessage(channelId, content) |
Send text/file message |
Promise<void> |
// Send text message
await talker.sendMessage('channel-id', { text: 'Hello team!' });
// Send image with caption
await talker.sendMessage('channel-id', {
file: imageFile, // File or Blob (image/* detected automatically)
description: 'Photo from today',
});
// Send document
await talker.sendMessage('channel-id', {
file: documentFile, // Non-image files sent as 'document'
});
// Listen for incoming messages
talker.on('message', (event) => {
const { senderId, description, attachments, sentAt } = event.message;
if (attachments?.images) {
console.log('Image URLs:', attachments.images);
}
if (description) {
console.log('Text:', description);
}
});
Event Methods
Subscribe to events using on() and unsubscribe with off().
// 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.