fix(audio): acquire streams before negotiation when peer is answerer

When a sendrecv peer acts as the answerer, gUM is only called _after_
the remote offer is received. This is fine, but the error handling runs
different in that scenario in a way that eventual gUM errors are treated
as negotiation errors, leading to inconsistencies when surfacing the
error to end users.

If a peer is acting as answerer and is a transceiver, acquire the local
streams _before_ actual negotiation so that gUM errors are surfaced
correctly (and we spare uneeded negotiation steps).
This commit is contained in:
prlanzarin 2024-04-10 21:25:40 -03:00
parent fcbfcb1bbc
commit 555a8f6522

View File

@ -97,11 +97,20 @@ class AudioBroker extends BaseBroker {
this.webRtcPeer.peerConnection.onconnectionstatechange = this.handleConnectionStateChange.bind(this); this.webRtcPeer.peerConnection.onconnectionstatechange = this.handleConnectionStateChange.bind(this);
if (this.offering) { if (this.offering) {
// We are the offerer
this.webRtcPeer.generateOffer() this.webRtcPeer.generateOffer()
.then(this.sendStartReq.bind(this)) .then(this.sendStartReq.bind(this))
.catch(this._handleOfferGenerationFailure.bind(this)); .catch(this._handleOfferGenerationFailure.bind(this));
} else { } else if (peerRole === 'recvonly') {
// We are the answerer and we are only listening, so we don't need
// to acquire local media
this.sendStartReq(); this.sendStartReq();
} else {
// We are the answerer and we are sending audio, so we need to acquire
// local media before sending the start request
this.webRtcPeer.mediaStreamFactory()
.then(() => { this.sendStartReq(); })
.catch(this._handleOfferGenerationFailure.bind(this));
} }
resolve(); resolve();