Quick Start
Get up and running with the Talker Web SDK in minutes.
Overview
The Talker SDK provides two main classes for building PTT applications:
TalkerAdmin- For managing users, channels, and credentials (uses SDK key)TalkerClient- For real-time PTT communication (uses user auth token)
Keep your SDK key secret. Avoid exposing it in publicly accessible code.
TalkerAdmin Setup
Use TalkerAdmin to create users and manage credentials.
import { TalkerAdmin } from '@talker-network/talker-sdk';
// Initialize with your SDK key (keep secret!)
const admin = new TalkerAdmin({
sdkKey: process.env.TALKER_SDK_KEY!,
});
// Create a new user
const user = await admin.createUser({ name: 'John Doe' });
// Or get an existing user
const existingUser = await admin.setUser({ userId: 'existing-user-id' });
// Use these credentials to initialize TalkerClient
const credentials = {
userAuthToken: user.userAuthToken,
userId: user.userId,
a_username: user.aUsername,
a_password: user.aPassword,
};
TalkerClient Setup
Use TalkerClient with credentials from TalkerAdmin to enable real-time communication.
import { TalkerClient } from '@talker-network/talker-sdk';
// Use credentials obtained from TalkerAdmin
// Initialize client - connection starts automatically
const talker = new TalkerClient({
userAuthToken,
userId,
a_username,
a_password,
});
// Monitor connection status
talker.on('connection_change', ({ connected, status }) => {
console.log(`Connection: ${status}`);
// status: 'connected' | 'connecting' | 'disconnected'
});
// Listen to broadcast events
talker.on('broadcast_start', (data) => {
console.log(`${data.senderName} started speaking`);
});
talker.on('broadcast_end', (data) => {
console.log(`User ${data.senderId} stopped speaking`);
});
The SDK includes a built-in audio player that automatically plays incoming broadcasts. No additional audio setup is required — received broadcasts are queued and played in order. You can control playback with pauseQueue(), resumeQueue(), and stopPlaybackAndPause(). See Audio Devices for speaker selection and volume control.
Push-to-Talk Implementation
Implement PTT with simple event handlers.
// PTT button handlers
const pttButton = document.getElementById('ptt-button');
pttButton.onmousedown = async () => {
const result = await talker.startTalking(channelId);
if (!result.success) {
switch (result.code) {
case 'not_connected':
// Show "Connecting..." UI
break;
case 'error':
alert(result.message);
break;
}
}
};
pttButton.onmouseup = () => talker.stopTalking();
PTT Result Codes
The startTalking() method returns a result object with the following codes:
| 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 |
error |
false | Other error (check message) |
Connection States
The SDK manages connections automatically. Monitor the status to update your UI:
| Status | Meaning |
|---|---|
connected |
Socket and WebRTC data channel both connected, ready for PTT |
connecting |
Connection is being established |
disconnected |
Not connected (will auto-reconnect) |
The SDK automatically reconnects if the connection is lost. If startTalking() is called while disconnected, reconnection is triggered automatically.
Next Steps
- Installation - Detailed installation instructions
- TalkerAdmin API - User and channel management
- TalkerClient API - Real-time communication
- React Integration - React hooks and patterns