本文整理汇总了Python中models.Room.leave方法的典型用法代码示例。如果您正苦于以下问题:Python Room.leave方法的具体用法?Python Room.leave怎么用?Python Room.leave使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Room
的用法示例。
在下文中一共展示了Room.leave方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: room_socket
# 需要导入模块: from models import Room [as 别名]
# 或者: from models.Room import leave [as 别名]
class room_socket(WebSocketHandler):
def open(self, room_id):
print('room_id: %s' % room_id)
self.room = Room(room_id)
self.user = None
self.subscription = None
def on_message(self, data):
print 'messaged'
data = json.loads(data)
if not self.user:
# make name
self.user = make_random_user()
self.room.join(self.user)
self.subscription = RedisListener(self.room, self)
self.subscription.start()
self.log_and_publish(construct_message('JOIN', 'Welcome!', self.user))
print self.room.host
else:
if data.get('type') == 'SET_SOURCE' and \
self.user.email != self.room.host:
print 'User tried to set source', self.user.email, self.room.host
return
self.log_and_publish(construct_message(data.get('type'), data.get('message'), self.user))
def on_close(self):
print("socket closed")
if self.subscription:
self.subscription.stop()
self.log_and_publish(construct_message('LEAVE', 'Goodbye.', self.user))
self.room.leave(self.user)
def log_and_publish(self, message):
print(message.get('log'))
conn.rpush("room:%s:logs" % self.room.id, message.get('log'))
conn.publish("room:%s" % self.room.id, message.get('display'))