sveltejs / examples

A collection of Svelte(Kit) examples
MIT License
34 stars 5 forks source link

Svelte(Kit) websocket example #4

Open karimfromjordan opened 1 year ago

karimfromjordan commented 1 year ago

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.

dummdidumm commented 1 year ago

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.

karimfromjordan commented 1 year ago

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.