'Why message is being sent to everyone instead of one user in Django Channels?
I am building a WebRTC videochat app. I have a function of holding the user on a line, which works great: I press a button, the signal goes to the server, the server sends it to the user using self.channel_layer.send(), the user gets alert() and puts on hold. But when I want to unhold the user, the server sends a signal to everyone in the room, despite all the parameters are the same as in "hold" function. Holding user:
if action == 'onhold': #holding user
await self.channel_layer.send(
list(usersChannels.keys())[list(usersChannels.values()).index(message['peer'])], #channel to hold
{
'type': 'channel_message',
'action': 'onhold',
'room': 'room',
'message': {message['peer']: '1'},
}
)
return
Unholding user:
if action == 'unhold': # unholding user
await self.channel_layer.send(
list(usersChannels.keys())[list(usersChannels.values()).index(message['peer'])], # channel to unhold
{
'type': 'channel_message',
'action': 'unhold',
'room': 'room',
'message': {message['peer']: '1'},
}
)
return
Full code here: https://pastebin.com/CicsUhy4
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
