portier/restream/signals.py

32 lines
932 B
Python
Raw Permalink Normal View History

2020-04-15 20:29:59 +02:00
import logging
from django.dispatch import receiver
from rtmp.signals import on_publish, on_unpublish
2020-04-15 20:29:59 +02:00
from portier.celery import app as celery
from .models import RestreamConfig
from rtmp.models import Stream
2020-04-15 20:29:59 +02:00
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']))
stream = Stream.objects.get(key=kwargs['stream'])
configs = RestreamConfig.objects.filter(stream=stream)
2020-04-15 20:29:59 +02:00
for config in configs:
celery.send_task('main.start_restream', kwargs={
'app': kwargs['app'],
'stream': kwargs['stream'],
2020-04-15 20:29:59 +02:00
'target': config.target,
'id': config.id
})