portier/restream/signals.py

24 lines
740 B
Python
Raw Normal View History

2020-04-15 20:29:59 +02:00
from django.dispatch import receiver
from rtmp.signals import stream_active
2020-04-15 20:29:59 +02:00
from .models import RestreamConfig
from rtmp.models import Stream
from concierge.models import Task
import json
2020-04-20 14:51:44 +02:00
2020-04-15 20:29:59 +02:00
@receiver(stream_active)
def create_tasks(sender, **kwargs):
stream = Stream.objects.get(stream=kwargs['stream'])
instances = RestreamConfig.objects.filter(active=True, stream=stream)
for inst in instances:
config = {
'name': inst.name,
'app': inst.stream.application.name,
'stream': str(inst.stream.stream),
'target': inst.target
}
json_config = json.dumps(config)
task = Task(stream=stream, type='restream', configuration=json_config)
task.save()