create mesh app and basic asgi websocket setup for communication
This commit is contained in:
parent
f51bc71799
commit
8af6bca51c
10 changed files with 63 additions and 0 deletions
16
src/c3nav/asgi.py
Normal file
16
src/c3nav/asgi.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
import os
|
||||
|
||||
from channels.auth import AuthMiddlewareStack
|
||||
from channels.routing import ProtocolTypeRouter, URLRouter
|
||||
from django.core.asgi import get_asgi_application
|
||||
|
||||
from c3nav.urls import websocket_urlpatterns
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')
|
||||
|
||||
application = ProtocolTypeRouter({
|
||||
"http": get_asgi_application(),
|
||||
"websocket": AuthMiddlewareStack(
|
||||
URLRouter(websocket_urlpatterns)
|
||||
),
|
||||
})
|
0
src/c3nav/mesh/__init__.py
Normal file
0
src/c3nav/mesh/__init__.py
Normal file
12
src/c3nav/mesh/consumers.py
Normal file
12
src/c3nav/mesh/consumers.py
Normal file
|
@ -0,0 +1,12 @@
|
|||
from channels.generic.websocket import WebsocketConsumer
|
||||
|
||||
|
||||
class EchoConsumer(WebsocketConsumer):
|
||||
def connect(self):
|
||||
self.accept()
|
||||
|
||||
def disconnect(self, close_code):
|
||||
pass
|
||||
|
||||
def receive(self, text_data):
|
||||
self.send(text_data=text_data)
|
0
src/c3nav/mesh/migrations/__init__.py
Normal file
0
src/c3nav/mesh/migrations/__init__.py
Normal file
0
src/c3nav/mesh/models.py
Normal file
0
src/c3nav/mesh/models.py
Normal file
7
src/c3nav/mesh/urls.py
Normal file
7
src/c3nav/mesh/urls.py
Normal file
|
@ -0,0 +1,7 @@
|
|||
from django.urls import path
|
||||
|
||||
from c3nav.mesh.consumers import EchoConsumer
|
||||
|
||||
websocket_urlpatterns = [
|
||||
path('ws', EchoConsumer.as_asgi()),
|
||||
]
|
18
src/c3nav/routing.py
Normal file
18
src/c3nav/routing.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
import os
|
||||
|
||||
from channels.auth import AuthMiddlewareStack
|
||||
from channels.routing import ProtocolTypeRouter, URLRouter
|
||||
from django.core.asgi import get_asgi_application
|
||||
|
||||
import c3nav.site.routing
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')
|
||||
|
||||
application = ProtocolTypeRouter({
|
||||
"http": get_asgi_application(),
|
||||
"websocket": AuthMiddlewareStack(
|
||||
URLRouter(
|
||||
c3nav.site.routing.websocket_urlpatterns
|
||||
)
|
||||
),
|
||||
})
|
|
@ -237,6 +237,7 @@ INSTALLED_APPS = [
|
|||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'channels',
|
||||
'compressor',
|
||||
'bootstrap3',
|
||||
'c3nav.api',
|
||||
|
@ -245,6 +246,7 @@ INSTALLED_APPS = [
|
|||
'c3nav.routing',
|
||||
'c3nav.site',
|
||||
'c3nav.control',
|
||||
'c3nav.mesh',
|
||||
'c3nav.editor',
|
||||
]
|
||||
|
||||
|
@ -287,6 +289,7 @@ X_FRAME_OPTIONS = 'DENY'
|
|||
ROOT_URLCONF = 'c3nav.urls'
|
||||
|
||||
WSGI_APPLICATION = 'c3nav.wsgi.application'
|
||||
ASGI_APPLICATION = 'c3nav.asgi.application'
|
||||
|
||||
USE_I18N = True
|
||||
USE_L10N = True
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
from contextlib import suppress
|
||||
|
||||
from channels.routing import URLRouter
|
||||
from django.conf import settings
|
||||
from django.contrib import admin
|
||||
from django.urls import include, path
|
||||
|
@ -8,6 +9,7 @@ import c3nav.api.urls
|
|||
import c3nav.control.urls
|
||||
import c3nav.editor.urls
|
||||
import c3nav.mapdata.urls
|
||||
import c3nav.mesh.urls
|
||||
import c3nav.site.urls
|
||||
|
||||
urlpatterns = [
|
||||
|
@ -20,6 +22,10 @@ urlpatterns = [
|
|||
path('', include(c3nav.site.urls)),
|
||||
]
|
||||
|
||||
websocket_urlpatterns = [
|
||||
path('mesh/', URLRouter(c3nav.mesh.urls.websocket_urlpatterns)),
|
||||
]
|
||||
|
||||
if settings.DEBUG:
|
||||
with suppress(ImportError):
|
||||
import debug_toolbar
|
||||
|
|
|
@ -15,3 +15,4 @@ qrcode==7.3.1
|
|||
matplotlib==3.5.1
|
||||
scipy==1.8.0
|
||||
django_libsass==0.9
|
||||
channels==3.0.4
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue