-
Notifications
You must be signed in to change notification settings - Fork 9
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
How to use in browser? #12
Comments
What are the dependency issues? The package doesn't have any production dependencies, only jest to run tests. I didn't use any other library to build it. |
Thanks for your quick answer :-) The issue is the missing
So this seems to be an unsolvable issue :-P I actually chose your package for its combination of NTP and UDP because I hoped that this would have the least latency and highest precision of all available time sync packages. Websockets seem to be low latency as well. Would it be possible to use |
I don't think that this would be possible, since the communication between NTP servers is done by UDP protocol. But even if you had a server that accepts NTP requests by websockets (which is definitely not the standard), this library has only implemented with UDP packages. |
Edit: okay nevermind, it's just another Node module that is not available in the browser :-P Thanks for clarification. I forked your repo and started to replace The client gives me: Uncaught TypeError: data.slice(...).readFloatBE is not a function
at NTPPacket.parse (packet.js:81:1)
at parse (websocketClient.js:16:1)
at Socket.<anonymous> (websocketClient.js:103:1)
at Emitter.emit (index.mjs:136:1)
at Socket.emitEvent (socket.js:294:1)
at Socket.onevent (socket.js:281:1)
at Socket.onpacket (socket.js:249:1)
at Emitter.emit (index.mjs:136:1)
at Manager.ondecoded (manager.js:233:1)
at Emitter.emit (index.mjs:136:1) Line 81 in packet.rootDelay = data.slice(4, 8).readFloatBE(0) / 2 ** 16; I did not change anything in The message that goes into NTPPacket {
mode: 3,
leap: 0,
version: 3,
stratum: 2,
poll: 10,
precision: 0,
rootDelay: 0,
rootDispersion: 0,
referenceId: <Buffer 00 00 00 00>,
referenceTimestamp: 1661724417,
originateTimestamp: 2208988800,
rxTimestamp: 1661724422,
txTimestamp: 2208988800
} What am I doing wrong here? |
You should check the return of the data.slice to see if it's being returned as a instance of the Buffer class, if it's not, you should find some other way of reading the floating bytes out of it. If you want to, you can create a SocketNTPServer class and make a PR to this repository, I would be glad to review the code and release it into NPM. |
Besides, the input of the parse function shouldn't be a ArrayBuffer, it should be a Buffer, they're different classes. |
Hi. Any update on this? |
I developed my own package that is syncing via WebSockets (but using a simpler protocol than NTP). It's closed source though, as it's gonna be the USP of the service I'm working on ... sorry :-P |
I can't work in the browser compatibility now, but if anyone has the time to do it I would be glad to review and help. I'm gonna leave this issue open for future references and if nobody comes to it, I'll do it myself when I manage to make some time. Sorry for being unavailable for it now! |
Hey @luk3skyw4lker,
thank you for your great work. I'm looking for high precision time synchronization with JS and this package seems to do exactly this.
However, I was not able to get the client running in the browser. When packing it with Webpack it throws dependency errors. I also tried to serve 'node_modules/ntp-time/src/client.js' through express as a static file but it didn't work either.
Can you please help me to get the client running in the browser?
Thanks in advance
Frederik
The text was updated successfully, but these errors were encountered: