Separate remote audio in different devices

Skip to first unread message

Joel Bermudez

Mar 12, 2021, 4:15:53 PMMar 12
to discuss-webrtc
Hi everyone,

we need to separate the audio from two peerconnections into two different output devices.
Each peerconnection receives the corresponding audio track.
we have two audio elements, one for each peerconnection.
By making use of setsinkid of an audio element assigned to peerconnection1, it also affects the audio output element assigned to peerconnection2 preventing each stream to be played by a different output device from the other peerconnection.
For each ontrack event of each peerconnection, we create a new mediastream and add the track to the mediastream.
Checking the browser's webrtc-internals viewer, I check that both peerconnection share the same RTCMediaStream element but each one with its corresponding track.

We impliemented for each peerConnection like the below:

var localStream = await navigator.mediaDevices.getUserMedia({vide: true, audio: true});
peerConnection1 = new RTCPeerConnection(config);
localStream.getTracks().forEach(track => {
peerConnection1.addTrack(track, localStream);

var remoteStream = new MediaStream();
var remote = document.querySelector('#audio1');
remoteVideo.srcObject = remoteStream;

peerConnection1.addEventListener('track', async (event) => {
remoteStream.addTrack(event.track, remoteStream);

peerConnection1.addEventListener('icecandidate', event => {
    if (event.candidate) {
                id: 'ADD_ICE_CANDIDATE_SELECT',
                candidate: event.candidate

var sdpOffer = await peerConnection1.createOffer();
await peerConnection1.setLocalDescription(sdpOffer);

ws.onmessage = function(message)

        switch ( {
        case 'PROCESS_SDP_ANSWER_PEER1':
            var remoteDesc = new RTCSessionDescription({type:"answer",sdp:jsonMessage.sdpAnswer});
await peerConnection1.setRemoteDescription(remoteDesc);
        case 'ADD_ICE_CANDIDATE_PEER1':
            await peerConnection1.addIceCandidate(jsonMessage.candidate);;
sdpOffer: sdpOffer.sdp

Thanks in advance!


Mar 13, 2021, 10:53:01 AMMar 13
to discuss-webrtc
> we need to separate the audio from two peerconnections into two different output devices.

Re setSinkId(), 'audiooutput' does not really mean an actual audio output devices, see On Linux on Chrome it is not possible to actually select an audio output device without workarounds.

> to be played by a different output device

The first step is clearly defining what you mean by output device? Two different sets of speakers connected to the machine? Headphones and speakers?

Joel Bermudez

Aug 30, 2021, 1:32:46 PMAug 30
to discuss-webrtc
Yes, two different sets of devices, one peerconnection stream via headphones and one peerconnection stream via speakers.


Aug 30, 2021, 10:03:28 PMAug 30
AFAIK there is no specified means to select headphones You can try to use PulseAudio or whatever the system audio controller is to select and stream to specific devices, or virtual devices, e.g.,


You received this message because you are subscribed to a topic in the Google Groups "discuss-webrtc" group.
To unsubscribe from this topic, visit
To unsubscribe from this group and all its topics, send an email to
To view this discussion on the web visit
Reply all
Reply to author
0 new messages