C
C
Chainsaw21002022-01-25 12:45:28
Django
Chainsaw2100, 2022-01-25 12:45:28

Django-channels: Why is a message sent to all users instead of just one?

Hello, tell me please.
I'm making a video chat with Django and WebRTC and I have a feature to set a user on hold.
The function works fine, the admin presses the button, a signal is sent to the user via the channel through the self.channel_layer.send() function, an alert() appears on the screen and he is put on hold.
However, when I release it from hold, a signal sent to the same address goes to all users, although the channel is the same as the previous time.
Hold function:

if action == 'onhold':  # поставили на удержание
            await self.channel_layer.send(
                list(usersChannels.keys())[list(usersChannels.values()).index(message['peer'])], #канал на удержание
                {
                    'type': 'channel_message',
                    'action': 'onhold',
                    'room': 'room',
                    'message': {message['peer']: '1'},
                }
            )
            return

Removal function:
if action == 'unhold':  # убрали с удержания
            await self.channel_layer.send(
                list(usersChannels.keys())[list(usersChannels.values()).index(message['peer'])],
                {
                    'type': 'channel_message',
                    'action': 'unhold',
                    'room': 'room',
                    'message': {message['peer']: '1'},
                }
            )
            return

The whole code: https://pastebin.com/CicsUhy4 (sorry for the clumsiness)
I don’t even roughly understand what the reason is. I'm new to Channels, any tips would be welcome.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question