2020-04-15 20:29:59 +02:00
|
|
|
from django.db import models
|
2020-04-23 20:19:49 +02:00
|
|
|
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):
|
2020-04-23 20:19:49 +02:00
|
|
|
name = models.CharField(max_length=100, unique=True, help_text=_("srs_application_name"))
|
2020-04-15 20:29:59 +02:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
|
|
|
|
class Streamkey(models.Model):
|
|
|
|
application = models.ForeignKey(Application, on_delete=models.CASCADE)
|
|
|
|
key = models.CharField(max_length=64, unique=True, default=uuid.uuid4())
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
|
|
|
|
def on_publish(self, client_ip, client_id, vhost, param):
|
|
|
|
signals.on_publish.send(sender=self.__class__,
|
|
|
|
name=self.name,
|
|
|
|
streamkey=self.key,
|
|
|
|
app=str(self.application),
|
|
|
|
client_ip=client_ip,
|
|
|
|
client_id=client_id,
|
|
|
|
vhost=vhost,
|
|
|
|
param=param
|
|
|
|
)
|
|
|
|
|
|
|
|
def on_unpublish(self, client_ip, client_id, vhost, param):
|
|
|
|
signals.on_unpublish.send(sender=self.__class__,
|
2020-04-20 14:51:44 +02:00
|
|
|
name=self.name,
|
|
|
|
streamkey=self.key,
|
|
|
|
app=str(self.application),
|
|
|
|
client_ip=client_ip,
|
|
|
|
client_id=client_id,
|
|
|
|
vhost=vhost,
|
|
|
|
param=param
|
|
|
|
)
|
2020-04-15 20:29:59 +02:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return '{}'.format(self.name)
|