@events.on_finish(channel='^room-')
def finish(request, socket, context):
 try:
  user = context['user']
 except KeyError:
  return
 left = {'action': 'leave', 'name': user.name, 'id': user.id}
 socket.broadcast_channel(left)
 user.delete()

@ events . on_finish ( channel = '^room-' ) def finish ( request , socket , context ) : try : user = context [ 'user' ] except KeyError : return left = { 'action' : 'leave' , 'name' : user . name , 'id' : user . id } socket . broadcast_channel ( left ) user . delete ( )
event handler for a socket session ending in a room .