本文整理匯總了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'))