Skip to content

Commit

Permalink
recording: implement correct sending of record ready callback
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippKilian committed May 15, 2024
1 parent f3eb770 commit 5599d0e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
1 change: 1 addition & 0 deletions b3lb/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ django-environ==0.11.2
django-redis==5.4.0
django-storages==1.14.2
intervaltree==3.1.0
pyjwt==2.8.0
psycopg2cffi==2.9.0
requests==2.31.0
uvicorn[standard]==0.23.2
Expand Down
6 changes: 6 additions & 0 deletions b3lb/rest/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,12 @@ class Meta(object):
def __str__(self):
return "{}-{}".format(self.tenant.slug, str(self.sub_id).zfill(3))

@property
def get_valid_secret(self) -> str:
if self.secret2:
return str(self.secret2)
return str(self.secret)

@property
def endpoint(self) -> str:
if self.sub_id == 0:
Expand Down
25 changes: 14 additions & 11 deletions b3lb/rest/task/recording.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@
from django.utils import timezone as tz
from django.conf import settings
from os import makedirs, path
from requests import get
from jwt import encode as jwt_encode
from requests import post
if settings.B3LB_RENDERING:
from rest.b3lb.make_xges import render_xges
from rest.models import Record, RecordSet, RecordProfile, SecretRecordProfileRelation
from subprocess import DEVNULL, PIPE, Popen
from tempfile import TemporaryDirectory


def render_by_profile(record_set: RecordSet, record_profile: RecordProfile, tempdir: str):
def render_by_profile(record_set: RecordSet, record_profile: RecordProfile, tempdir: str) -> str:
"""
Render RecordSet with given RecordProfile in tempdir with
Expand Down Expand Up @@ -59,6 +60,7 @@ def render_by_profile(record_set: RecordSet, record_profile: RecordProfile, temp
record.published = True
record.save()
print(f"Finished rendering {record_set.__str__()} with profile {record_profile.name}")
return str(record.uuid)


def render_record(record_set: RecordSet):
Expand All @@ -79,20 +81,21 @@ def render_record(record_set: RecordSet):
profile_relations = SecretRecordProfileRelation.objects.filter(secret=record_set.secret)
if profile_relations.count() > 0:
for profile_relation in profile_relations:
render_by_profile(record_set, profile_relation.record_profile, tempdir)
record_id = render_by_profile(record_set, profile_relation.record_profile, tempdir)
else:
for record_profile in RecordProfile.objects.filter(is_default=True):
render_by_profile(record_set, record_profile, tempdir)
record_id = render_by_profile(record_set, record_profile, tempdir)

# Greenlight v3 sends a record ready URL, Greenlight v2 doesn't send one
if record_set.recording_ready_origin_url:
body = {"signed_parameters": jwt_encode({"meeting_id": record_set.meta_meeting_id, "record_id": record_id}, record_set.secret.get_valid_secret)}
response = post(record_set.recording_ready_origin_url, json=body)
print(f"Send record ready callback to: {record_set.recording_ready_origin_url} with return code: {response.status_code}")
if response.status_code < 200 or 299 < response.status_code:
return False

record_set.status = RecordSet.RENDERED
record_set.save()
print("Send record ready to Greenlight, if url exists")
if record_set.recording_ready_origin_url:
try:
print(f"send GET to: {record_set.recording_ready_origin_url}")
print(f"Status code: {get(record_set.recording_ready_origin_url).status_code}")
except:
pass
return True


Expand Down

0 comments on commit 5599d0e

Please sign in to comment.