Skip to content
Merged
Changes from all commits
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
24 changes: 24 additions & 0 deletions packages/media-signaling/src/lib/services/webrtc/Processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,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 @@ -387,6 +389,28 @@ export class MediaCallWebRTCProcessor implements IWebRTCProcessor {
.filter((transceiver) => transceiver.sender.track?.kind === 'audio' || transceiver.receiver.track?.kind === 'audio');
}

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;
}
}

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

Expand Down
Loading