Skip to content

Commit 89505f3

Browse files
[IMP] discuss: wip recording
see: odoo/sfu#27 task-3725174
1 parent 0ec8b72 commit 89505f3

File tree

7 files changed

+8267
-5785
lines changed

7 files changed

+8267
-5785
lines changed

addons/mail/controllers/discuss/rtc.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,10 @@ def channel_ping(self, channel_id, rtc_session_id=None, check_rtc_session_ids=No
145145
fields_params={"added": rtc_updates[0], "removed": rtc_updates[1]},
146146
)
147147
return store.get_result()
148+
149+
@http.route("/mail/rtc/recording/routing/<channel_id>", methods=["POST"], type="jsonrpc", auth="public")
150+
def route_recording(self, channel_id, recording: bool, transcription: bool):
151+
# TODO: check auth JWT
152+
# if transcription: provide callback upload address, expected format,...
153+
# if recording: get cloud bucket, provide upload address
154+
return

addons/mail/models/discuss/discuss_channel_member.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,10 +442,13 @@ def _rtc_join_call(self, store: Store = None, check_rtc_session_ids=None, camera
442442
"_store_rtc_update_fields",
443443
fields_params={"added": rtc_updates[0], "removed": rtc_updates[1]},
444444
)
445+
has_sfu = bool(discuss.get_sfu_url(self.env))
445446
store.add_singleton_values(
446447
"Rtc",
447448
lambda res: (
448449
res.attr("iceServers", ice_servers or False),
450+
res.attr("canRecord", has_sfu),
451+
res.attr("canTranscribe", has_sfu),
449452
res.one("localSession", "_store_rtc_session_fields", value=rtc_session),
450453
res.attr("serverInfo", self._get_rtc_server_info(rtc_session, ice_servers)),
451454
),
@@ -454,7 +457,10 @@ def _rtc_join_call(self, store: Store = None, check_rtc_session_ids=None, camera
454457
self._rtc_invite_members()
455458

456459
def _join_sfu(self, ice_servers=None, force=False):
457-
if len(self.channel_id.rtc_session_ids) < SFU_MODE_THRESHOLD and not force:
460+
session_count = len(self.channel_id.rtc_session_ids)
461+
if session_count < 2:
462+
return # cant join a SFU when alone
463+
if session_count < SFU_MODE_THRESHOLD and not force:
458464
if self.channel_id.sfu_channel_uuid:
459465
self.channel_id.sfu_channel_uuid = None
460466
self.channel_id.sfu_server_url = None
@@ -475,9 +481,13 @@ def _join_sfu(self, ice_servers=None, force=False):
475481
algorithm=jwt.Algorithm.HS256,
476482
)
477483
try:
484+
recording_address = (
485+
f"{self.get_base_url()}/mail/rtc/recording/routing/{self.channel_id.id}"
486+
)
478487
response = requests.get(
479488
sfu_server_url + "/v1/channel",
480489
headers={"Authorization": "jwt " + json_web_token},
490+
params={"recordingAddress": recording_address},
481491
timeout=3,
482492
)
483493
response.raise_for_status()
@@ -500,9 +510,11 @@ def _get_rtc_server_info(self, rtc_session, ice_servers=None, key=None):
500510
return None
501511
if not key:
502512
key = self.env["ir.config_parameter"].sudo().get_str("mail.sfu_local_key")
513+
is_partner = bool(rtc_session.partner_id)
503514
claims = {
504515
"session_id": rtc_session.id,
505516
"ice_servers": ice_servers,
517+
"permissions": {"recording": is_partner, "transcription": is_partner}
506518
}
507519
json_web_token = jwt.sign(claims, key=key, ttl=60 * 60 * 8, algorithm=jwt.Algorithm.HS256) # 8 hours
508520
return {"url": sfu_server_url, "channelUUID": sfu_channel_uuid, "jsonWebToken": json_web_token}

0 commit comments

Comments
 (0)