replaceTrack only works once
- Dominant language
- JavaScript
- Stars
- 7.8k
- Forks
- 983
- PR merge metrics
- No merged PRs in 30d
Description
I'm looking at implementing a "switch between front and rear camera" feature.
When user taps a button to switch the camera:
* I run `navigator.mediaDevices.getUserMedia` with appropriate constraint
* when getUserMedia returns a stream I run `replaceTrack` like so:
```
navigator.mediaDevices.getUserMedia({
video: { facingMode: facingMode },
audio: true
}).then(function(stream) {
if (p && localStream) {
p.replaceTrack(localStream.getVideoTracks()[0], stream.getVideoTracks()[0], localStream);
console.log("Done");
}
localStream = stream;
}).catch(() => {})
```
In the example, `p` is a Peer instance, and `localStream` 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 (the `console.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`?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.