2020-04-15 20:29:59 +02:00
|
|
|
import logging
|
|
|
|
|
|
|
|
from django.dispatch import receiver
|
2020-04-23 21:08:39 +02:00
|
|
|
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
|
2020-04-23 21:08:39 +02:00
|
|
|
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']))
|
2020-04-23 21:08:39 +02:00
|
|
|
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'],
|
2020-04-23 21:08:39 +02:00
|
|
|
'stream': kwargs['stream'],
|
2020-04-15 20:29:59 +02:00
|
|
|
'target': config.target,
|
|
|
|
'id': config.id
|
|
|
|
})
|