breaking: rename srs app to rtmp and rebuild migrations from scratch
This commit is contained in:
parent
70713fe02c
commit
92bf7fbf75
|
@ -36,7 +36,7 @@ INSTALLED_APPS = [
|
||||||
'django.contrib.sessions',
|
'django.contrib.sessions',
|
||||||
'django.contrib.messages',
|
'django.contrib.messages',
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
'srs.apps.SrsConfig',
|
'rtmp.apps.RtmpConfig',
|
||||||
'restream.apps.RestreamConfig',
|
'restream.apps.RestreamConfig',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -18,5 +18,5 @@ from django.urls import include, path
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
path('srs/', include('srs.urls'))
|
path('rtmp/', include('rtmp.urls'))
|
||||||
]
|
]
|
||||||
|
|
|
@ -3,7 +3,7 @@ from .models import RestreamConfig
|
||||||
|
|
||||||
|
|
||||||
class RestreamConfigAdmin(admin.ModelAdmin):
|
class RestreamConfigAdmin(admin.ModelAdmin):
|
||||||
fields = ['name', 'active', 'streamkey', 'target']
|
fields = ['name', 'active', 'stream', 'target']
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(RestreamConfig, RestreamConfigAdmin)
|
admin.site.register(RestreamConfig, RestreamConfigAdmin)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# Generated by Django 3.0.5 on 2020-04-13 17:45
|
# Generated by Django 3.0.5 on 2020-04-23 19:04
|
||||||
|
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
import django.db.models.deletion
|
import django.db.models.deletion
|
||||||
|
@ -9,7 +9,7 @@ class Migration(migrations.Migration):
|
||||||
initial = True
|
initial = True
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
('srs', '0005_auto_20200413_1745'),
|
('rtmp', '0001_initial'),
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
|
@ -20,7 +20,7 @@ class Migration(migrations.Migration):
|
||||||
('target', models.CharField(max_length=500)),
|
('target', models.CharField(max_length=500)),
|
||||||
('name', models.CharField(max_length=100)),
|
('name', models.CharField(max_length=100)),
|
||||||
('active', models.BooleanField()),
|
('active', models.BooleanField()),
|
||||||
('streamkey', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='srs.Streamkey')),
|
('stream', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='rtmp.Stream')),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
|
@ -2,14 +2,14 @@ from django.db import models
|
||||||
|
|
||||||
# Create your models here.
|
# Create your models here.
|
||||||
|
|
||||||
from srs.models import Streamkey
|
from rtmp.models import Stream
|
||||||
|
|
||||||
|
|
||||||
class RestreamConfig(models.Model):
|
class RestreamConfig(models.Model):
|
||||||
streamkey = models.ForeignKey(Streamkey, on_delete=models.CASCADE)
|
stream = models.ForeignKey(Stream, on_delete=models.CASCADE)
|
||||||
target = models.CharField(max_length=500)
|
target = models.CharField(max_length=500)
|
||||||
name = models.CharField(max_length=100)
|
name = models.CharField(max_length=100)
|
||||||
active = models.BooleanField()
|
active = models.BooleanField()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return '{} to {}'.format(self.streamkey, self.name)
|
return '{} to {}'.format(self.stream, self.name)
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
from srs.signals import on_publish, on_unpublish
|
from rtmp.signals import on_publish, on_unpublish
|
||||||
|
|
||||||
from portier.celery import app as celery
|
from portier.celery import app as celery
|
||||||
|
|
||||||
from .models import RestreamConfig
|
from .models import RestreamConfig
|
||||||
from srs.models import Streamkey
|
from rtmp.models import Stream
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -20,13 +20,12 @@ def callback_on_unpublish(sender, **kwargs):
|
||||||
@receiver(on_publish)
|
@receiver(on_publish)
|
||||||
def callback_on_publish(sender, **kwargs):
|
def callback_on_publish(sender, **kwargs):
|
||||||
logger.info("start publish - {}".format(kwargs['name']))
|
logger.info("start publish - {}".format(kwargs['name']))
|
||||||
streamkey = Streamkey.objects.get(key=kwargs['streamkey'])
|
stream = Stream.objects.get(key=kwargs['stream'])
|
||||||
configs = RestreamConfig.objects.filter(streamkey=streamkey)
|
configs = RestreamConfig.objects.filter(stream=stream)
|
||||||
for config in configs:
|
for config in configs:
|
||||||
pass
|
|
||||||
celery.send_task('main.start_restream', kwargs={
|
celery.send_task('main.start_restream', kwargs={
|
||||||
'app': kwargs['app'],
|
'app': kwargs['app'],
|
||||||
'streamkey': kwargs['streamkey'],
|
'stream': kwargs['stream'],
|
||||||
'target': config.target,
|
'target': config.target,
|
||||||
'id': config.id
|
'id': config.id
|
||||||
})
|
})
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
from django.contrib import admin
|
||||||
|
from .models import Application, Stream
|
||||||
|
|
||||||
|
|
||||||
|
class ApplicationAdmin(admin.ModelAdmin):
|
||||||
|
fields = ['name']
|
||||||
|
|
||||||
|
|
||||||
|
class StreamAdmin(admin.ModelAdmin):
|
||||||
|
fields = ['application', 'stream', 'name']
|
||||||
|
|
||||||
|
|
||||||
|
admin.site.register(Application, ApplicationAdmin)
|
||||||
|
admin.site.register(Stream, StreamAdmin)
|
|
@ -0,0 +1,8 @@
|
||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class RtmpConfig(AppConfig):
|
||||||
|
name = 'rtmp'
|
||||||
|
|
||||||
|
def ready(self):
|
||||||
|
import rtmp.signals # noqa
|
|
@ -1,8 +1,8 @@
|
||||||
# Generated by Django 3.0.5 on 2020-04-13 15:30
|
# Generated by Django 3.0.5 on 2020-04-23 19:04
|
||||||
|
|
||||||
from django.conf import settings
|
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
import django.db.models.deletion
|
import django.db.models.deletion
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
@ -10,7 +10,6 @@ class Migration(migrations.Migration):
|
||||||
initial = True
|
initial = True
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
|
@ -18,16 +17,16 @@ class Migration(migrations.Migration):
|
||||||
name='Application',
|
name='Application',
|
||||||
fields=[
|
fields=[
|
||||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
('name', models.CharField(max_length=16)),
|
('name', models.CharField(help_text='rtmp_application_name', max_length=100, unique=True)),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
name='Streamkey',
|
name='Stream',
|
||||||
fields=[
|
fields=[
|
||||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
('key', models.CharField(max_length=64)),
|
('stream', models.CharField(default=uuid.uuid4, max_length=64, unique=True)),
|
||||||
('application', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='srs.Application')),
|
('name', models.CharField(max_length=100)),
|
||||||
('owner', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
('application', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='rtmp.Application')),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
]
|
]
|
|
@ -6,38 +6,32 @@ from . import signals
|
||||||
|
|
||||||
|
|
||||||
class Application(models.Model):
|
class Application(models.Model):
|
||||||
name = models.CharField(max_length=100, unique=True, help_text=_("srs_application_name"))
|
name = models.CharField(max_length=100, unique=True, help_text=_("rtmp_application_name"))
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
class Streamkey(models.Model):
|
class Stream(models.Model):
|
||||||
application = models.ForeignKey(Application, on_delete=models.CASCADE)
|
application = models.ForeignKey(Application, on_delete=models.CASCADE)
|
||||||
key = models.CharField(max_length=64, unique=True, default=uuid.uuid4())
|
stream = models.CharField(max_length=64, unique=True, default=uuid.uuid4)
|
||||||
name = models.CharField(max_length=100)
|
name = models.CharField(max_length=100)
|
||||||
|
|
||||||
def on_publish(self, client_ip, client_id, vhost, param):
|
def on_publish(self, param):
|
||||||
signals.on_publish.send(sender=self.__class__,
|
signals.on_publish.send(sender=self.__class__,
|
||||||
name=self.name,
|
name=self.name,
|
||||||
streamkey=self.key,
|
stream=self.stream,
|
||||||
app=str(self.application),
|
app=str(self.application),
|
||||||
client_ip=client_ip,
|
|
||||||
client_id=client_id,
|
|
||||||
vhost=vhost,
|
|
||||||
param=param
|
param=param
|
||||||
)
|
)
|
||||||
|
|
||||||
def on_unpublish(self, client_ip, client_id, vhost, param):
|
def on_unpublish(self, param):
|
||||||
signals.on_unpublish.send(sender=self.__class__,
|
signals.on_unpublish.send(sender=self.__class__,
|
||||||
name=self.name,
|
name=self.name,
|
||||||
streamkey=self.key,
|
stream=self.stream,
|
||||||
app=str(self.application),
|
app=str(self.application),
|
||||||
client_ip=client_ip,
|
|
||||||
client_id=client_id,
|
|
||||||
vhost=vhost,
|
|
||||||
param=param
|
param=param
|
||||||
)
|
)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return '{}'.format(self.name)
|
return self.name
|
|
@ -0,0 +1,4 @@
|
||||||
|
from django.dispatch import Signal
|
||||||
|
|
||||||
|
on_publish = Signal(providing_args=['application', 'stream', 'params'])
|
||||||
|
on_unpublish = Signal(providing_args=['application', 'stream', 'params'])
|
|
@ -2,5 +2,5 @@ from django.urls import path
|
||||||
from . import views
|
from . import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('callback', views.callback, name='callback'),
|
path('callback/srs', views.callback_srs, name='callback_srs'),
|
||||||
]
|
]
|
|
@ -11,40 +11,32 @@ logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
def callback(request):
|
def callback_srs(request):
|
||||||
if request.method != 'POST':
|
if request.method != 'POST':
|
||||||
return HttpResponse('1', status=405)
|
return HttpResponse('1', status=405)
|
||||||
|
|
||||||
json_data = json.loads(request.body)
|
try:
|
||||||
|
json_data = json.loads(request.body)
|
||||||
|
except json.decoder.JSONDecodeError:
|
||||||
|
return HttpResponse('1', status=400)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
client_ip = json_data['ip']
|
|
||||||
client_id = json_data['client_id']
|
|
||||||
vhost = json_data['vhost']
|
|
||||||
param = json_data['param']
|
|
||||||
app_name = json_data['app']
|
app_name = json_data['app']
|
||||||
stream_name = json_data['stream']
|
stream_name = json_data['stream']
|
||||||
|
param = json_data['param']
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return HttpResponse('1', status=401)
|
return HttpResponse('1', status=401)
|
||||||
try:
|
try:
|
||||||
application = models.Application.objects.get(name=app_name)
|
application = models.Application.objects.get(name=app_name)
|
||||||
streamkey = models.Streamkey.objects.get(key=stream_name, application=application)
|
stream = models.Stream.objects.get(stream=stream_name, application=application)
|
||||||
|
|
||||||
except ObjectDoesNotExist:
|
except ObjectDoesNotExist:
|
||||||
return HttpResponse('1', status=401)
|
return HttpResponse('1', status=401)
|
||||||
|
|
||||||
if json_data.get('action') == 'on_publish':
|
if json_data.get('action') == 'on_publish':
|
||||||
streamkey.on_publish(client_ip=client_ip,
|
stream.on_publish(param=param)
|
||||||
client_id=client_id,
|
|
||||||
vhost=vhost,
|
|
||||||
param=param
|
|
||||||
)
|
|
||||||
|
|
||||||
if json_data.get('action') == 'on_unpublish':
|
if json_data.get('action') == 'on_unpublish':
|
||||||
streamkey.on_unpublish(client_ip=client_ip,
|
stream.on_unpublish(param=param)
|
||||||
client_id=client_id,
|
|
||||||
vhost=vhost,
|
|
||||||
param=param
|
|
||||||
)
|
|
||||||
|
|
||||||
return HttpResponse('0')
|
return HttpResponse('0')
|
14
srs/admin.py
14
srs/admin.py
|
@ -1,14 +0,0 @@
|
||||||
from django.contrib import admin
|
|
||||||
from .models import Application, Streamkey
|
|
||||||
|
|
||||||
|
|
||||||
class ApplicationAdmin(admin.ModelAdmin):
|
|
||||||
fields = ['name']
|
|
||||||
|
|
||||||
|
|
||||||
class StreamkeyAdmin(admin.ModelAdmin):
|
|
||||||
fields = ['application', 'key', 'name']
|
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(Application, ApplicationAdmin)
|
|
||||||
admin.site.register(Streamkey, StreamkeyAdmin)
|
|
|
@ -1,8 +0,0 @@
|
||||||
from django.apps import AppConfig
|
|
||||||
|
|
||||||
|
|
||||||
class SrsConfig(AppConfig):
|
|
||||||
name = 'srs'
|
|
||||||
|
|
||||||
def ready(self):
|
|
||||||
import srs.signals # noqa
|
|
|
@ -1,19 +0,0 @@
|
||||||
# Generated by Django 3.0.5 on 2020-04-13 15:40
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('srs', '0001_initial'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AddField(
|
|
||||||
model_name='streamkey',
|
|
||||||
name='name',
|
|
||||||
field=models.CharField(default='', max_length=16),
|
|
||||||
preserve_default=False,
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,17 +0,0 @@
|
||||||
# Generated by Django 3.0.5 on 2020-04-13 17:21
|
|
||||||
|
|
||||||
from django.db import migrations
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('srs', '0002_streamkey_name'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.RemoveField(
|
|
||||||
model_name='streamkey',
|
|
||||||
name='owner',
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,28 +0,0 @@
|
||||||
# Generated by Django 3.0.5 on 2020-04-13 17:36
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('srs', '0003_remove_streamkey_owner'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='application',
|
|
||||||
name='name',
|
|
||||||
field=models.CharField(max_length=100, unique=True),
|
|
||||||
),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='streamkey',
|
|
||||||
name='key',
|
|
||||||
field=models.CharField(max_length=64, unique=True),
|
|
||||||
),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='streamkey',
|
|
||||||
name='name',
|
|
||||||
field=models.CharField(max_length=100),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,20 +0,0 @@
|
||||||
# Generated by Django 3.0.5 on 2020-04-13 17:45
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
import uuid
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('srs', '0004_auto_20200413_1736'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='streamkey',
|
|
||||||
name='key',
|
|
||||||
field=models.CharField(default=uuid.UUID('b5777854-4533-49dc-b38d-69738d8844d6'),
|
|
||||||
max_length=64, unique=True),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,4 +0,0 @@
|
||||||
from django.dispatch import Signal
|
|
||||||
|
|
||||||
on_publish = Signal(providing_args=['application', 'streamkey', 'node'])
|
|
||||||
on_unpublish = Signal(providing_args=['application', 'streamkey', 'node'])
|
|
Loading…
Reference in New Issue