-
-
Notifications
You must be signed in to change notification settings - Fork 981
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
replaceTrack only works once #634
Comments
|
The above snippet was simplified for clarity. Here's a full one:
And here's what I see in console: Note the missing final "Replace done". |
Then replace |
Thanks, missed that! Wasn't intentional, it was just me copying samples from README and not knowing how error reporting works. I'm now getting this: To me it looks like the newTrack in the first switch matches the oldTrack in the second switch. But it's throwing a "Cannot replace a track that was never added." error. |
I'm afraid the way it is designed right now, you are supposed to always add the same media stream as a third parameter to |
Ah I see. I commented out the line that updates
Just to get my mental model correct – is If the third argument is always the same, why does it need to be passed in at all? |
No, there is just a mapping inside of simple-peer that causes this unnecessary otherwise requirement. |
Thanks for the suggestion! I had previously tried to use But back to the topic, I think it would be great if there was an example of |
|
The API reflects the old Plan-B WebRTC API, in which "streams" were added to a RTCPeerConnection with a native addStream method and you attached tracks to that outgoing stream. The mediastream you got those tracks from is irrelevant. The relevant stream is the one passed to addStream. In other words, you're "attaching" the new track onto the old stream. Now everything is done with tracks+senders, so this is outdated and confusing. But this behaviour of replaceTrack is by design... 🙁 |
FWIW I just tried to pass undefined for the stream to addTrack and that doesn't fly:
|
You need to pass a stream to The only method that doesn't require a stream is It seems the only thing that can be done is improve documentation of |
@cuu508 Your problem is resolved ? I'm trying to switch de camera on Android but for me also its work only once, first ime it's ok I've the new track on the peers the second time I've this error
EDIT: Solved
If I change the
It's work. So do not use addStream at all and only work with addTrack removeTrack and replaceTrack. |
Hi, I'm having an issue with making replaceTrack work when a peer reconnect. Somehow the track i try to replace is not in the connection because I get an error, but how and why this is happening? I tried several way to fix this nut nothing works.. |
This sequence works for me Add new track to local stream |
I had a similar issue and managed to solve this way First I replace the track My error was that I was removing the track from the current local stream before replacing it in the peer, receiving the infamous error: "Cannot replace a track that was never added" |
I'm looking at implementing a "switch between front and rear camera" feature.
When user taps a button to switch the camera:
navigator.mediaDevices.getUserMedia
with appropriate constraintreplaceTrack
like so:In the example,
p
is a Peer instance, andlocalStream
is a local variable that keeps track of the current local stream. The above works, but only once. When I try to switch camera the second time, the replaceTrack doesn't return (theconsole.log
statement doesn't run), and there are no errors logged in console.Am I using it wrong? Is there an example of an idiomatic use of
replaceTrack
?The text was updated successfully, but these errors were encountered: