Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions packages/media-signaling/src/lib/services/webrtc/Processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ export class MediaCallWebRTCProcessor implements IWebRTCProcessor {
this._held = held;
this.localStream.setEnabled(!held && !this._muted);
this.remoteStream.setEnabled(!held);

this.updateAudioDirectionWithoutNegotiation();
}

public stop(): void {
Expand Down Expand Up @@ -301,6 +303,34 @@ export class MediaCallWebRTCProcessor implements IWebRTCProcessor {
await new Promise((resolve) => setTimeout(resolve, 30));
}

private updateAudioDirectionWithoutNegotiation(): void {
// If the signaling state is not stable, then a negotiation is already happening and the audio direction will be updated by them
if (this.peer.signalingState !== 'stable') {
return;
}

const desiredDirection = this.held ? 'sendonly' : 'sendrecv';
const acceptableDirection = this.held ? 'inactive' : 'recvonly';

const transceivers = this.getAudioTransceivers();
for (const transceiver of transceivers) {
// If the last direction we requested still matches our current requirements, then we don't need to change our request
if ([desiredDirection, acceptableDirection, 'stopped'].includes(transceiver.direction)) {
continue;
}

// If the current state of the call doesn't match what we are requesting here, the browser will trigger the negotiation-needed event for us
this.config.logger?.debug(`Changing desired audio direction from ${transceiver.direction} to ${desiredDirection}.`);
transceiver.direction = desiredDirection;
}
}
Comment thread
pierre-lehnen-rc marked this conversation as resolved.

private getAudioTransceivers(): RTCRtpTransceiver[] {
return this.peer
.getTransceivers()
.filter((transceiver) => transceiver.sender.track?.kind === 'audio' || transceiver.receiver.track?.kind === 'audio');
}

private registerPeerEvents() {
const { peer } = this;

Expand Down
Loading