本文整理匯總了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)