Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to list channels stored in a Group?

Is it possible to access the list of channels added in a Group with django-channels?

def consumer(message):
    Group("group_name").add(message.reply_channel)
    channel_list = Group("group_name").???

EDIT:

What I try to achieve is to have access to sessions of all channel, like the list of connected users for instance.

Thus far I use a database based system that lists the connections. But if the server shuts down without executing my ws_disconnect consumers, these connections object will remain in database, and I don't want this.

EDIT 2:

To list the connected users, I found django-channels-presence. I'll test it.

like image 662
vmonteco Avatar asked Sep 12 '16 01:09

vmonteco


1 Answers

Yeah that's possible. And the easy hack is...

# Get channel_layer function
from channels.asgi import get_channel_layer

# passing group_channel takes channel name
channel_layer = get_channel_layer()
ch_group_list = channel_layer.group_channels('<your group name>')
like image 99
Raja Simon Avatar answered Nov 15 '22 07:11

Raja Simon