examples icon indicating copy to clipboard operation
examples copied to clipboard

Svelte(Kit) websocket example

Open karimfromjordan opened this issue 2 years ago • 2 comments

Similar to #3. and a very frequently asked question on Discord. I'm not sure however if this example should use plain websockets or the socket.io library. And to make this example self contained we probably have to use the Vite development server to setup the websocket server and mention that you need a separate websocket server in production.

For the actual content, would a simple chat app to demonstrate the bidirectional nature of websockets be too much for an example? Also, this example could use either plain Svelte or SvelteKit. I think the most important part to show here would be how to manage a websocket connection with a custom store. And if it's a chat app the store could just be extended with a store.send_message() function.

karimfromjordan avatar Feb 20 '23 16:02 karimfromjordan

Regarding the use case, I think a very simple chat app is perfect for this. Regarding "self-contained" - I would be ok with having a backend folder at the root in this example where a super simple node express/whatever project is set up.

dummdidumm avatar Feb 20 '23 17:02 dummdidumm

Ok great. And I think using SvelteKit instead of plain Svelte would actually be better because one problem/question that often comes up is how to initialize a websocket connection in a SSR enabled SvelteKit app.

karimfromjordan avatar Feb 21 '23 04:02 karimfromjordan