electron - access the webcam

1

to use the webcam from my application made in electron I used the module node webcamjs, this is the code I used, taken from the doc of the module itself:

<h1>camara</h1>
<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>

When I try to access the webcam electron, it throws the following exception:

  

Uncaught ReferenceError: take_snapshot is not defined

However, when the same code is tested from firefox , it works fine, firefox announces that you try to access the webcam and is given OK to complete the action. On the other hand, since Google Chrome it seems that this is not allowed because it tells me:

  

Webcam.js error: Webcam is not loaded yet.

Any suggestions then to use the camera from electron , or why Google Chrome have this behavior?

    
asked by mos 08.07.2016 в 22:47
source

2 answers

1

Checking the official website of the library that you use link there's something to keep in mind: In Google Chrome requires HTTPS and unless you have a domain with that protocol, it will not work. You can get a free SSL certificate at link or at link

WebcamJS has been tested on the following browsers / operating systems:
OS  Browser     Notes
**Mac OS X  Chrome 30+  Works -- Chrome 47+ requires HTTPS**
Mac OS X    Firefox 20+     Works
Mac OS X    Safari 6+   Requires Adobe Flash Player
**Windows   Chrome 30+  Works -- Chrome 47+ requires HTTPS**
Windows     Firefox 20+     Works
Windows     IE 9    Requires Adobe Flash Player
Windows     IE 10   Requires Adobe Flash Player
Windows     IE 11   Requires Adobe Flash Player
    
answered by 08.07.2016 в 23:06
0

electron is composed of: electron + node + chromium library.

Since webcamjs in Chrome (derived from chromium) requires HTTPS as it says @fredyfx you will not be able to use it directly

In this thread clarify that being chromium you do not need webcamJS and you can directly use the HTML5 getUserMedia API:

WebCam js not starting using electron-build on windows. # 243 link

  

Also, I should point out that since you are using Electron, you have Chromium built right into your app, so you do not really need WebcamJS. You could just use the HTML5 getUserMedia API directly, and you can be assured that it will be available on all platforms, thanks to Chromium / Electron.

link link

Following links you get to the getusermedia HTML5 tutorial

link

    
answered by 05.04.2018 в 01:29