|
24 | 24 |
|
25 | 25 | from channels.routing import ProtocolTypeRouter, URLRouter
|
26 | 26 | from channels.auth import AuthMiddlewareStack
|
27 |
| -from channels.http import AsgiHandler |
28 | 27 |
|
29 |
| -from django.conf.urls import url |
30 | 28 | from django.urls import re_path
|
31 | 29 |
|
32 | 30 | from .consumers import MessageConsumer, PokePipeConsumer
|
33 | 31 | from .util import pipe_ws_endpoint_name, http_endpoint, http_poke_endpoint_enabled
|
34 | 32 |
|
| 33 | +try: |
| 34 | + from channels.http import AsgiHandler |
| 35 | + OLDER_CHANNELS = True |
| 36 | +except: |
| 37 | + from django.core.asgi import get_asgi_application |
| 38 | + OLDER_CHANNELS = False |
| 39 | + |
| 40 | + |
35 | 41 | # TODO document this and discuss embedding with other routes
|
36 | 42 |
|
37 | 43 | http_routes = [
|
38 | 44 | ]
|
39 | 45 |
|
| 46 | + |
40 | 47 | if http_poke_endpoint_enabled():
|
41 |
| - http_routes.append(re_path(http_endpoint("poke"), PokePipeConsumer)) |
| 48 | + http_routes.append(re_path(http_endpoint("poke"), PokePipeConsumer if OLDER_CHANNELS else PokePipeConsumer.as_asgi())) |
| 49 | + |
| 50 | + |
| 51 | +if OLDER_CHANNELS: |
| 52 | + http_routes.append(re_path("^", AsgiHandler)) # AsgiHandler is 'the normal Django view handlers' |
| 53 | +else: |
| 54 | + http_routes.append(re_path("^", get_asgi_application())) |
42 | 55 |
|
43 |
| -http_routes.append(re_path("^", AsgiHandler)) # AsgiHandler is 'the normal Django view handlers' |
44 | 56 |
|
45 | 57 | application = ProtocolTypeRouter({
|
46 |
| - 'websocket': AuthMiddlewareStack(URLRouter([re_path(pipe_ws_endpoint_name(), MessageConsumer),])), |
| 58 | + 'websocket': AuthMiddlewareStack(URLRouter([re_path(pipe_ws_endpoint_name(), MessageConsumer if OLDER_CHANNELS else MessageConsumer.as_asgi()),])), |
47 | 59 | 'http': AuthMiddlewareStack(URLRouter(http_routes)),
|
48 |
| - }) |
| 60 | +}) |
0 commit comments