Recipes / Share Audio from Browser Tab

Share Audio from Browser Tab

Note:

Sharing audio is only possible in certain browsers. You can check for compatibility here.

Code

Assuming a user is already connected to a LiveKit room:

const tracks = await localParticipant.createScreenTracks({
audio: true,
});
tracks.forEach((track) => {
localParticipant.publishTrack(track);
});

Testing

Publisher

When sharing audio, make sure you select a Browser Tab (not a Window) and ☑️ Share tab audio, otherwise no audio track will be generated when calling createScreenTracks:

Subscriber

On the receiving side, you can use AudioRenderer or your own custom <audio> tag to add the track to the page. If you don't hear any sound, check you're receiving the track from the server:

room.getParticipantByIdentity('<participant_id>').getTrack('screen_share_audio')