Skip to main content

opentalk_roomserver_types_livekit/
internal.rs

1// SPDX-License-Identifier: EUPL-1.2
2// SPDX-FileCopyrightText: OpenTalk Team <mail@opentalk.eu>
3
4use std::{collections::BTreeSet, fmt::Debug};
5
6use opentalk_roomserver_signaling::signaling_module::InternalCommand;
7use opentalk_roomserver_types::livekit_proxy::{
8    LiveKitProxyRequest, PreparedSocket, websocket::LiveKitSocket,
9};
10use opentalk_types_signaling::ParticipantId;
11use tokio::sync::oneshot;
12use url::Url;
13
14use crate::MicrophoneRestrictionState;
15
16/// Internal LiveKit commands that can be sent by other modules
17#[derive(Debug)]
18pub enum LiveKitInternal {
19    /// Mutes participants
20    Mute {
21        /// The original sender of the command
22        sender: Option<ParticipantId>,
23        /// The participants that should get muted
24        participants: BTreeSet<ParticipantId>,
25        /// The return channel for the result of the operation
26        return_channel: oneshot::Sender<ParticipantsMuted>,
27    },
28
29    /// Enables or disables microphone restriction state
30    UpdateMicrophoneRestrictions {
31        /// The original sender of the command
32        sender: ParticipantId,
33        /// The new microphone restriction state
34        new_state: MicrophoneRestrictionState,
35        /// The return channel for the result of the operation
36        return_channel:
37            oneshot::Sender<Result<MicrophoneRestrictionState, MicrophoneRestrictionError>>,
38    },
39
40    /// Prepare a livekit proxy socket by verifying access and connecting to the upstream LiveKit
41    /// server.
42    ConnectUpstreamSocket {
43        websocket_request: Box<LiveKitProxyRequest>,
44        return_channel: oneshot::Sender<Option<PreparedSocket>>,
45    },
46
47    /// Connect the client socket and finalize the proxy setup.
48    ConnectDownstreamSocket {
49        websocket_request: Box<LiveKitProxyRequest>,
50        upstream_socket: Box<PreparedSocket>,
51        downstream_socket: Box<dyn LiveKitSocket>,
52        return_channel: oneshot::Sender<()>,
53    },
54
55    /// Return the configured LiveKit service URL
56    GetLivekitServiceUrl {
57        return_channel: oneshot::Sender<Url>,
58    },
59}
60
61/// The type of error that can occur when updating the microphone restriction state
62#[derive(Debug)]
63pub enum MicrophoneRestrictionErrorKind {
64    /// The received command cannot be executed since there is already a conflicting ongoing task.
65    ConflictingTask,
66    /// Livekit server is not available
67    LivekitUnavailable,
68}
69
70/// Internal error that can occur when updating the microphone restriction state
71#[derive(Debug)]
72pub struct MicrophoneRestrictionError {
73    /// The original sender of the command
74    pub sender: ParticipantId,
75    /// The type of error that occurred
76    pub error: MicrophoneRestrictionErrorKind,
77}
78
79/// Participants were muted by a moderator
80#[derive(Debug)]
81pub struct ParticipantsMuted {
82    /// The moderator that sent the command
83    pub sender: Option<ParticipantId>,
84    /// The participants that were muted
85    pub participants: BTreeSet<ParticipantId>,
86}
87
88impl InternalCommand for LiveKitInternal {}