outmoded / sntp

SNTP client (RFC4330) for node

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Usage with React Native

amaury1093 opened this issue · comments

Support plan

  • which support plan is this issue covered by? Community
  • is this issue currently blocking your project? yes
  • is this issue affecting a production system? no

Context

  • node version: 13.6.0 (but using it in React Native)
  • module version with issue: 4.0.0
  • last module version without issue: unknown
  • environment (e.g. node, browser, native): React Native
  • used with (e.g. hapi application, another framework, standalone, ...): React Native
  • any other relevant information:

What are you trying to achieve or the steps to reproduce?

Concretely, in my code, I'm doing this:

import Hawk from '@hapi/hawk';

And @hapi/hawk depends on @hapi/sntp.

What was the result you got?

Screenshot 2020-01-13 at 12 48 42

What result did you expect?

Be able to use @hapi/sntp

Notes

I can think of 2 solutions:

  1. Add a dgram polyfill in my react native app, e.g. https://github.com/tradle/react-native-udp
  2. Change @hapi/sntp to not use nodejs-specific API. e.g.: would it be possible to replace dgram with ws/http requests?

Additional question

How does @hapi/sntp work in browser (which don't support UDP)? If there's a plan to make @hapi/sntp work in browser too, then the solution 2 above seems to be the optimal choice.

If you are trying to use the hawk client in the browser, import just that directly (lib/browser.js), not the entire module as it is designed to work only server-side on node.