-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
80 lines (62 loc) · 2.44 KB
/
test.js
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const puppeteer = require('puppeteer');
const child_process = require('child_process');
// const XMLHttpRequest = require('xhr2'); //uncomment this if you want to show notes instead of chat
const Xvfb = require('xvfb');
options.executablePath = "/usr/bin/chromium-browser"
// Generate randome display port number to avoide xvfb failure
var disp_num = Math.floor(Math.random() * 100 + 99);
var xvfb = new Xvfb({
displayNum: disp_num,
silent: true,
xvfb_args: ["-screen", "0", "1280x800x24", "-ac", "-nolisten", "tcp", "-dpi", "96", "+extension", "RANDR"]
});
xvfb.startSync()
async function ssr(url) {
// set duration to 0
var duration = 0
const browser = await puppeteer.launch({headless: true,
args: [
'--disable-infobars',
'--no-sandbox',
'--disable-dev-shm-usage',
'--start-fullscreen',
// '--app=url',
`--window-size=1280,800`,
],
});
const page = await browser.newPage();
await page.goto(url, {waitUntil: 'networkidle0'});
const html = await page.content(); // serialized HTML of page DOM.
// Get recording duration
const recDuration = await page.evaluate(() => {
return document.getElementById("vjs_video_3_html5_api").duration
});
duration = recDuration
console.log("Record duration: ", duration)
await page.waitForSelector('button[class=vjs-big-play-button]');
await page.$eval('.bottom-content', element => element.style.display = "none");
await page.$eval('.fullscreen-button', element => element.style.opacity = "0");
await page.$eval('.right', element => element.style.opacity = "0");
await page.$eval('.vjs-control-bar', element => element.style.opacity = "0");
await page.click('button[class=vjs-big-play-button]', { waitUntil: 'domcontentloaded' });
// Start capturing screen with ffmpeg
const ls = child_process.spawn('sh', ['ffmpeg-cmd.sh', ' ',
`${duration}`, ' ',
`${exportname}`, ' ',
`${disp_num}`
], {
shell: true
});
ls.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
});
ls.stderr.on('data', (data) => {
console.error(`stderr: ${data}`);
});
ls.on('close', (code) => {
console.log(`child process exited with code ${code}`);
});
await browser.close();
xvfb.stopSync()
return html;
}