cduss Claude Opus 4.5 commited on
Commit
1588d39
·
1 Parent(s): e5f9acf

Fix bidirectional audio: use sendrecv on existing transceiver

Browse files

Instead of adding a new sendonly transceiver (which creates a new m-line
the server may not handle), find the existing audio transceiver from the
robot's stream and change its direction to sendrecv. This allows both
receiving robot audio AND sending mic audio on the same transceiver.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

Files changed (1) hide show
  1. index.html +19 -2
index.html CHANGED
@@ -930,8 +930,25 @@
930
  if (msg.sdp) {
931
  await peerConnection.setRemoteDescription(new RTCSessionDescription(msg.sdp));
932
  if (msg.sdp.type === 'offer') {
933
- const transceiver = peerConnection.addTransceiver('audio', { direction: 'sendonly' });
934
- audioSender = transceiver.sender;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
935
  const answer = await peerConnection.createAnswer();
936
  await peerConnection.setLocalDescription(answer);
937
  await sendToServer({ type: 'peer', sessionId: currentSessionId, sdp: { type: 'answer', sdp: answer.sdp } });
 
930
  if (msg.sdp) {
931
  await peerConnection.setRemoteDescription(new RTCSessionDescription(msg.sdp));
932
  if (msg.sdp.type === 'offer') {
933
+ // Find the audio transceiver and change direction to sendrecv
934
+ // so we can both receive robot audio AND send our mic audio
935
+ const transceivers = peerConnection.getTransceivers();
936
+ for (const transceiver of transceivers) {
937
+ if (transceiver.receiver.track?.kind === 'audio') {
938
+ transceiver.direction = 'sendrecv';
939
+ audioSender = transceiver.sender;
940
+ console.log('Audio transceiver set to sendrecv');
941
+ break;
942
+ }
943
+ }
944
+
945
+ // If no audio transceiver found, add one
946
+ if (!audioSender) {
947
+ const transceiver = peerConnection.addTransceiver('audio', { direction: 'sendrecv' });
948
+ audioSender = transceiver.sender;
949
+ console.log('Added new audio transceiver');
950
+ }
951
+
952
  const answer = await peerConnection.createAnswer();
953
  await peerConnection.setLocalDescription(answer);
954
  await sendToServer({ type: 'peer', sessionId: currentSessionId, sdp: { type: 'answer', sdp: answer.sdp } });