portier/srs/views.py

51 lines
1.4 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(request):
if request.method != 'POST':
return HttpResponse('1', status=405)
json_data = json.loads(request.body)
try:
client_ip = json_data['ip']
client_id = json_data['client_id']
vhost = json_data['vhost']
param = json_data['param']
app_name = json_data['app']
stream_name = json_data['stream']
except KeyError:
return HttpResponse('1', status=401)
try:
app = models.Application.objects.get(name=app_name)
streamkey = models.Streamkey.objects.get(key=stream_name)
except ObjectDoesNotExist:
return HttpResponse('1', status=401)
if json_data.get('action') == 'on_publish':
2020-04-20 14:51:44 +02:00
streamkey.on_publish(client_ip=client_ip,
client_id=client_id,
vhost=vhost,
param=param
)
2020-04-15 20:29:59 +02:00
if json_data.get('action') == 'on_unpublish':
2020-04-20 14:51:44 +02:00
streamkey.on_unpublish(client_ip=client_ip,
client_id=client_id,
vhost=vhost,
param=param
)
2020-04-15 20:29:59 +02:00
return HttpResponse('0')