3

I am working on an Electron app with React.js that sets up some peer connections through webRTC. Everything looks good with the connections and the peers receive the stream, but the video on the peers end does no play the audio. Perhaps I'm just not understanding how getUserMedia works, but I thought setting constraints true for audio and video was enough.

Relavent HTML (Peer)

<video ref="video" autoplay></video>

A few snippets of the code getting the stream

// constraints
this.constraints = {
    video: true,
    audio: true,
};

this.sdpConstraints = {
    'mandatory': {
        'OfferToReceiveAudio': this.constraints.audio,
        'OfferToReceiveVideo': this.constraints.video
    }
};

...
// getting/setting local video
setupLocalMedia(){
    navigator.mediaDevices.getUserMedia(self.constraints)
    .then(function(stream){
        self.localVideo.src = window.URL.createObjectURL(stream);
        self.stream = stream;
        window.stream = stream;
     }).catch(self.errorHandler);
}

// adding the stream to the peer
peerConnection.onaddstream = function(event){
    peerVideo.src = window.URL.createObjectURL(event.stream); 
};

Again, all the connections are working just fine, and the video is streaming as expected, but no audio. Consoling the stream shows that the audio channel is enabled. Any ideas?

dev_pool
  • 203
  • 4
  • 14
  • There's nothing wrong with the code you show (except the `sdpConstraints` which are [outdated](http://stackoverflow.com/a/30982333/918910) and redundant here, since the default behavior is to offer to receive the same as what you're sending, i.e. audio+video in your case), so the problem must be elsewhere. – jib Jun 02 '16 at 00:50
  • Thanks, I got it playing audio, but had to call play on the video element for the audio to start. Is that the expected behavior? I just assumed autoplay would take care of that as well. – dev_pool Jun 02 '16 at 01:56
  • Shouldn't be necessary. What browser is this? Have you tried other browsers? – jib Jun 02 '16 at 03:41
  • It's actually in Electron app, so it would be Chromium. Perhaps it's just an oddity in Electron then. – dev_pool Jun 02 '16 at 20:36
  • any news about this problem? – Luca C. Oct 24 '18 at 17:22

0 Answers0