summaryrefslogtreecommitdiff
path: root/src/handlers/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/handlers/index.js')
-rw-r--r--src/handlers/index.js26
1 files changed, 18 insertions, 8 deletions
diff --git a/src/handlers/index.js b/src/handlers/index.js
index 196c3db..7101250 100644
--- a/src/handlers/index.js
+++ b/src/handlers/index.js
@@ -1,28 +1,30 @@
const { Types } = require('mongoose');
+const puppeteer = require('puppeteer');
const Bluebird = require('bluebird');
const UserModel = require('../services/users/user.model.js');
const launchUserSession = require('./launchUserSession.js');
const attendConference = require('./attendConference.js');
const { clickElementBySelector } = require('./utils.js');
-const { EDUFPMI_URL, NODE_ENV, HEADLESS } = process.env;
+const { EDUFPMI_URL, NODE_ENV, HEADFUL } = process.env;
// Always run headless in production, but allow configuring for development
-const headless = NODE_ENV === 'production' || HEADLESS;
+const headless = NODE_ENV === 'production' || !HEADFUL;
-const handleJobAsUser = async (job, user) => {
+const handleJobAsUser = async (job, browser, user) => {
console.log(`Running job as ${user.username}`);
+ const browserContext = await browser.createIncognitoBrowserContext();
+
const { conferenceId } = job.attrs.data;
const conferenceUrl = `${EDUFPMI_URL}/mod/bigbluebuttonbn/view.php?id=${conferenceId}`;
- const browser = await launchUserSession(user, headless);
- const page = await browser.newPage();
+ const page = await launchUserSession(user, browserContext);
await page.goto(conferenceUrl);
// Launch the conference in a new tab
- const conferencePagePromise = new Promise(resolve => browser.on(
+ const conferencePagePromise = new Promise(resolve => browserContext.on(
'targetcreated',
target => resolve(target.page())
));
@@ -31,7 +33,7 @@ const handleJobAsUser = async (job, user) => {
await attendConference(conferencePage, () => console.log(`Joined the conference at ${conferenceUrl}`));
- await browser.close();
+ await browserContext.close();
};
const handleJob = async job => {
@@ -45,7 +47,15 @@ const handleJob = async job => {
console.log('Participants: ', participants.map(participant => participant.username));
- return Bluebird.map(participants, participant => handleJobAsUser(job, participant));
+ const browser = await puppeteer.launch({ headless, args: ['--no-sandbox'] });
+
+ try {
+ await Bluebird.map(participants, participant => handleJobAsUser(job, browser, participant));
+ } catch (err) {
+ console.error(err);
+ } finally {
+ await browser.close();
+ }
};