diff options
author | eug-vs <eug-vs@keemail.me> | 2020-11-14 17:41:39 +0300 |
---|---|---|
committer | eug-vs <eug-vs@keemail.me> | 2020-11-14 17:41:39 +0300 |
commit | ecb98e114bc461f439386ed8d914e4617746570d (patch) | |
tree | bf052b6da50eb007d897c61fd7f09e9564c60598 | |
parent | ae94313667b3abe257c0767439c6d3986ba0fde6 (diff) | |
download | bsu-fantom-ecb98e114bc461f439386ed8d914e4617746570d.tar.gz |
feat: attend conference on job
-rw-r--r-- | src/handlers/attendConference.js | 5 | ||||
-rw-r--r-- | src/handlers/index.js | 26 |
2 files changed, 27 insertions, 4 deletions
diff --git a/src/handlers/attendConference.js b/src/handlers/attendConference.js index 54d6479..8f5c53f 100644 --- a/src/handlers/attendConference.js +++ b/src/handlers/attendConference.js @@ -1,13 +1,14 @@ const { clickElementByXPath } = require('./utils.js'); -const CONFERENCE_DURATION = 1000 * 60 * 80; // 80 minutes +const CONFERENCE_DURATION = process.env.NODE_ENV === 'production' + ? 1000 * 60 * 80 // 80 minutes + : 5000; const attendConference = async (page, onJoin) => { // Join as "Listen only" await clickElementByXPath(page, '//span[contains(text(),"Listen only")]'); if (typeof(onJoin) === 'function') onJoin(); - console.log('Joined the conference'); // Wait 5 seconds await page.waitForTimeout(CONFERENCE_DURATION); diff --git a/src/handlers/index.js b/src/handlers/index.js index 188547c..d4eaf43 100644 --- a/src/handlers/index.js +++ b/src/handlers/index.js @@ -2,11 +2,33 @@ const { Types } = require('mongoose'); 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 } = process.env; const handleJobAsUser = async (job, user) => { console.log(`Running job as ${user.username}`); - return launchUserSession(user); + + const { conferenceId } = job.attrs.data; + const conferenceUrl = `${EDUFPMI_URL}/mod/bigbluebuttonbn/view.php?id=${conferenceId}`; + + const browser = await launchUserSession(user, false); + const page = await browser.newPage(); + await page.goto(conferenceUrl); + + // Launch the conference in a new tab + const conferencePagePromise = new Promise(resolve => browser.on( + 'targetcreated', + target => resolve(target.page()) + )); + await clickElementBySelector(page, 'input#join_button_input'); + const conferencePage = await conferencePagePromise; + + await attendConference(conferencePage, () => console.log(`Joined the conference at ${conferenceUrl}`)); + + await browser.close(); }; const handleJob = async job => { @@ -19,7 +41,7 @@ const handleJob = async job => { } }); - console.log({ participants }) + console.log('Participants: ', participants.map(participant => participant.username)); return Bluebird.map(participants, participant => handleJobAsUser(job, participant)); }; |