summaryrefslogtreecommitdiffstats
path: root/recording
diff options
context:
space:
mode:
authorDaniel Calviño Sánchez <danxuliu@gmail.com>2023-02-08 13:23:44 +0100
committerDaniel Calviño Sánchez <danxuliu@gmail.com>2023-02-22 02:41:25 +0100
commit24bb1cf20f091c83f4de4cb42984534670c7313d (patch)
tree2e33eb4bc1b4b6879a181542a5f0d6e1f4b4b47b /recording
parent7ee0f148248305fbdc3d871fb94cb6c6877c72be (diff)
Change recording status when notified by the recording server
Before the recording status was immediately changed by the Nextcloud server when a recording was started or stopped. However starting or stopping (but mostly starting) can take some time due to the initialization of the display and audio device, starting the browser, joining the call... so the recording status did not match the actual status. To address that now the recording server sends a notification back to the Nextcloud server when the recording actually started or stopped, and only then the Nextcloud server changes the recording status. Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Diffstat (limited to 'recording')
-rw-r--r--recording/src/nextcloud/talk/recording/BackendNotifier.py60
-rw-r--r--recording/src/nextcloud/talk/recording/Service.py4
2 files changed, 64 insertions, 0 deletions
diff --git a/recording/src/nextcloud/talk/recording/BackendNotifier.py b/recording/src/nextcloud/talk/recording/BackendNotifier.py
index 8177c8253..78e254f29 100644
--- a/recording/src/nextcloud/talk/recording/BackendNotifier.py
+++ b/recording/src/nextcloud/talk/recording/BackendNotifier.py
@@ -23,6 +23,7 @@ Module to send requests to the Nextcloud server.
import hashlib
import hmac
+import json
import logging
import os
import ssl
@@ -74,6 +75,65 @@ def doRequest(backend, request, retries=3):
logger.exception(f"Failed to send message to backend, giving up!")
raise
+def backendRequest(backend, data):
+ """
+ Sends the data to the backend on the endpoint to receive notifications from
+ the recording server.
+
+ The data is automatically wrapped in a request for the appropriate URL and
+ with the needed headers.
+
+ :param backend: the backend to send the data to.
+ :param data: the data to send.
+ """
+ url = backend + '/ocs/v2.php/apps/spreed/api/v1/recording/backend'
+
+ data = json.dumps(data).encode()
+
+ random, checksum = getRandomAndChecksum(backend, data)
+
+ headers = {
+ 'Content-Type': 'application/json',
+ 'OCS-ApiRequest': 'true',
+ 'Talk-Recording-Random': random,
+ 'Talk-Recording-Checksum': checksum,
+ }
+
+ backendRequest = Request(url, data, headers)
+
+ doRequest(backend, backendRequest)
+
+def started(backend, token, status):
+ """
+ Notifies the backend that the recording was started.
+
+ :param backend: the backend of the conversation.
+ :param token: the token of the conversation.
+ """
+
+ backendRequest(backend, {
+ 'type': 'started',
+ 'started': {
+ 'token': token,
+ 'status': status,
+ },
+ })
+
+def stopped(backend, token):
+ """
+ Notifies the backend that the recording was stopped.
+
+ :param backend: the backend of the conversation.
+ :param token: the token of the conversation.
+ """
+
+ backendRequest(backend, {
+ 'type': 'stopped',
+ 'stopped': {
+ 'token': token,
+ },
+ })
+
def uploadRecording(backend, token, fileName, owner):
"""
Upload the recording specified by fileName.
diff --git a/recording/src/nextcloud/talk/recording/Service.py b/recording/src/nextcloud/talk/recording/Service.py
index 0bb1519f5..bc74b51dc 100644
--- a/recording/src/nextcloud/talk/recording/Service.py
+++ b/recording/src/nextcloud/talk/recording/Service.py
@@ -222,6 +222,8 @@ class Service:
self._logger.debug("Joining call")
self._participant.joinCall(self.token)
+ BackendNotifier.started(self.backend, self.token, self.status)
+
extensionlessFileName = f'{fullDirectory}/recording-{datetime.now().strftime("%Y%m%d-%H%M%S")}'
recorderArgs = getRecorderArgs(self.status, self._display.new_display_var, audioSinkIndex, width, height, extensionlessFileName)
@@ -258,6 +260,8 @@ class Service:
self._stopHelpers()
+ BackendNotifier.stopped(self.backend, self.token)
+
if not self._fileName:
self._logger.error(f"Recording stopping before starting, nothing to upload")