Skip to content
Snippets Groups Projects
Unverified Commit 7e3083af authored by Brian Peiris's avatar Brian Peiris Committed by GitHub
Browse files

Merge pull request #403 from mozilla/other/bot-robustness

Other/bot robustness
parents d75d3a48 55b82cdc
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();
})(); })();
...@@ -336,7 +336,7 @@ const onReady = async () => { ...@@ -336,7 +336,7 @@ const onReady = async () => {
}); });
const audio = document.getElementById("bot-recording"); const audio = document.getElementById("bot-recording");
mediaStream.addTrack(audio.captureStream().getAudioTracks()[0]); mediaStream.addTrack(audio.captureStream().getAudioTracks()[0]);
// wait for runner script to interact with the page so that we can play audio. // Wait for runner script to interact with the page so that we can play audio.
await new Promise(resolve => { await new Promise(resolve => {
window.interacted = resolve; window.interacted = resolve;
}); });
...@@ -400,6 +400,11 @@ const onReady = async () => { ...@@ -400,6 +400,11 @@ const onReady = async () => {
// Stop rendering while the UI is up. We restart the render loop in enterScene. // Stop rendering while the UI is up. We restart the render loop in enterScene.
// Wait a tick plus some margin so that the environments actually render. // Wait a tick plus some margin so that the environments actually render.
setTimeout(() => scene.renderer.animate(null), 100); setTimeout(() => scene.renderer.animate(null), 100);
} else {
const noop = () => {};
// Replace renderer with a noop renderer to reduce bot resource usage.
scene.renderer = { animate: noop, render: noop };
document.body.style.display = "none";
} }
}); });
environmentRoot.appendChild(initialEnvironmentEl); environmentRoot.appendChild(initialEnvironmentEl);
......
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