portier/restream/signals.py

33 lines
967 B
Python
Raw Permalink Normal View History

2020-04-15 20:29:59 +02:00
import logging
from django.dispatch import receiver
from srs.signals import on_publish, on_unpublish
from portier.celery import app as celery
from .models import RestreamConfig
from srs.models import Streamkey
logger = logging.getLogger(__name__)
2020-04-20 14:51:44 +02:00
2020-04-15 20:29:59 +02:00
@receiver(on_unpublish)
def callback_on_unpublish(sender, **kwargs):
logger.info("stop publish - {}".format(kwargs['name']))
2020-04-20 14:51:44 +02:00
celery.send_task('main.stop_restream', kwargs={'name': kwargs['name']})
2020-04-15 20:29:59 +02:00
@receiver(on_publish)
def callback_on_publish(sender, **kwargs):
logger.info("start publish - {}".format(kwargs['name']))
streamkey = Streamkey.objects.get(key=kwargs['streamkey'])
configs = RestreamConfig.objects.filter(streamkey=streamkey)
for config in configs:
pass
celery.send_task('main.start_restream', kwargs={
'app': kwargs['app'],
'streamkey': kwargs['streamkey'],
'target': config.target,
'id': config.id
})