Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
H
Hubs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ar-noc
Hubs
Commits
7e3083af
Unverified
Commit
7e3083af
authored
6 years ago
by
Brian Peiris
Committed by
GitHub
6 years ago
Browse files
Options
Downloads
Plain Diff
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
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
scripts/bot/run-bot.js
+28
-14
28 additions, 14 deletions
scripts/bot/run-bot.js
src/hub.js
+6
-1
6 additions, 1 deletion
src/hub.js
with
34 additions
and
15 deletions
scripts/bot/run-bot.js
+
28
−
14
View file @
7e3083af
...
@@ -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
();
})();
})();
This diff is collapsed.
Click to expand it.
src/hub.js
+
6
−
1
View file @
7e3083af
...
@@ -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
]);
//
w
ait for runner script to interact with the page so that we can play audio.
//
W
ait 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
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment