-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebcam.js
More file actions
executable file
·41 lines (36 loc) · 926 Bytes
/
Copy pathwebcam.js
File metadata and controls
executable file
·41 lines (36 loc) · 926 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const puppeteer = require('puppeteer');
module.exports = class Webcam {
constructor() {
this.browser = null;
}
async start() {
try {
this.browser = await puppeteer.launch({
headless: false,
executablePath: '/usr/bin/google-chrome',
ignoreHTTPSErrors: true,
args: [
'--use-fake-ui-for-media-stream',
'--no-sandbox',
'--disable-setuid-sandbox'
]
});
const page = await this.browser.newPage();
const address = process.env.NODE_ENV === 'production'
? 'https://localhost:5000/webcam'
: 'https://localhost:3001'
await page.goto(address, {waitUntil: 'domcontentloaded'});
}
catch(error) {
console.log('error: ', error);
}
}
async stop() {
await this.browser.close();
this.browser = null;
}
async restart() {
await this.stop();
await this.start();
}
}