ambelovsky / gosf

Go SocketIO API Framework
http://gosf.io
MIT License
97 stars 14 forks source link

Compatibility with JavaScript frameworks #19

Open darienmiller88 opened 6 months ago

darienmiller88 commented 6 months ago

I was wondering if this socket.io library was compatible with JavaScript frameworks like React, Vue or Svelte, because JavaScript code written in an HTML file works perfectly fine, but applying the same code to a basic React or Svelte frontend doesn't yield the same results. The connection is made successfully, but messages are not coming through.

ASoldo commented 6 months ago

First, you need to use npm i socket.io in your blank Vue/React/Svelte since you are not using cdn links but the npm package. Socket.io is a basic websocket package with some convenient utility functions for creating rooms and lobbies. Next, you import in your main.ts this socket.io package and provide it to your app. From there, you have Vue/React/Svelte life cycle hooks you can use to send events and receive events.