Hi,
I am trying to implement switching mobile flash during Openvidu session, I am using web browser of mobile device to connect to Openvidu call.
Here is what I am trying to do
let videoSource = this.localUsersService.getWebcamPublisher().stream.getMediaStream().getVideoTracks()[0];
videoSource.applyConstraints({
advanced: [{torch: true}]
}).then(() => {
// do whatever
})
.catch(e => {
alert(e);
});
I am getting below error:
“NotSupportedError: Unsupported constraint(s)”
Referring the document: https://codepen.io/adamrifai/pen/YLxjKa?editors=1111
It would be great if anyone could help me here.
TIA
This is a purely Web API question, unrelated to OpenVidu. But yes, it seems that the browser API supports using the torch light of mobile devices applying that constraint to a MediaStreamTrack
of type video.
If unsupported constraint error is raised, then it must be that the device does not support it. I don’t think this error could be caused by a timing issue.
Hi @pabloFuente ,
I do agree that it is totally related to Web API
When I open this link https://codepen.io/adamrifai/pen/YLxjKa?editors=1111 in my mobile browser I could able to switch on flash.
But the same not happening through Openvidu session.
Kindly let me know “this.localUsersService.getWebcamPublisher().stream.getMediaStream().getVideoTracks()[0]” is the right way to get video tracks and apply constraints on it
Yes, you get the video track from a Publisher or Subscriber by calling:
publisher.stream.getMediaStream().getVideoTracks()[0]
That is correct. If you are not getting a null pointer / undefined exception when calling applyConstraints over the track object, then it means it exists at that point, it has been successfully retrieved and you can call any methods offered by its API. Beyond that, I don’t know what could be happening for you being unable to apply the torch constraint over the MediaStreamTrack object.
You can try something different: OpenVidu.initPublisher method allows providing an already existing video track and audio track. Just provide as audioSource
and videoSource
properties both MediaStreamTrack objects. And obtain both objects with the codepen code that works for you.
When I tried with height and width constraints it did work with the above code.
But the advanced : [{torch:true}] constraint is giving me the error.
Even the “publisher.stream.getMediaStream().getVideoTracks()[0]” is giving me undefined.
But “this.localUsersService.getWebcamPublisher().stream.getMediaStream().getVideoTracks()[0] as any” is giving me videosource and height and width constraints are getting applied.
Make sure the Publisher object is properly initialized before calling stream.getMediaStream()...
function.
You can do so with promisified function OpenVidu.initPublisherAsync:
var publisher = await OpenVidu.initPublisherAsync();
That will ensure the Stream object (and its internal MediaStream) is available in the Publisher object.
1 Like
It worked. Flash will get enabled only if the camera of the device has attached flash with it.
Not all camera of a mobile phone will have the flash for it.