AgoraIO / API-Examples-Web

224 stars 199 forks source link

change audio source input on the fly! #77

Open Abdeladim101Basraoui opened 1 year ago

Abdeladim101Basraoui commented 1 year ago

in my current scenarion I want to have the ability to change the audioTracks on the fly I found on the documentation that it's possible to do so for the audio Track ,but couldn't find resource for audio tracks ,I've been using webRTC native api and I did a solution to

  peerConnection.removeTrack(oldSender);

  const newSender = peerConnection.addTrack(track, stream);

  const localSdp = await peerConnection.createOffer({ offerToReceiveAudio: 1 });
  await peerConnection.setLocalDescription(reply);

  const response = await sendOffer(peerConnection.localDescription);

  const description = new RTCSessionDescription(response);
  peerConnection.setRemoteDescription(description);

  return newSender;
}

thank you