peerreynders / solid-start-ws-demo

Use a websocket server within SolidStart v1
MIT License
4 stars 0 forks source link

Questions #1

Open sh1man999 opened 6 months ago

sh1man999 commented 6 months ago

1) in your example from the solistart server I will not be able to send data to clients.

2) Should we wait for the official release of ws with solidstart?

3) Is it possible to get peers on the server now and send a message to everyone?

peerreynders commented 1 month ago

Copied from Solid Discord

If you look at the nuxt-chat example it's a matter of collecting the user/peers in a Map during the open event and removing them on the close event.

Then the server can send a message to anyone stored in the map at any time.

In the spirit of Plan to throw one away I'd use the opportunity to move ahead to figure out what you want to do and need.

Once websocket support stabilizes it should be relatively quick to switch over.

If you are only concerned with the server communicating with the client you could use SSE instead (which is part of the HTTP standard; websockets are not.)

https://youtu.be/n9mRjkQg3VE

i can use sse to reset cache for all users using server ?

I'm not understanding the question.

Each client has a separate SSE response responsible for streaming any events from the server to the respective client but the server side code has access to centrally managed server resources/services while the response remains open.

So the server can broadcast an event to all currently active event streams and each connected client can then take the necessary actions based on that event.

I want to send information to all clients https://github.com/peerreynders/solid-start-sse-counter is this example relevant?

This one would be more relevant https://github.com/peerreynders/solid-start-sse-chat


Did you manage to have this working after building, outside of a dev environment? I have been unable to get it to work...

If this was my problem I'd focus on getting an absolute minimal web socket example (without anything related to SolidStart) to work on your particular deployment platform.

This is necessary to uncover any web socket related challenges of the platform given that most are optimized towards the request/response mode and may require additional configuration to allow/support the necessary connection upgrade.

Some people seem to believe that web sockets are universally supported; they are not. There are instances where web sockets won't work (most notably across strictly configured corporate firewalls) while SSE + req/res can.

That example is simply a port of the h3 example which is live on StackBlitz. Fundamentally the SolidStart port isn't different from that.

Now there is an issue stating that “In your example from the SolidStart server I will not be able to send data to clients.”

Clearly in the example the “server is sending data to clients”– but it only sends data in response to a message from the client.

I've documented SolidStart's behaviour that would interfere with the server sending unsolicited data to client in https://github.com/peerreynders/server_-routes-lobotomy.

My hypothesis is that this relates to each request being wrapped by vinxi inside AsyncLocalStorage. Architecturally this would mean that the request/response (i.e. RequestEvent) can interact with the server but for the server to interact with all active RequestEvents additional infrastructure is required.

In the case of https://github.com/peerreynders/solid-start-sse-chat I simply used a BroadcastChannel that the RequestEvent would subscribe to while it's active. The server then simply publishes data onto the BroadcastChannel and the various active RequestEvents would then forward it back to the client provided it's relevant.