News for hackers. Stuff that matters.

hntrl

Re:You might not need WebSockets on Friday April 11, 2025 @10:37PM (#43660826)
The helper example was a sore attempt to plug the project I've been working on (tinkering with it is how I came up with the example). The library I plugged has much more to do with enabling a more flexible reactive programming model in js, but just so happens to plug into the stream API pretty handily. Still an interesting look IMO if you're into that kind of stuff
Re:You might not need WebSockets on Friday April 11, 2025 @09:30PM (#43660503)
It even has mention as being the spiritual successor to WebSocket for certain cases in mdn docs:

https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_...

Re:You might not need WebSockets on Friday April 11, 2025 @08:38PM (#43660241)
who's to say your data is coming from multiple streams? You can propagate any updates you need to make in the application to a single stream (like SSE or a long-lived response) in place of a WebSocket. your http responses can just be always 204 if all they're doing is handling updates and pushing events to aforementioned single stream.

https://en.wikipedia.org/wiki/Command%E2%80%93query_separati...

Re:You might not need WebSockets on Friday April 11, 2025 @08:16PM (#43660110)
It's a good thing I didn't then :shrug:

Websockets are a web standard, socket.io is a userland framework

Re:You might not need WebSockets on Friday April 11, 2025 @08:07PM (#43660063)
> sending a RequestID to the server so that you get request/response cycles isn't weird nor beyond the pale.

To me the sticking point is what if the "response" message never comes? There's nothing in the websocket protocol that dictates that messages need to be acknowledged. With request/response the client knows how to handle that case natively

> And the websocket browser API is nicer to work with than, say, EventSource.

What in particular would you say?

Re:You might not need WebSockets on Friday April 11, 2025 @07:57PM (#43660019)
I have a demo of this for CF workers https://github.com/hntrl/eventkit/tree/main/examples/workers...

(it's not SSE in particular, but it demonstrates that you can have a long running stream like SSE)

Re:You might not need WebSockets on Friday April 11, 2025 @07:53PM (#43659988)
I've noticed some weird behaviors with the EventSource impl that browsers ship with. Chief among them being the default behavior is to infinitely reconnect after the server closes the stream, so you have to coordinate some kind of special stop event to stop the client from reconnecting. You wouldn't have that problem with the stream object from Response.body

The SSE protocol is actually just a long-running stream like I mentioned but with specific formatting for each chunk (id, event, and data fields)

as a side note, eventkit actually exports utilities to support SSE both on client and server. The reason you'd want to use eventkit in either case is because it ships with some extra transformation and observability goodies. https://hntrl.github.io/eventkit/guide/examples/http-streami...

Show HN: Eventkit- a better way to work with data streams in JavaScript

https://github.com/hntrl/eventkit

Hey HN! I've spent the last few weeks working on eventkit, an open source library designed for working with data streams in TS/JS.I had a need to track all the work associated with handling application events. If you're familiar at all with reactive systems or what that entails, having this sort of functionality is super important.If you're familiar with observables or RxJS, this library is...

( Read More... | no comments | on HN )