diff options
author | Daniel Calviño Sánchez <danxuliu@gmail.com> | 2023-02-08 13:42:31 +0100 |
---|---|---|
committer | Daniel Calviño Sánchez <danxuliu@gmail.com> | 2023-02-22 13:09:26 +0100 |
commit | 87b20311b0ae075c0a99a09b24a10b0aa3706351 (patch) | |
tree | 1e2a4a74396cdc584b87bf9f2eb3614d4fa9aaaa /recording | |
parent | 3a397142c247c2d1acbb56999965c4e8eedbefc1 (diff) |
Include participant in start/stop requests to the recording server
The participant will be in turn forwarded again to the Nextcloud server
once notified that the recording started or stopped so it retains the
proper participant (for example, in system messages) rather than using
the recording server.
The actor is optional when stopping the recording, as the recording
could be implicitly stopped when the last participant leaves the call.
Nevertheless, this causes the system message to be assigned to a guest
(as the request comes from the recording server), which is unexpected,
so this may need to be adjusted.
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Diffstat (limited to 'recording')
-rw-r--r-- | recording/docs/recording-api.md | 12 | ||||
-rw-r--r-- | recording/src/nextcloud/talk/recording/BackendNotifier.py | 28 | ||||
-rw-r--r-- | recording/src/nextcloud/talk/recording/Server.py | 29 | ||||
-rw-r--r-- | recording/src/nextcloud/talk/recording/Service.py | 16 |
4 files changed, 73 insertions, 12 deletions
diff --git a/recording/docs/recording-api.md b/recording/docs/recording-api.md index b80dc5d1d..41152beaf 100644 --- a/recording/docs/recording-api.md +++ b/recording/docs/recording-api.md @@ -45,6 +45,10 @@ "start": { "status": "the-type-of-recording (1 for audio and video, 2 for audio only)", "owner": "the-user-to-upload-the-resulting-file-as", + "actor": { + "type": "the-type-of-the-actor", + "id": "the-id-of-the-actor", + }, } } ``` @@ -56,5 +60,13 @@ ```json { "type": "stop", + "stop": { + "actor": { + "type": "the-type-of-the-actor", + "id": "the-id-of-the-actor", + }, + }, } ``` + + - `actor` is optional diff --git a/recording/src/nextcloud/talk/recording/BackendNotifier.py b/recording/src/nextcloud/talk/recording/BackendNotifier.py index 78e254f29..43b5485de 100644 --- a/recording/src/nextcloud/talk/recording/BackendNotifier.py +++ b/recording/src/nextcloud/talk/recording/BackendNotifier.py @@ -103,12 +103,16 @@ def backendRequest(backend, data): doRequest(backend, backendRequest) -def started(backend, token, status): +def started(backend, token, status, actorType, actorId): """ Notifies the backend that the recording was started. :param backend: the backend of the conversation. :param token: the token of the conversation. + :param actorType: the actor type of the Talk participant that stopped the + recording. + :param actorId: the actor id of the Talk participant that stopped the + recording. """ backendRequest(backend, { @@ -116,23 +120,39 @@ def started(backend, token, status): 'started': { 'token': token, 'status': status, + 'actor': { + 'type': actorType, + 'id': actorId, + }, }, }) -def stopped(backend, token): +def stopped(backend, token, actorType, actorId): """ Notifies the backend that the recording was stopped. :param backend: the backend of the conversation. :param token: the token of the conversation. + :param actorType: the actor type of the Talk participant that started the + recording. + :param actorId: the actor id of the Talk participant that started the + recording. """ - backendRequest(backend, { + data = { 'type': 'stopped', 'stopped': { 'token': token, }, - }) + } + + if actorType != None and actorId != None: + data['stopped']['actor'] = { + 'type': actorType, + 'id': actorId, + } + + backendRequest(backend, data) def uploadRecording(backend, token, fileName, owner): """ diff --git a/recording/src/nextcloud/talk/recording/Server.py b/recording/src/nextcloud/talk/recording/Server.py index 057b112f5..4c4121c73 100644 --- a/recording/src/nextcloud/talk/recording/Server.py +++ b/recording/src/nextcloud/talk/recording/Server.py @@ -119,12 +119,24 @@ def startRecording(backend, token, data): if 'owner' not in data['start']: raise BadRequest() + if 'actor' not in data['start']: + raise BadRequest() + + if 'type' not in data['start']['actor']: + raise BadRequest() + + if 'id' not in data['start']['actor']: + raise BadRequest() + status = RECORDING_STATUS_AUDIO_AND_VIDEO if 'status' in data['start']: status = data['start']['status'] owner = data['start']['owner'] + actorType = data['start']['actor']['type'] + actorId = data['start']['actor']['id'] + service = None with servicesLock: if serviceId in services: @@ -137,12 +149,12 @@ def startRecording(backend, token, data): app.logger.info(f"Start recording: {backend} {token}") - serviceStartThread = Thread(target=_startRecordingService, args=[service], daemon=True) + serviceStartThread = Thread(target=_startRecordingService, args=[service, actorType, actorId], daemon=True) serviceStartThread.start() return {} -def _startRecordingService(service): +def _startRecordingService(service, actorType, actorId): """ Helper function to start a recording service. @@ -154,7 +166,7 @@ def _startRecordingService(service): serviceId = f'{service.backend}-{service.token}' try: - service.start() + service.start(actorType, actorId) except Exception as exception: with servicesLock: if serviceId not in services: @@ -171,6 +183,15 @@ def _startRecordingService(service): def stopRecording(backend, token, data): serviceId = f'{backend}-{token}' + if 'stop' not in data: + raise BadRequest() + + actorType = None + actorId = None + if 'actor' in data['stop'] and 'type' in data['stop']['actor'] and 'id' in data['stop']['actor']: + actorType = data['stop']['actor']['type'] + actorId = data['stop']['actor']['id'] + service = None with servicesLock: if serviceId not in services: @@ -183,7 +204,7 @@ def stopRecording(backend, token, data): app.logger.info(f"Stop recording: {backend} {token}") - serviceStopThread = Thread(target=service.stop, daemon=True) + serviceStopThread = Thread(target=service.stop, args=[actorType, actorId], daemon=True) serviceStopThread.start() return {} diff --git a/recording/src/nextcloud/talk/recording/Service.py b/recording/src/nextcloud/talk/recording/Service.py index bc74b51dc..12dbb5b7c 100644 --- a/recording/src/nextcloud/talk/recording/Service.py +++ b/recording/src/nextcloud/talk/recording/Service.py @@ -178,12 +178,16 @@ class Service: def __del__(self): self._stopHelpers() - def start(self): + def start(self, actorType, actorId): """ Starts the recording. This method blocks until the recording ends. + :param actorType: the actor type of the Talk participant that started + the recording. + :param actorId: the actor id of the Talk participant that started the + recording. :raise Exception: if the recording ends unexpectedly (including if it could not be started). """ @@ -222,7 +226,7 @@ class Service: self._logger.debug("Joining call") self._participant.joinCall(self.token) - BackendNotifier.started(self.backend, self.token, self.status) + BackendNotifier.started(self.backend, self.token, self.status, actorType, actorId) extensionlessFileName = f'{fullDirectory}/recording-{datetime.now().strftime("%Y%m%d-%H%M%S")}' @@ -248,19 +252,23 @@ class Service: raise - def stop(self): + def stop(self, actorType, actorId): """ Stops the recording and uploads it. The recording is removed from the temporary directory once uploaded, although it is kept if the upload fails. + :param actorType: the actor type of the Talk participant that stopped + the recording. + :param actorId: the actor id of the Talk participant that stopped the + recording. :raise Exception: if the file could not be uploaded. """ self._stopHelpers() - BackendNotifier.stopped(self.backend, self.token) + BackendNotifier.stopped(self.backend, self.token, actorType, actorId) if not self._fileName: self._logger.error(f"Recording stopping before starting, nothing to upload") |