Search code examples
javascriptcameratwiliowebrtc

Twilio programmable video zoom in camera


I am using twilio video javascript sdk in a browser (or mobile webview). It works just fine, both ends publish their tracks. But I have not found any way for a user to zoom in his/hers camera exept from a custom css solution. Is there any "native" way to zoom in a camera that is powering the published track in twilio video/webrtc?

Thanks in advance

Edit:

Actually, the navigator.mediaDevices.getSupportedConstraints().zoom is true in all cases which means it is indeed supported by webview but the track.mediaStreamTrack.getCapabilities() does not have the zoom property when in android webview. When in android chrome it works just fine. Does anyone know why this happens?


Solution

  • There is a relatively new API for pan-tilt-zoom that works with getUserMedia. In a nutshell you should be able to use

    navigator.mediaDevices.getUserMedia({video: {zoom: true}})
    

    and then use MediaStreamTrack.applyConstraint to change the zoom. See the web.dev article for the details (as well as pitfalls)