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
aecbdb16
Commit
aecbdb16
authored
6 years ago
by
Brian Peiris
Browse files
Options
Downloads
Patches
Plain Diff
improve bot loading and retry logic
parent
6cbe19e3
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
scripts/bot/run-bot.js
+28
-14
28 additions, 14 deletions
scripts/bot/run-bot.js
with
28 additions
and
14 deletions
scripts/bot/run-bot.js
+
28
−
14
View file @
aecbdb16
...
@@ -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.
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