-
-
Save dmfrancisco/951e149d62b048e9e468 to your computer and use it in GitHub Desktop.
Simple extension of the RoomsMixin (gevent-socketio)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from socketio.mixins import RoomsMixin | |
class ExtendedRoomsMixin(RoomsMixin): | |
def emit_to_room_not_me(self, room, event, *args): | |
"""This is sent to all in the room (in this particular Namespace) except itself""" | |
pkt = dict(type="event", | |
name=event, | |
args=args, | |
endpoint=self.ns_name) | |
room_name = self._get_room_name(room) | |
for sessid, socket in self.socket.server.sockets.iteritems(): | |
if socket is not self.socket: # This prevents from sending to itself | |
if 'rooms' not in socket.session: | |
continue | |
if room_name in socket.session['rooms']: | |
socket.send_packet(pkt) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment