Skip to content

Commit

Permalink
pimp start, add services
Browse files Browse the repository at this point in the history
  • Loading branch information
andibraeu committed Dec 7, 2021
1 parent 178d037 commit 681f5b6
Show file tree
Hide file tree
Showing 6 changed files with 590 additions and 107 deletions.
10 changes: 10 additions & 0 deletions Xvfb.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Unit]
Description=X Virtual Frame Buffer Service
After=network.target

[Service]
User=pi
ExecStart=Xvfb :1 -screen 0 1920x1080x24

[Install]
WantedBy=multi-user.target
78 changes: 47 additions & 31 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,31 @@ TODO
*/

const puppeteer = require("puppeteer");
const express = require('express');
const app = express();
const http = require("http");

async function main(room, baseUrl = "https://meet.jit.si") {
const port=8001;
app.listen(port,()=>{
console.log('live on port '+port);
});

app.get('/reload', async (req,res)=>{
console.log('reload page')
await page.reload();
res.send('jo, seite wurde neu geladen');
});

app.get('/shutdown', async (req,res)=>{
console.log('shutdown browser')
process.kill(process.pid, "SIGINT");
res.send('jo, browser wurde heruntergefahren');
});

browser = null;
page = null;

async function main() {
// Chromium browser options
// https://peter.sh/experiments/chromium-command-line-switches/
const chromeArgs = [
Expand All @@ -18,48 +41,47 @@ async function main(room, baseUrl = "https://meet.jit.si") {

// Silence all output, just in case
"--alsa-output-device=plug:null",
"--remote-debugging-port=9222",

// Point chromium to xvfb display
"--display=:1",
"--no-sandbox",
"--disable-extensions",
];

// // Jitsi Meet options
// // https://github.com/jitsi/lib-jitsi-meet/blob/master/doc/API.md
// const meetArgs = [
// // Disable receiving of video
// "config.channelLastN=0",
// // Mute our audio
// "config.startWithAudioMuted=true",
// // Don't use simulcast to save resources on the sender (our) side
// "config.disableSimulcast=true",
// // No need to process audio levels
// "config.disableAudioLevels=true",
// // Disable P2P mode due to a bug in Jitsi Meet
// "config.p2p.enabled=false",
// ];

// const url = `${baseUrl}/${room}#${meetArgs.join("&")}`;
const url = `${baseUrl}/${room}`;
console.log(`Loading ${url}`);
// Jitsi Meet options
// https://github.com/jitsi/lib-jitsi-meet/blob/master/doc/API.md
const meetArgs = [
// Disable receiving of video
"config.channelLastN=0",
// Mute our audio
"config.startWithAudioMuted=true",
// Don't use simulcast to save resources on the sender (our) side
"config.disableSimulcast=true",
// No need to process audio levels
"config.disableAudioLevels=true",
// Disable P2P mode due to a bug in Jitsi Meet
"config.p2p.enabled=false",
"config.prejoinPageEnabled=false"
];

const url = 'http://localhost:8000/static/jitsi/main.html';
console.log(`Loading local jitsi client`);

// Puppeteer launch options
// https://github.com/puppeteer/puppeteer/blob/v3.0.1/docs/api.md#puppeteerlaunchoptions
// https://github.com/puppeteer/puppeteer/issues/550#issuecomment-551991273
const browser = await puppeteer.launch({
defaultViewport: { height: 1080, width: 1920 },
headless: false,
browser = await puppeteer.launch({
headless: true,
args: chromeArgs,
executablePath: "/usr/bin/chromium-browser",
handleSIGINT: false,
});
const page = await browser.newPage();
page = await browser.newPage();

// Manual handling on SIGINT to gracefully hangup and exit
process.on("SIGINT", async () => {
console.log("Exiting...");
await page.evaluate("APP.conference.hangup();");
await page.close();
browser.close();
console.log("Done!");
Expand All @@ -69,13 +91,7 @@ async function main(room, baseUrl = "https://meet.jit.si") {
// Start Jitsi Meet
await page.goto(url);

// Mute audio
await page.evaluate(`APP.conference.muteAudio(true);`);

// Set some friendly display name
await page.evaluate(`APP.conference.changeLocalDisplayName('Webcam');`);

console.log("Running...");
}

main(process.argv[2] || "test-0123456789");
main(process.argv[2] || "test-0123456789");
12 changes: 12 additions & 0 deletions jitsi-headless.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
Description=headless jitsi client
After=network.target

[Service]
Type=simple
User=pi
ExecStart=/usr/bin/node /home/pi/sources/jitsi-headless/app.js
Restart=on-failure

[Install]
WantedBy=multi-user.target
Loading

0 comments on commit 681f5b6

Please sign in to comment.