portier/rtmp/models.py

38 lines
1.2 KiB
Python
Raw Normal View History

2020-04-15 20:29:59 +02:00
from django.db import models
from django.utils.translation import gettext as _
2020-04-15 20:29:59 +02:00
import uuid
from . import signals
2020-04-20 14:51:44 +02:00
2020-04-15 20:29:59 +02:00
class Application(models.Model):
name = models.CharField(max_length=100, unique=True, help_text=_("rtmp_application_name"))
2020-04-15 20:29:59 +02:00
def __str__(self):
return self.name
class Stream(models.Model):
2020-04-15 20:29:59 +02:00
application = models.ForeignKey(Application, on_delete=models.CASCADE)
stream = models.CharField(max_length=64, unique=True, default=uuid.uuid4)
2020-04-15 20:29:59 +02:00
name = models.CharField(max_length=100)
def on_publish(self, param):
2020-04-15 20:29:59 +02:00
signals.on_publish.send(sender=self.__class__,
name=self.name,
stream=self.stream,
2020-04-15 20:29:59 +02:00
app=str(self.application),
param=param
)
def on_unpublish(self, param):
2020-04-15 20:29:59 +02:00
signals.on_unpublish.send(sender=self.__class__,
2020-04-20 14:51:44 +02:00
name=self.name,
stream=self.stream,
2020-04-20 14:51:44 +02:00
app=str(self.application),
param=param
)
2020-04-15 20:29:59 +02:00
def __str__(self):
return self.name