From 5e541640c1ef075d61382ccb0dacdba454073c1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Sat, 5 Dec 2020 11:45:42 +0100 Subject: [PATCH] generate stream key --- src/models.py | 1 + src/resources.py | 15 ++++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/models.py b/src/models.py index 500de8b..4b6fc71 100644 --- a/src/models.py +++ b/src/models.py @@ -52,6 +52,7 @@ class StreamResource(db.Model): parent_id = db.Column(UUID(as_uuid=True), db.ForeignKey('stream_resource.id'), nullable=True) children = db.relationship('StreamResource', lazy=False) owner_id = db.Column(db.Integer, db.ForeignKey('videon_user.id'), nullable=False) + stream_key = db.Column(UUID(as_uuid=True), unique=True, nullable=False) owner = db.relationship('VideonUser', backref=backref("stream_resource", cascade="all, delete"), lazy=False) x = db.Column(db.Integer, nullable=False) y = db.Column(db.Integer, nullable=False) diff --git a/src/resources.py b/src/resources.py index 4de21f3..6108b2c 100644 --- a/src/resources.py +++ b/src/resources.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -from uuid import UUID +from uuid import UUID,uuid4 import datetime from flask_jwt_extended import create_access_token, jwt_required, get_jwt_identity @@ -176,12 +176,14 @@ class CreateIngestResource(Resource): abort(417, INVALID_JSON_SCHEMA_MSG) ingest = StreamResource(resource_type=StreamResourceTypeEnum['INGEST'], - url="rtmp://zelenka.tormakristof.eu:6969/origin/asdasd", x=ingestobj['x'],y=ingestobj['y']) + url="rtmp://zelenka.tormakristof.eu:6969/origin/asdasd", x=ingestobj['x'], + y=ingestobj['y']) # username = get_jwt_identity() username = "jozska" user = VideonUser.query.filter_by(name=username).first_or_404() ingest.owner_id = user.id + ingest.stream_key = str(uuid4()) try: db.session.add(ingest) except Exception as e: @@ -220,12 +222,14 @@ class CreateRestreamResource(Resource): abort(417, INVALID_JSON_SCHEMA_MSG) restream = StreamResource(resource_type=StreamResourceTypeEnum['RESTREAM'], - url="rtmp://zelenka.tormakristof.eu:6969/origin/asdasd",x=restreamobj['x'],y=restreamobj['y']) + url="rtmp://zelenka.tormakristof.eu:6969/origin/asdasd", x=restreamobj['x'], + y=restreamobj['y']) # username = get_jwt_identity() username = "jozska" user = VideonUser.query.filter_by(name=username).first_or_404() restream.owner_id = user.id + restream.stream_key = str(uuid4()) if 'inputNeighbour' in restreamobj: restream.parent_id = restreamobj['inputNeighbour'] try: @@ -263,13 +267,14 @@ class CreateEncodeResource(Resource): abort(417, INVALID_JSON_SCHEMA_MSG) encoder = StreamResource(resource_type=StreamResourceTypeEnum['ENCODE'], - url="rtmp://zelenka.tormakristof.eu:6969/origin/asdasd",x=encoderobj['x'],y=encoderobj['y']) + url="rtmp://zelenka.tormakristof.eu:6969/origin/asdasd", x=encoderobj['x'], + y=encoderobj['y']) # username = get_jwt_identity() username = "jozska" user = VideonUser.query.filter_by(name=username).first_or_404() encoder.owner_id = user.id - + encoder.stream_key = str(uuid4()) if 'inputNeighbour' in encoderobj: encoder.parent_id = encoderobj['inputNeighbour']