Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.streampixel.io/llms.txt

Use this file to discover all available pages before exploring further.

The SDK includes a voice and text chat system built on LiveKit, separate from the video stream. This enables real-time communication between users viewing the same stream or application.

Video tutorial

Import

import { StreamPixelVoiceChat } from 'streampixelsdk';

Creating a chat instance

const voiceChat = new StreamPixelVoiceChat(
  'my-room',       // Room name — users in the same room can communicate
  'John',          // Display name for this user
  true,            // Enable voice chat (true) or text-only (false)
  'https://example.com/avatar.png',  // Avatar URL
  true             // Start with microphone enabled
);

Constructor parameters

ParameterTypeDescription
roomNamestringRoom identifier. Users in the same room can communicate.
userNamestringDisplay name for this user
voiceChatbooleantrue to enable voice chat, false for text-only
avatarstringURL to the user’s avatar image
micStartbooleantrue to start with microphone enabled (only applies if voiceChat is true)

Joining and leaving

// Join the room
await voiceChat.join();

// Leave the room
await voiceChat.leave();
join() automatically:
  • Fetches an access token from the Streampixel API
  • Connects to the LiveKit server
  • Subscribes to other participants’ audio tracks
  • Enables the microphone if micStart is true

Voice controls

// Toggle microphone on/off
await voiceChat.toggleMic();

Muting other participants

// Mute all remote participants (local only — does not affect their actual mic)
await voiceChat.muteAllRemote();

// Unmute all remote participants
await voiceChat.unmuteAllRemote();

// Mute a specific participant by their identity
await voiceChat.muteSelected('user123');

// Unmute a specific participant
await voiceChat.unmuteSelected('user123');
Muting is local only — it controls whether you hear the participant, not whether they are actually transmitting. The muted participant’s microphone remains active for other users in the room.

Text chat

// Send a text message to the room
voiceChat.sendMessage('Hello everyone!');

Receiving messages

voiceChat.onMessage((msg) => {
  console.log(`${msg.from}: ${msg.text}`);
  console.log(`Avatar: ${msg.avatar}`);
});
PropertyTypeDescription
msg.fromstringSender’s identity ("You" for your own messages)
msg.textstringMessage content
msg.avatarstringSender’s avatar URL

Participant updates

Track who’s in the room and who’s speaking:
voiceChat.onParticipantUpdate((data) => {
  // Local participant (you)
  console.log('You:', data.localParticipant.id, data.localParticipant.speaking);

  // Remote participants
  data.remoteParticipants.forEach((p) => {
    console.log(`${p.id}: speaking=${p.speaking}, avatar=${p.avatar}`);
  });
});

Participant data shape

{
  localParticipant: {
    id: 'your-username',
    avatar: 'https://example.com/avatar.png',
    speaking: true   // true if currently speaking
  },
  remoteParticipants: [
    {
      id: 'other-user',
      avatar: 'https://example.com/other-avatar.png',
      speaking: false
    }
  ]
}
The speaking boolean updates in real-time and can be used to drive speaking indicators in your UI, such as highlighting the active speaker or showing a microphone animation.

Full example

import { StreamPixelVoiceChat } from 'streampixelsdk';

const chat = new StreamPixelVoiceChat('room-1', 'Alice', true, '/avatar.png', true);

// Join the room
await chat.join();

// Listen for messages
chat.onMessage((msg) => {
  appendToChat(`${msg.from}: ${msg.text}`);
});

// Track participants
chat.onParticipantUpdate((data) => {
  updateParticipantList(data.remoteParticipants);
});

// Send a message
document.getElementById('send-btn').addEventListener('click', () => {
  const text = document.getElementById('chat-input').value;
  chat.sendMessage(text);
});

// Toggle mic
document.getElementById('mic-btn').addEventListener('click', () => {
  chat.toggleMic();
});

Next steps

StreamPixelVoiceChat API

Full reference for every method and callback.

SFU streaming

Combine voice chat with one-to-many SFU sessions.