-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Change video/audio source on Chrome/Firefox #367
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
Comments
@postacik Hi, on the web platform, we may need to use the RtpSender.replaceTrack method. |
Hi, I made a test on the following WebRTC sample page: Goto the page and click "Start" + "Call". Then open the DevTools console and paste the following code:
After this each time you call Would this be enough to implement this feature in the Dart code? It works on the latest versions of both Chrome and Firefox. I could not fully understand the web implementation to create a PR, sorry. PS: You have to have more than one camera on your PC for this to work. I use the "ManyCam" application to add a virtual camera to my Windows 10 for testing. |
@postacik Cool, I think this is the correct code. |
I'm not sure about one thing in this piece of code.
However, I was not able to set the deviceId for the audio part (it raised an error) so I commented out the property which sets the device id the same as the current one and just used the "true" value which I assume chooses the default audio device. |
@cloudwebrtc But there is other considerations as of today MediaStreamTrackWeb is where the switchCamera API is currently implemented. @postacik here is what the code look like if we transform it to DART
|
Also created a ticket here for add support in the "native" library: |
In my app, I can re-negotiate with the WebRTC server using a new stream so switching between available cams on the fly is not the only solution to switch camera. As far as I can understand from the Can I do that? |
Well, I tried it as in the following function:
I have two cameras on my system. However the following two statements both set the first cam to the stream (index 0).
Do you have any idea what I might be doing wrong? |
And I verified that the following Javascript version of the sample code runs perfectly well and sets the camera I want:
|
Have you tried
mediaConstraints["video"]["deviceId"]["exact"] = videoDevices[1].deviceId
…On Thu, Oct 15, 2020 at 7:52 AM Ahmet Uzun ***@***.***> wrote:
And I verified that the following Javascript version of the sample code
runs perfectly well and sets the camera I want:
try {
var videoDevices = (await navigator.mediaDevices.enumerateDevices()).filter((device) => device.kind === "videoinput");
var constraints = {
audio: true,
video: { deviceId: { exact: videoDevices[1].deviceId } }
};
const stream = await navigator.mediaDevices.getUserMedia(constraints);
console.log('Received local stream');
localVideo.srcObject = stream;
localStream = stream;
} catch (e) {
alert(`getUserMedia() error: ${e.name}`);
}
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#367 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AJL6EZ4ZPRVT3M4YOHD36FDSK3PAZANCNFSM4SMNHRFQ>
.
|
I've tried both of the following:
|
What browser are you using?
https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackSupportedConstraints/deviceId
…On Thu, Oct 15, 2020 at 8:32 AM Ahmet Uzun ***@***.***> wrote:
I've tried both of the following:
mediaConstraints["video"] = {"deviceId": videoDevices[1]["deviceId"]};
mediaConstraints["video"] = {
"deviceId": {"exact": videoDevices[1]["deviceId"]}
};
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#367 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AJL6EZ5VYSY46ED6PD2PKNLSK3TV5ANCNFSM4SMNHRFQ>
.
|
I'm doing all my tests on Chrome. |
The Javascript code works fine but flutter code sets only the first cam. |
I also tested the same on flutter-webrtc-demo. I changed the following function in signaling.dart.
It also uses the cam at index 0, not at index 1 as I set in the mediaConstraints. |
Can the following question be related to this? getUserMedia is defined in html_dart2js.dart as below:
Can this implementation not be calling the same function we use in the following JavaScript statement:
|
I was able to reproduce the problem. After couple of testing here what I found so far with Chrome. There is many strange things happening behind the scene:
When you pass the constraint to the getUserMedia(), it always open the default camera and do not considerer the deviceId pass in the constraints. To test this you can change the default camera in Chrome and you will see that It will open the default one. This is not a problem in the implementation in this library, but in the html_dart2js.dart implementation. So I will fill two bugs with the dart team! I will update this issue after. I the mean time, if someone familiar with JS library can try to post a workaround. Related to : dart-lang/sdk#43801 |
Thanks for testing and all your efforts. 👍 |
I think I found the reason of the error.
constraints parameter is converted to JS object using
So the function ignores all the sub items in the "video" parameter. If you can implement the
Can you do it, or shall I create a PR? |
PRs are always welcome, but I can do it if you want.
I tested it locally and it works :-)
We are still having the issue with the first time authorization.
But now it pass the constraints.
I also updated the issue(dart-lang/sdk#43802) with your comment, thanks @postacik.
|
Try it out, I merged it on master. But still not resolve the problem with the list of devices before authorization is granted.
But experience the same behaviors. |
I think Thank you very much, closing this one. 👍 |
Hi,
I can switch between front and back cameras using the following function on mobile:
stream.getVideoTracks()[0].switchCamera();
Can it be possible to iterate through all available cameras on Chrome (web) using the same function or an additional function?
Or can you add a function to get a list of available cameras (and also available audio input sources) and select one of them using an index?
On Chrome WebRTC, one can select from available video and audio sources even during a conversation.
But on Firefox, the user chooses the video/audio source before the conversation starts and it's not possible to switch to another source afterwards.
I'm not sure how this difference can be addressed.
PS: My app works fine on the latest versions of Chrome and Firefox but not on Safari. Do you have any plans to support Safari?
The text was updated successfully, but these errors were encountered: