本文整理汇总了Python中channels.asgi.get_channel_layer方法的典型用法代码示例。如果您正苦于以下问题:Python asgi.get_channel_layer方法的具体用法?Python asgi.get_channel_layer怎么用?Python asgi.get_channel_layer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类channels.asgi
的用法示例。
在下文中一共展示了asgi.get_channel_layer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: whois
# 需要导入模块: from channels import asgi [as 别名]
# 或者: from channels.asgi import get_channel_layer [as 别名]
def whois(request):
mimetype = 'application/json'
# Get channel_layer function
from channels.asgi import get_channel_layer
from channels.sessions import session_for_reply_channel
# passing group_channel takes channel name
#channel_layer = get_channel_layer()
#data = channel_layer.group_channels('notifications')
#data = channel_layer.global_statistics()
#data = channel_layer.channel_statistics('notifications')
#data = get_channel_layer().group_channels('notifications')
#data = Group("notifications").extensions
#data = get_channel_layer().receive_twisted()
#from channels import channel_layers
#layer = channel_layers["default"]
#print(layer.router.channels)
data = []
from django.contrib.sessions.backends import cache as engine
data = get_channel_layer().group_channels('notifications')
active_users = []
for C in data:
#Channel(C).send({"text": json.dumps({'clean_signal':True})})
c_session = session_for_reply_channel(C)
session = engine.SessionStore(c_session._session_key)
#print(c_session._session['_auth_user_id'])
#print(session.keys())
#print(session.get('username', None), session.get_expiry_date())
username = session.get('username', None)
# this is the same
# username = c_session.get('username', None)
if username not in active_users and username != None:
active_users.append(username)
data = active_users
return HttpResponse(json.dumps(data), mimetype)