Git Product home page Git Product logo

Comments (6)

mtsgrd avatar mtsgrd commented on June 5, 2024

Emit sends a message back to the connected socket, not to every client. Notice the method receiver is a socket handler: https://github.com/googollee/go-socket.io/blob/ad2caa087d468ddb67c4e9e41157371c5f83a07b/handler.go#L55-78

Broadcasts are used to send a message to every socket in a given room. http://socket.io/docs/rooms-and-namespaces/

from go-socket.io.

polds avatar polds commented on June 5, 2024

Well still in that case, a new connection who joins the channel should then receive the Broadcast that is sent immediately afterwards, however in using of that code the client never receives the broadcast.

Edit: Thanks for the clarification on emit

from go-socket.io.

mtsgrd avatar mtsgrd commented on June 5, 2024

In typical design patters you actually want to exclude the sender from receiving the broadcast. Consider a simple chat application - the UI should update in the client as soon as you send a message to a room.

https://github.com/googollee/go-socket.io/blob/master/handler.go#L116

The socket handler BroadcastTo method passes itself as a socket to ignore.. but I agree it's not a technical requirement.

from go-socket.io.

polds avatar polds commented on June 5, 2024

So following design patterns (thanks again for the response), what is the best way to use singular channels instead of a global channel. Our use case would require the ability to communicate to all users on individual sockets.

Pretty much we'd like every user to be a part of a "global" room (or rooms) that all users can receive the same communications on, and communicate individually to those users.

Hence why I was thinking BroadcastTo was the solution to this, but I'm not sure if this is possible using this library.

from go-socket.io.

mtsgrd avatar mtsgrd commented on June 5, 2024

To the extent that I understand socket.io, I would recommend you communicate privately through channels prefixed a certain way, .e.g. "private-". Then check for permissions before you let anyone join such channels.

Technically you could modify the BroadcastTo functionality to accept a socket to communicate with, instead of a socket to exclude. But consider a client that's signed in with the same account on two different devices; most of the time it makes more sense for private messages to reach both of them (private rooms), rather than just one (targeting socket).

from go-socket.io.

googollee avatar googollee commented on June 5, 2024

Hi everyone, could you try latest version? Please update go-engine.io which is the base of go-socket.io. And it fixed a lot of bugs like no disconnect event.

And if meet any issue, please open a new issue.

from go-socket.io.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.