Skip to content
Snippets Groups Projects
Commit aecbdb16 authored by Brian Peiris's avatar Brian Peiris
Browse files

improve bot loading and retry logic

parent 6cbe19e3
No related branches found
No related tags found
No related merge requests found
...@@ -6,7 +6,7 @@ Usage: ...@@ -6,7 +6,7 @@ Usage:
Options: Options:
-u --url=<url> URL -u --url=<url> URL
-o --host=<host> Hubs host if URL is not specified [default: localhost:8080] -o --host=<host> Hubs host if URL is not specified [default: localhost:8080]
-r --room=<room> Room id -r --room=<room> Room id [default: 234234]
-h --help Show this screen -h --help Show this screen
`; `;
...@@ -20,8 +20,8 @@ const querystring = require("query-string"); ...@@ -20,8 +20,8 @@ const querystring = require("query-string");
const browser = await puppeteer.launch({ ignoreHTTPSErrors: true }); const browser = await puppeteer.launch({ ignoreHTTPSErrors: true });
const page = await browser.newPage(); const page = await browser.newPage();
page.on("console", msg => console.log("PAGE: ", msg.text())); page.on("console", msg => console.log("PAGE: ", msg.text()));
page.on("error", err => console.error("ERROR: ", err)); page.on("error", err => console.error("ERROR: ", err.toString().split("\n")[0]));
page.on("pageerror", err => console.error("PAGE ERROR: ", err)); page.on("pageerror", err => console.error("PAGE ERROR: ", err.toString().split("\n")[0]));
const baseUrl = options["--url"] || `https://${options["--host"]}/hub.html`; const baseUrl = options["--url"] || `https://${options["--host"]}/hub.html`;
...@@ -39,22 +39,36 @@ const querystring = require("query-string"); ...@@ -39,22 +39,36 @@ const querystring = require("query-string");
const navigate = async () => { const navigate = async () => {
try { try {
console.log("Spawning bot...");
await page.goto(url); await page.goto(url);
await page.evaluate(() => { await page.evaluate(() => console.log(navigator.userAgent));
console.log(navigator.userAgent); let retryCount = 5;
}); let backoff = 1000;
// Interact with the page so that audio can play. const interact = async () => {
await page.mouse.click(100, 100); try {
// Signal that the page has been interacted with. // Interact with the page so that audio can play.
// If the interacted function has not been defined yet, this will error and restart the process with the await page.mouse.click(100, 100);
// setTimeout below. // Signal that the page has been interacted with.
await page.evaluate(() => window.interacted()); await page.evaluate(() => window.interacted());
console.log("Interacted.");
} catch (e) {
console.log("Interaction error", e.message);
if (retryCount-- < 0) {
// If retries failed, throw and restart navigation.
throw new Error("Retries failed");
}
console.log("Retrying...");
backoff *= 2;
// Retry interaction to start audio playback
setTimeout(interact, backoff);
}
};
await interact();
} catch (e) { } catch (e) {
console.log("Navigation error", e.toString()); console.log("Navigation error", e.message);
setTimeout(navigate, 1000); setTimeout(navigate, 1000);
} }
}; };
console.log("Spawning bot...");
navigate(); navigate();
})(); })();
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment