Accessing video devices in Webkit2Gtk

153 Views Asked by At

I am trying to access my webcam from a Webkit2Gtk window, but I am unable to. I'm using the WebKit2 python module.

from gi.repository import Gtk
from gi.repository import WebKit2

class BrowserView:
    def __init__(self):
        window = Gtk.Window()
        window.connect('delete-event', Gtk.main_quit)

        context=WebKit2.WebContext()
        context.set_tls_errors_policy(WebKit2.TLSErrorsPolicy(0))
        
        self.view = WebKit2.WebView(web_context=context)

        self.view.connect("permission-request", WebKit2.PermissionRequest)
        self.settings = self.view.get_settings()
        self.settings.set_property("enable-mediasource", True)
        self.settings.set_property("enable-media-stream", True)

        window.add(self.view)
        self.view.load_uri('https://localhost:8080')

        window.show_all()

if __name__ == "__main__":
    BrowserView()
    Gtk.main()

The webpage is hosted with flask and using WebcamJS for a webcam interfacing library. The javascript is an example for using WebcamJS.

<script src="{{url_for('static',filename='webcam.js')}}"></script>

<div id="my_camera" style="width:320px; height:240px;"></div>
<div id="my_result"></div>

<script language="JavaScript">
    Webcam.attach( '#my_camera' );

    function take_snapshot() {
        Webcam.snap( function(data_uri) {
            document.getElementById('my_result').innerHTML = '<img src="'+data_uri+'"/>';
        } );
    }
</script>
<a href="javascript:void(take_snapshot())">Take Snapshot</a>

This webpage works fine in chrome but I get the error Webcam.js Error: No supported webcam when loading the page in Webkit2. SSL is enabled.

Has anyone been able to get webcams / external media devices to work in Webkit2GTK?

0

There are 0 best solutions below