Commits

Arkaitz Jimenez committed 93a067e

Fixed RoomsMixin and put chat example working

  • Participants
  • Parent commits 0930345

Comments (0)

Files changed (3)

File examples/chat.html

 
     $('#send-message').submit(function () {
 	message('me', $('#message').val());
-	socket.emit('user message', $('#message').val());
+	socket.emit('user message','main_room', $('#message').val());
 	clear();
 	$('#lines').get(0).scrollTop = 10000000;
 	return false;

File examples/chat.py

 class ChatNamespace(BaseNamespace, RoomsMixin, BroadcastMixin):
     
     def on_nickname(self, nickname):
+        self.ack()
         self.environ['nicknames'].append(nickname)
-        self.socket.session = nickname
-        self.broadcast_event('anouncement', '%s has connected' % nickname)
+        self.socket.nickname = self.socket.session = nickname
+        self.broadcast_event('announcement', '%s has connected' % nickname)
         self.broadcast_event('nicknames', self.environ['nicknames'])
+        self.join('main_room')
 
-    def on_user_message(self, room_name, msg):
-        self.emit_to_room('msg_to_room', room_name, msg)
+    def on_user_message(self, room, msg):
+        self.emit_to_room('msg_to_room', (self.socket.nickname,msg),room)
 
     def recv_message(self, message):
         print "PING!!!", message

File socketio/mixins.py

 
 class RoomsMixin(object):
     def __init__(self, *args, **kwargs):
-        super(RoomsMixin).__init__(self, *args, **kwargs)
+        super(RoomsMixin,self).__init__(*args, **kwargs)
         if not hasattr(self.socket, 'rooms'):
             self.socket.rooms = set() # a set of simple strings
 
         for sessid, socket in self.socket.server.sockets.iteritems():
             if not hasattr(socket, 'rooms'):
                 continue
-            if room_name in socket.rooms:
+            if room_name in socket.rooms and socket != self.socket:
                 socket.send_packet(pkt)