1

I'm programming using PeerJS and, because PeerJS is already very outdated, I'm testing everything on Firefox version 38. I know it is not the best to do, but I don't have time for more. So, I'm trying to do the following:

Peer1 transmits audio and video to Peer2.

Peer2 wants to transmit to Peer3 the video that receives from Peer1 but not the audio. Peer2 wants to send it's own audio.

Basically, Peer3 will receive the video from Peer1 (with Peer2 relaying it) and audio from Peer2, but it will arrive to him all together, like if it was a normal WebRTC call.

I do this like this:

var mixStream = remoteStream;

var audioMixStream = mixStream.getAudioTracks();

mixStream = mixStream.removeStream(audioMixStream);

var mixAudioStream = localStream;

var audioMixAudioStream = mixAudioStream.getAudioTracks();

mixStream.addTrack(audioMixAudioStream);

//Answer the call automatically instead of prompting user.
call.answer(window.audioMixAudioStream);

But I'm getting an error on removeStream. Maybe I will get more errors after that one, but now I'm stuck on this one.

Can someone please tell what I should use instead of removeStream?

P.S.: I already used removeTrack too and got an error too.

Krunal Limbad
  • 1,533
  • 1
  • 12
  • 23
  • 1
    Dunno about Peer.js, but in plain WebRTC, `mediaStream.getAudioTracks()` returns an array of tracks, not another stream. Some context and code formatting would help. This code isn't enough to do what you say you want. – jib Mar 23 '17 at 21:10
  • The code is here http://www.filedropper.com/serverside. It is located on Server Side\public\js\index.js. Basically, I want to mix two streams from different sources into one and send it, as a call answer, to another peer. –  Mar 23 '17 at 21:59
  • 1
    You're mixing [streams](https://developer.mozilla.org/en-US/docs/Web/API/MediaStream/MediaStream) and [tracks](https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrack), that's likely what's wrong (you're not telling us what errors you're getting). – jib Mar 24 '17 at 01:49
  • 1
    [this](http://stackoverflow.com/a/40288418/918910) and [this](http://stackoverflow.com/a/40012316/918910) combined should get you what you want, but you may need to update to at least Firefox 44. – jib Mar 24 '17 at 02:04
  • I updated what I was doing and, by miracle, got it working on Firefox 53. But I think PeerJS is what is limiting me here. I get this error: TypeError: Element of argument 1 of MediaStream does not implement interface MediaStreamTrack. I'm doing it like this: ->var newStream = new MediaStream(remoteStream); var newStreamAudio = newStream.getAudioTracks(); var newStreamVideo = newStream.removeTrack(newStreamAudio); var oldStream = new MediaStream(localStream); var oldStreamAudio = oldStream.getAudioTracks(); newStream = newStream.addTrack(oldStreamAudio);<- –  Mar 26 '17 at 18:05
  • I'd expect that `TypeError` if you did `new MediaStream([remoteStream])`... Is `remoteStream` an array?? Also, note that `newStream.getAudioTracks()` returns an array, not a track! – jib Mar 27 '17 at 01:38
  • 1
    That was it! I was passing the array, not the track! Already working! Thanks a lot for your help. –  Mar 27 '17 at 14:18

0 Answers0