knezzz/ntp

getNtpOffset fails on web with “Unsupported operation: InternetAddress.lookup”

amatveiakin opened this issue · 23 comments

Does ntp package support web? Web isn't explicitly mentioned in the list of supported platforms at https://pub.dev/packages/ntp, but I was under impression that the package is written in native dart and should work on all platforms.

However when I try to call getNtpOffset from a web app, it fails with “Unsupported operation: InternetAddress.lookup”.

Tested in Firefox and Chrome, in a debug build running on local host and in a release build deployed to Firebase hosting. Using Dart 2.8.1, Flutter 1.17.0-3.4.pre, ntp 1.0.6.

Thanks for reporting the issue :D

Looks like I'll have to find better solution for this.
This is because dart:io is not supported on web.

Thanks! I'm a bit confused about the status of this issue now :) Was 0f0d1a4 supposed to work around dart:io problem?

I've updated to the new version and now getNtpOffset throws an UnimplementedError.

It was supposed to fix it yeah. There was package I found universal_io that is supposed to work on web, but it was not working when I tested it so I reopened the issue :/ (github automatically closes the issue if issue number is in commit message)

Interested in support for web too :)

Okay, will look up how can I make it work on web as well :)

Hello. How is it going? Do you need a hand?

Hey @itschrono. Sure if you have time I can assign it to you.
I didn't have much luck with universal_io.

Hi. when can we expect an update on this?

Thanks I appreciate it. meanwhile I'll try to come up with something, if I do I'll ping here.

Hello,

dgram and raw socket are a no go in web browser. The only options are: http(s) 1.1 or websocket. This means it is not going to work with this ntp protocol. The api can still be the same if the lookUpAddress support both connection types.

Any news about fix?

@itschrono How did you get host address (The InternetAddress.lookup part that is failing here)? Can something like that be implemented here?
I was looking today a bit at other solutions but coundn't find anything that works 😞

oonid commented

hi @knezzz
do you think it is possible to construct the InternetAddress if we have the IP Address?
if so, I think one idea is to build DNS utility with the implementation of DNS-over-HTTPS (DoH).
https://developers.google.com/speed/public-dns/docs/doh

this is one example:
https://github.com/Ephenodrom/Dart-Basic-Utils/blob/master/lib/src/DnsUtils.dart

thoughts?

Hi @oonid, sorry for not getting back sooner, I wanted to reply when I test this but I still didn't have a chance to try it.

Looks promising, and that will solve the web issue for sure so I will definitely try it.

Thanks for suggestion 😄

oonid commented

hi @knezzz
I have added PR #27
would you please review and edit it for better implementation?

Hello,
with 1.0.8 I'm getting this error on web:

Error: UnimplementedError
at Object.throw_ [as throw] (http://localhost:55438/dart_sdk.js:5348:11)
at bind (http://localhost:55438/packages/universal_io/src/io_impl_js/sync_socket.dart.lib.js:3434:21)
at bind.next ()
at runBody (http://localhost:55438/dart_sdk.js:39211:34)
at Object._async [as async] (http://localhost:55438/dart_sdk.js:39242:7)
at Function.bind (http://localhost:55438/packages/universal_io/src/io_impl_js/sync_socket.dart.lib.js:3431:20)
at getNtpOffset (http://localhost:55438/packages/ntp/ntp.dart.lib.js:128:63)
at getNtpOffset.next ()
at http://localhost:55438/dart_sdk.js:39191:33
at _RootZone.runUnary (http://localhost:55438/dart_sdk.js:39048:58)
at _FutureListener.thenAwait.handleValue (http://localhost:55438/dart_sdk.js:34034:29)
at handleValueCallback (http://localhost:55438/dart_sdk.js:34594:49)
at Function._propagateToListeners (http://localhost:55438/dart_sdk.js:34632:17)
at _Future.new.[_completeWithValue] (http://localhost:55438/dart_sdk.js:34474:23)
at async._AsyncCallbackEntry.new.callback (http://localhost:55438/dart_sdk.js:34497:35)
at Object._microtaskLoop (http://localhost:55438/dart_sdk.js:39335:13)
at _startMicrotaskLoop (http://localhost:55438/dart_sdk.js:39341:13)
at http://localhost:55438/dart_sdk.js:34848:9

I'm quite new to flutter web but it looks like the update didn't solve the problem...

capce commented

I have the exactly same error as @ma-ruz posted.

[√] Flutter (Channel stable, 2.0.2, on Microsoft Windows [Version 10.0.19041.804], locale de-DE)
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
[√] Chrome - develop for the web
[√] Android Studio (version 4.1.0)
[√] VS Code (version 1.54.1)
[√] Connected device (2 available)

opened a new issue #32

It seems this error still exists