async def pre_disconnect(self, room_name, participant_label, tab_unique_id): if room_name in ROOM_DICT: room = ROOM_DICT[room_name] else: # doesn't get shown because not yet localized await self.send_json( {'error': 'Invalid room name "{}".'.format(room_name)}) return # should use filter instead of get, # because if the DB is recreated, # the record could already be deleted await database_sync_to_async(self.delete_visit)( participant_label=participant_label, room_name=room_name, tab_unique_id=tab_unique_id, ) event = {'status': 'remove_participant'} if room.has_participant_labels(): if await database_sync_to_async(self.visit_exists)( participant_label=participant_label, room_name=room_name): return # it's ok if there is a race condition -- # in JS removing a participant is idempotent event['participant'] = participant_label admin_group = channel_utils.room_admin_group_name(room_name) await channel_utils.group_send_wrapper(group=admin_group, type='roomadmin_update', event=event)
async def post_connect(self, room_name, participant_label, tab_unique_id): if room_name in ROOM_DICT: room = ROOM_DICT[room_name] else: # doesn't get shown because not yet localized await self.send_json({'error': 'Invalid room name "{}".'.format(room_name)}) return if await database_sync_to_async(room.has_session)(): await self.room_session_ready() else: try: await database_sync_to_async(self.create_participant_room_visit)( participant_label=participant_label, room_name=room_name, tab_unique_id=tab_unique_id, last_updated=time.time(), ) except django.db.IntegrityError: # possible that the tab connected twice # without disconnecting in between # because of WebSocket failure # tab_unique_id is unique=True, # so this will throw an integrity error. # 2017-09-17: I saw the integrityerror on macOS. # previously, we logged this, but i see no need to do that. pass await channel_utils.group_send_wrapper( type='roomadmin_update', group=channel_utils.room_admin_group_name(room_name), event={'status': 'add_participant', 'participant': participant_label}, )
async def pre_disconnect(self, room_name, participant_label, tab_unique_id): room = ROOM_DICT[room_name] event = { 'status': 'remove_participant', 'participant': participant_label } room.presence_remove(participant_label) admin_group = channel_utils.room_admin_group_name(room_name) await channel_utils.group_send(group=admin_group, data=event)
async def post_connect(self, room_name, participant_label, tab_unique_id): if not room_name in ROOM_DICT: return room = ROOM_DICT[room_name] # add it even if there is a session, because in pre_disconnect we do # presence_remove, so we need to be consistent. room.presence_add(participant_label) if room.has_session(): await self.send_json(SESSION_READY_PAYLOAD) else: await channel_utils.group_send( group=channel_utils.room_admin_group_name(room_name), data={ 'status': 'add_participant', 'participant': participant_label }, )
def group_name(self, room): return channel_utils.room_admin_group_name(room)