Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added 'timeout' to startup arguments #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions bin/run.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,17 @@ main(List<String> args) async {
defaultsTo: "250",
help: "Poll Interval in Milliseconds"
);
argp.addOption(
"timeout",
defaultsTo: "250",
help: "Poll Timeout in Milliseconds"
);

link.configure(argp: argp, optionsHandler: (opts) {
globalPollInterval =
int.parse(opts["poll-interval"] == null ? 250 : opts["poll-interval"]);
globalTimeout =
int.parse(opts["timeout"] == null ? 5000 : opts["timeout"]);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int.parse(opts["timeout"] ?? 5000]);

});

saveLink = () {
Expand Down Expand Up @@ -82,7 +89,7 @@ Future<String> detectAndCorrectHost(String host) async {
}

http.Response response = await httpClient.get(host).timeout(
const Duration(seconds: 5));
new Duration(milliseconds: globalTimeout));

var server = response.headers["server"];

Expand All @@ -98,15 +105,15 @@ Future<String> detectAndCorrectHost(String host) async {
u = u.resolve(response.headers["location"]);
response = await httpClient.get(u.toString(), headers: {
"x-niagara": "true" // Use Proxy on WKWebView
}).timeout(const Duration(seconds: 5));
}).timeout(new Duration(milliseconds: globalTimeout));
}

if (response.headers.containsKey("x-location")) {
var u = uri;
u = u.resolve(response.headers["x-location"]);
response = await httpClient.get(u.toString(), headers: {
"x-niagara": "true" // Use Proxy on WKWebView
}).timeout(const Duration(seconds: 5));
}).timeout(new Duration(milliseconds: globalTimeout));
}

if (response.body.contains("ENVYSION") ||
Expand Down
6 changes: 5 additions & 1 deletion dslink.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dslink-dart-dgapi",
"version": "1.0.4",
"version": "1.0.5",
"description": "DGAPI DSLink",
"main": "bin/run.dart",
"engines": {
Expand All @@ -25,6 +25,10 @@
"poll-interval": {
"type": "number",
"default": 250
},
"timeout": {
"type": "number",
"default": 250
}
}
}
1 change: 1 addition & 0 deletions lib/dgapi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ part "node.dart";
part "data_service.dart";

int globalPollInterval = 250;
int globalTimeout = 5000;