portier/rtmp/views.py

43 lines
1.1 KiB
Python
Raw Normal View History

2020-04-15 20:29:59 +02:00
import json
import logging
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
from django.core.exceptions import ObjectDoesNotExist
from . import models
logger = logging.getLogger(__name__)
2020-04-20 14:51:44 +02:00
2020-04-15 20:29:59 +02:00
@csrf_exempt
def callback_srs(request):
2020-04-15 20:29:59 +02:00
if request.method != 'POST':
return HttpResponse('1', status=405)
try:
json_data = json.loads(request.body)
except json.decoder.JSONDecodeError:
return HttpResponse('1', status=400)
2020-04-15 20:29:59 +02:00
try:
app_name = json_data['app']
stream_name = json_data['stream']
param = json_data['param']
2020-04-15 20:29:59 +02:00
except KeyError:
return HttpResponse('1', status=401)
try:
application = models.Application.objects.get(name=app_name)
stream = models.Stream.objects.get(stream=stream_name, application=application)
2020-04-15 20:29:59 +02:00
except ObjectDoesNotExist:
return HttpResponse('1', status=401)
if json_data.get('action') == 'on_publish':
stream.on_publish(param=param)
2020-04-15 20:29:59 +02:00
if json_data.get('action') == 'on_unpublish':
stream.on_unpublish(param=param)
2020-04-15 20:29:59 +02:00
return HttpResponse('0')