Events
Subscribe to real-time events to build reactive UIs and handle PTT communication.
Subscribing to Events
// Subscribe to an event
const handler = (event) => {
console.log('Event received:', event);
};
client.on('broadcast_start', handler);
// Unsubscribe when done
client.off('broadcast_start', handler);
Connection Events
connection_change
Fired when the connection status changes.
client.on('connection_change', (event: ConnectionChangeEvent) => {
console.log('Connected:', event.connected);
console.log('Status:', event.status);
});
// ConnectionChangeEvent:
// {
// connected: boolean, // true if fully connected
// status: 'connected' | 'connecting' | 'disconnected'
// }
| Property | Type | Description |
|---|---|---|
connected |
boolean |
True when both Socket and WebRTC are connected |
status |
ConnectionStatus |
Current connection state |
Broadcast Events
broadcast_start
Fired when someone starts speaking.
client.on('broadcast_start', (event: BroadcastStartEvent) => {
console.log(`${event.senderName} started speaking in ${event.channelId}`);
});
// BroadcastStartEvent:
// {
// channelId: string,
// senderId: string,
// senderName: string,
// messageId?: string,
// timestamp: number
// }
broadcast_end
Fired when someone stops speaking.
client.on('broadcast_end', (event: BroadcastEndEvent) => {
console.log(`User ${event.senderId} stopped speaking`);
});
// BroadcastEndEvent:
// {
// channelId: string,
// senderId: string,
// timestamp: number
// }
playback_progress
Fired during audio playback with current progress.
client.on('playback_progress', (event: PlaybackProgressEvent) => {
console.log(`Playback duration: ${event.duration} seconds`);
});
// PlaybackProgressEvent:
// {
// duration: number // seconds elapsed
// }
Channel Events
new_channel
Fired when a new channel is created.
client.on('new_channel', (event: NewChannelEvent) => {
console.log('New channel:', event.channel.channelName);
});
// NewChannelEvent:
// {
// channel: {
// channelId: string,
// channelName: string,
// channelType: 'group' | 'direct'
// },
// timestamp: number
// }
room_name_update
Fired when a channel is renamed.
client.on('room_name_update', (event: RoomNameUpdateEvent) => {
console.log(`Channel ${event.channelId} renamed to ${event.newName}`);
});
// RoomNameUpdateEvent:
// {
// channelId: string,
// newName: string,
// timestamp: number
// }
room_participant_added
Fired when a user is added to a channel.
client.on('room_participant_added', (event: ParticipantAddedEvent) => {
console.log(`${event.userName} joined channel ${event.channelId}`);
});
// ParticipantAddedEvent:
// {
// channelId: string,
// userId: string,
// userName: string,
// timestamp: number
// }
room_participant_removed
Fired when a user is removed from a channel.
client.on('room_participant_removed', (event: ParticipantRemovedEvent) => {
console.log(`User ${event.userId} left channel ${event.channelId}`);
});
// ParticipantRemovedEvent:
// {
// channelId: string,
// userId: string,
// timestamp: number
// }
room_admin_added
Fired when a user is promoted to admin.
client.on('room_admin_added', (event: AdminAddedEvent) => {
console.log(`User ${event.userId} is now admin of ${event.channelId}`);
});
// AdminAddedEvent:
// {
// channelId: string,
// userId: string,
// timestamp: number
// }
room_admin_removed
Fired when admin privileges are removed from a user.
client.on('room_admin_removed', (event: AdminRemovedEvent) => {
console.log(`User ${event.userId} is no longer admin of ${event.channelId}`);
});
// AdminRemovedEvent:
// {
// channelId: string,
// userId: string,
// timestamp: number
// }
User Events
new_sdk_user
Fired when a new user is created in the workspace.
client.on('new_sdk_user', (event: NewSdkUserEvent) => {
console.log(`New user: ${event.userName}`);
});
// NewSdkUserEvent:
// {
// userId: string,
// userName: string,
// timestamp: number
// }
Live Status Events
Live status indicates a user's availability for real-time audio. A channel is live when at least one participant is live.
room_live_status
Fired when a channel's live status changes. A channel becomes live when the first participant goes live, and drops from live when the last participant drops.
client.on('room_live_status', (event: RoomLiveStatusEvent) => {
if (event.live) {
console.log(`Channel ${event.channelId} is now live!`);
} else {
console.log(`Channel ${event.channelId} is no longer live`);
}
});
// RoomLiveStatusEvent:
// {
// channelId: string,
// live: boolean,
// timestamp: number
// }
room_participant_live_status
Fired when a participant goes live or drops from live in a channel.
client.on('room_participant_live_status', (event: ParticipantLiveStatusEvent) => {
if (event.live) {
console.log(`User ${event.participantId} is now live in ${event.channelId}`);
} else {
console.log(`User ${event.participantId} dropped from live in ${event.channelId}`);
}
});
// ParticipantLiveStatusEvent:
// {
// channelId: string,
// participantId: string,
// live: boolean,
// timestamp: number
// }
room_participant_ptt_status
Fired when a participant changes their PTT mode setting.
client.on('room_participant_ptt_status', (event: ParticipantPttStatusEvent) => {
console.log(`User ${event.participantId} PTT mode: ${event.pttMode}`);
});
// ParticipantPttStatusEvent:
// {
// channelId: string,
// participantId: string,
// pttMode: string,
// timestamp: number
// }
Message Events
message
Fired when a text or file message is received.
client.on('message', (event: MessageEvent) => {
const { message } = event;
console.log(`${message.senderName}: ${message.text}`);
});
// MessageEvent:
// {
// message: {
// messageId: string,
// channelId: string,
// senderId: string,
// senderName: string,
// type: string,
// text?: string,
// mediaUrl?: string,
// timestamp: string
// }
// }
Event Summary
| Event | Type | Description |
|---|---|---|
connection_change |
ConnectionChangeEvent |
Connection status changed |
broadcast_start |
BroadcastStartEvent |
Someone started speaking |
broadcast_end |
BroadcastEndEvent |
Someone stopped speaking |
playback_progress |
PlaybackProgressEvent |
Audio playback progress |
new_channel |
NewChannelEvent |
New channel created |
room_name_update |
RoomNameUpdateEvent |
Channel renamed |
room_participant_added |
ParticipantAddedEvent |
User added to channel |
room_participant_removed |
ParticipantRemovedEvent |
User removed from channel |
room_admin_added |
AdminAddedEvent |
User promoted to admin |
room_admin_removed |
AdminRemovedEvent |
Admin privileges removed |
new_sdk_user |
NewSdkUserEvent |
New user created |
room_live_status |
RoomLiveStatusEvent |
Channel live status changed |
room_participant_live_status |
ParticipantLiveStatusEvent |
Participant joined/left live session |
room_participant_ptt_status |
ParticipantPttStatusEvent |
Participant PTT mode changed |
message |
MessageEvent |
Message received |