How to pass event to specific user using Pyramid and socketio

I was looking at gevent-socketio and was wondering how I stream to a specific user. Let's say I want to send a notification to user X when user submits data. Examples of broadcast messages for all users in the chat, but still can't figure out how to send and transmit events to a specific user. Do I need to create a custom Broadcast Mixin?

+3


source to share


1 answer


If you want to implement a dedicated broadcaster or dedicated room, you will need to implement your own Mixin. I just added a "session" attribute to the Namespace and Socket .. object on which you can set any information you need (this is a dictionary). I suggest having an event that will set an alias, say, self.session['nickname']

and then a function like broadcast_event()

(on BroadcastMixin) that will go through all the sockets, check its session to check if the socket belongs to that particular user and send a packet if so ...



Check out the code . It's easy to use. You just need to understand the Socket / Namespace relationship.

+2


source







All Articles