2025-04-14 16:13:42 +03:00
|
|
|
use std::fmt::Display;
|
|
|
|
|
2025-04-11 04:58:16 +03:00
|
|
|
use chrono::{DateTime, Utc};
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
2025-04-14 04:58:44 +03:00
|
|
|
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
|
2025-04-14 16:13:42 +03:00
|
|
|
pub enum Error {
|
|
|
|
SignalType(SignalType),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl std::error::Error for Error {
|
|
|
|
fn cause(&self) -> Option<&dyn std::error::Error> {
|
|
|
|
self.source()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Display for Error {
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
match self {
|
|
|
|
Error::SignalType(signal_type) => {
|
|
|
|
write!(f, "Not Expected Signal Type: {}", signal_type)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
2025-04-14 04:58:44 +03:00
|
|
|
pub enum SignalType {
|
|
|
|
Auth,
|
|
|
|
Offer,
|
|
|
|
Answer,
|
2025-04-11 04:58:16 +03:00
|
|
|
}
|
2025-04-13 04:55:33 +03:00
|
|
|
|
2025-04-14 04:58:44 +03:00
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
pub struct Signal {
|
2025-04-14 16:13:42 +03:00
|
|
|
signal_type: SignalType,
|
|
|
|
data: String,
|
2025-04-14 04:58:44 +03:00
|
|
|
time: DateTime<Utc>,
|
2025-04-13 04:55:33 +03:00
|
|
|
}
|
2025-04-14 04:58:44 +03:00
|
|
|
|
2025-04-14 16:13:42 +03:00
|
|
|
impl Display for SignalType {
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
match self {
|
|
|
|
SignalType::Auth => write!(f, "Auth"),
|
|
|
|
SignalType::Offer => write!(f, "Offer"),
|
|
|
|
SignalType::Answer => write!(f, "Answer"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-04-14 04:58:44 +03:00
|
|
|
impl Signal {
|
2025-04-14 16:13:42 +03:00
|
|
|
pub fn new(signal_type: &SignalType, data: &String) -> Signal {
|
2025-04-14 04:58:44 +03:00
|
|
|
let signal_type = *signal_type;
|
|
|
|
let data = data.to_owned();
|
|
|
|
Signal {
|
|
|
|
signal_type,
|
|
|
|
data,
|
|
|
|
time: DateTime::default(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-04-14 16:13:42 +03:00
|
|
|
pub fn get_signal_type(&self) -> SignalType {
|
|
|
|
self.signal_type
|
|
|
|
}
|
|
|
|
pub fn get_data(&self) -> String {
|
|
|
|
self.data.to_owned()
|
|
|
|
}
|
2025-04-14 04:58:44 +03:00
|
|
|
pub fn get_time(&self) -> DateTime<Utc> {
|
|
|
|
self.time
|
|
|
|
}
|
2025-04-13 04:55:33 +03:00
|
|
|
}
|