Friday, October 26, 2018

Channels -- a question about how ProtocolTypeRouter works

Hi,    Newbie here. (please bear with me if this a stupid question)
I am going through the tutorial and doc and got this question regarding how ProtocolTypeRouter works.  ProtocolTypeRouter.__init__ takes a dict "application_mapping" and append a key-value pair to it: "http': class AsgiHandler  As doc says ASGI application is created on a per scope basis, I think I vaguely understand how the "http" one works.   Once a http scope comes in, an instance/object of class AsgiHandler is initiated, which lasts for the duration of the scope.  So it is one scope leads to one ASGI application/object    But I am confused about this one:  application = ProtocolTypeRouter({      # (http->django views is added by default)      'websocket': AuthMiddlewareStack(          URLRouter(              chat.routing.websocket_urlpatterns          )      ),  })  The whole value of this key-value pair AuthMiddlewareStack(URLRouter(chat.routing.websocket_urlpatterns)) seems to be a object not a class,   so that means the application already exists before a websocket scope comes in. How does this conform to "one scope one application" rule?    Any help would be appreciated.    Thanks  Drew

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f6088bd4-457a-4106-b883-332af9a99337%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment