Skip to main content

opentalk_roomserver_types_ping/
command.rs

1// SPDX-License-Identifier: EUPL-1.2
2// SPDX-FileCopyrightText: OpenTalk Team <mail@opentalk.eu>
3
4use std::time::Duration;
5
6use opentalk_roomserver_signaling::signaling_module::CreateReplica;
7use serde::{Deserialize, Serialize};
8
9use crate::event::{PingEvent, Replication};
10
11#[derive(Deserialize, Serialize, Debug)]
12#[serde(tag = "action", rename_all = "snake_case")]
13pub enum PingCommand {
14    /// A normal ping
15    Ping,
16    /// A ping with delayed response
17    AsyncDelayedPing {
18        /// The duration that the pong is delayed for.
19        #[serde(with = "opentalk_types_common::utils::duration_seconds")]
20        delay: Duration,
21    },
22    /// Request the ping module to die by returning a
23    /// [`FatalError`](opentalk_roomserver_types::signaling::module_error::FatalError)
24    Die,
25    /// A ping where the command gets replicated
26    ReplicatedPing,
27}
28
29impl CreateReplica<PingEvent> for PingCommand {
30    fn replicate(&self) -> Option<PingEvent> {
31        match self {
32            PingCommand::ReplicatedPing => {
33                Some(PingEvent::Replication(Replication::ReplicatedPing))
34            }
35            _ => None,
36        }
37    }
38}