-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
56 lines (48 loc) · 1.2 KB
/
index.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
"use strict";
const puppeteer = require("puppeteer");
const Promise = require("bluebird");
const express = require("express");
const mqtt = require("mqtt");
const port = 3199;
const app = express();
const mqttClient = mqtt.connect("mqtt://localhost", {
will: {
topic: "revspace/j",
payload: "E_BOT_STUK",
retain: true,
}
});
app.get("/mqtt", (req, res) => {
console.log("PARTICIPANTS", req.query.participants);
mqttClient.publish('revspace/j', req.query.participants.toString(), {retain: true});
res.send("ack");
});
app.get("/console", (req, res) => {
console.log(req.query.log);
console.log("Log from browser:", ...Object.values(JSON.parse(req.query.log)));
res.send("ack");
});
app.use(express.static("public"));
app.listen(port, "127.0.0.1", () => {
console.log("started");
});
let page;
let browser;
Promise.try(() => {
return puppeteer.launch({
headless: false,
args: ["--no-sandbox"]
});
}).then((res) => {
browser = res;
const context = browser.defaultBrowserContext();
context.clearPermissionOverrides();
return browser.newPage();
}).then((res) => {
page = res;
return page.goto(`http://localhost:${port}`);
}).then(() => {
page.on('dialog', (dialog) => {
console.log(dialog);
});
});