This commit is contained in:
SergeantPanda 2025-03-07 08:34:21 -06:00
commit fe83e8a03e
49 changed files with 813 additions and 401 deletions

View file

@ -1,8 +1,14 @@
"""
ASGI config for dispatcharr project.
"""
import os
from django.core.asgi import get_asgi_application
from channels.routing import ProtocolTypeRouter, URLRouter
from channels.auth import AuthMiddlewareStack
import dispatcharr.routing
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'dispatcharr.settings')
application = get_asgi_application()
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dispatcharr.settings")
application = ProtocolTypeRouter({
"http": get_asgi_application(),
"websocket": AuthMiddlewareStack(
URLRouter(dispatcharr.routing.websocket_urlpatterns)
),
})

18
dispatcharr/consumers.py Normal file
View file

@ -0,0 +1,18 @@
import json
from channels.generic.websocket import AsyncWebsocketConsumer
class MyWebSocketConsumer(AsyncWebsocketConsumer):
async def connect(self):
await self.accept()
self.room_name = "updates"
await self.channel_layer.group_add(self.room_name, self.channel_name)
async def disconnect(self, close_code):
await self.channel_layer.group_discard(self.room_name, self.channel_name)
async def receive(self, text_data):
data = json.loads(text_data)
print("Received:", data)
async def m3u_refresh(self, event):
await self.send(text_data=json.dumps(event))

6
dispatcharr/routing.py Normal file
View file

@ -0,0 +1,6 @@
from django.urls import path
from dispatcharr.consumers import MyWebSocketConsumer
websocket_urlpatterns = [
path("ws/", MyWebSocketConsumer.as_asgi()),
]

View file

@ -6,6 +6,7 @@ BASE_DIR = Path(__file__).resolve().parent.parent
SECRET_KEY = 'REPLACE_ME_WITH_A_REAL_SECRET'
REDIS_HOST = os.environ.get("REDIS_HOST", "localhost")
REDIS_DB = os.environ.get("REDIS_DB", "0")
DEBUG = True
ALLOWED_HOSTS = ["*"]
@ -13,7 +14,7 @@ ALLOWED_HOSTS = ["*"]
INSTALLED_APPS = [
'apps.api',
'apps.accounts',
'apps.channels',
'apps.channels.apps.ChannelsConfig',
'apps.dashboard',
'apps.epg',
'apps.hdhr',
@ -22,6 +23,8 @@ INSTALLED_APPS = [
'apps.proxy.apps.ProxyConfig',
'core',
'drf_yasg',
'daphne',
'channels',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
@ -70,6 +73,15 @@ TEMPLATES = [
WSGI_APPLICATION = 'dispatcharr.wsgi.application'
ASGI_APPLICATION = 'dispatcharr.asgi.application'
CHANNEL_LAYERS = {
"default": {
"BACKEND": "channels_redis.core.RedisChannelLayer",
"CONFIG": {
"hosts": [(REDIS_HOST, 6379, REDIS_DB)], # Ensure Redis is running
},
},
}
if os.getenv('DB_ENGINE', None) == 'sqlite':
DATABASES = {
'default': {

View file

@ -6,6 +6,9 @@ from django.views.generic import TemplateView, RedirectView
from rest_framework import permissions
from drf_yasg.views import get_schema_view
from drf_yasg import openapi
from .routing import websocket_urlpatterns
from apps.hdhr.api_views import HDHRDeviceViewSet, DiscoverAPIView, LineupAPIView, LineupStatusAPIView, HDHRDeviceXMLAPIView, hdhr_dashboard_view
# Define schema_view for Swagger
schema_view = get_schema_view(
@ -24,7 +27,7 @@ schema_view = get_schema_view(
urlpatterns = [
# API Routes
path('api/', include(('apps.api.urls', 'api'), namespace='api')),
path('api', RedirectView.as_view(url='/api/', permanent=True)),
path('api', RedirectView.as_view(url='/api/', permanent=True)),
# Admin
path('admin', RedirectView.as_view(url='/admin/', permanent=True)),
@ -42,6 +45,13 @@ urlpatterns = [
path('proxy/', include(('apps.proxy.urls', 'proxy'), namespace='proxy')),
path('proxy', RedirectView.as_view(url='/proxy/', permanent=True)),
# HDHR API
path('discover.json', DiscoverAPIView.as_view(), name='discover'),
path('lineup.json', LineupAPIView.as_view(), name='lineup'),
path('lineup_status.json', LineupStatusAPIView.as_view(), name='lineup_status'),
path('device.xml', HDHRDeviceXMLAPIView.as_view(), name='device_xml'),
# Swagger UI
path('swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
@ -57,6 +67,8 @@ urlpatterns = [
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += websocket_urlpatterns
# Serve static files for development (React's JS, CSS, etc.)
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)