from tg import expose, TGController, AppConfig from tgext.socketio import SocketIOController from tgext.socketio.pubsub import PubSubTGNamespace from tgext.socketio.server import socketio_server_runner import uuid class ChatNamespace(PubSubTGNamespace): def subscribe_room(self, roomid): self.session['uid'] = str(uuid.uuid4()) self.session['channel'] = 'room-%s' % roomid self.emit('userid', self.session['uid']) return self.session['channel'] def on_user_message(self, message): self.publish(self.session['channel'], {'uid': self.session['uid'], 'message': message}) class SocketIO(SocketIOController): chat = ChatNamespace class RootController(TGController): socketio = SocketIO() @expose() def index(self): return '''