diff --git a/bin/run.dart b/bin/run.dart index ea46846..7393fb9 100644 --- a/bin/run.dart +++ b/bin/run.dart @@ -29,10 +29,17 @@ main(List 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"]); }); saveLink = () { @@ -82,7 +89,7 @@ Future 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"]; @@ -98,7 +105,7 @@ Future 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")) { @@ -106,7 +113,7 @@ Future detectAndCorrectHost(String host) async { 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") || diff --git a/dslink.json b/dslink.json index 44d916d..b555bf2 100644 --- a/dslink.json +++ b/dslink.json @@ -1,6 +1,6 @@ { "name": "dslink-dart-dgapi", - "version": "1.0.4", + "version": "1.0.5", "description": "DGAPI DSLink", "main": "bin/run.dart", "engines": { @@ -25,6 +25,10 @@ "poll-interval": { "type": "number", "default": 250 + }, + "timeout": { + "type": "number", + "default": 250 } } } diff --git a/lib/dgapi.dart b/lib/dgapi.dart index 5498e13..151bb72 100644 --- a/lib/dgapi.dart +++ b/lib/dgapi.dart @@ -21,3 +21,4 @@ part "node.dart"; part "data_service.dart"; int globalPollInterval = 250; +int globalTimeout = 5000;