I'm trying to implement a workaround for what appears to be a known issue in all browsers but firefox where webRTC audio stream is downgraded to mono from stereo.
This seems to happen due to the local session description defaulting to stereo=0 in the negotiated sdp config file which is produced based on the stream's constraints.
I have included the following constraints:
audio: { deviceId: audioSource ? { exact: audioSource } : undefined,
channelCount:2,
echoCancellation: false, // disabling audio processing
googAutoGainControl: false,
googNoiseSuppression: false,
googHighpassFilter: false
},
and then I attempt to append the required fix to the sdp file before setting local description using a process called SDP munging https://webrtcglossary.com/sdp-munging/:
peerConnection
.createOffer({ offerToReceiveAudio: true, offerToReceiveVideo: false })
.then( desc => desc.sdp=desc.sdp.replace('useinbandfec=1','useinbandfec=1; stereo=1'))
.then(desc => peerConnection.setLocalDescription(desc))
.then(() => socket.emit("offer", id, peerConnection.localDescription));
the error I receive :
broadcast.js:53 Uncaught (in promise) TypeError: Failed to execute 'setLocalDescription' on 'RTCPeerConnection': The provided value is not of type 'RTCSessionDescriptionInit'.
This fix was recommended by a number of sources on this topic but any time I attempt to modify the file prior to setting the local description I get a type error that it is no longer an RTCSessionDescription
I am hoping I am performing the SDP munging incorrectly and that there is a better way to go about this