use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct AttachEvent {
#[serde(skip_serializing_if = "Option::is_none")]
pub session_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub client_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub width: Option<u16>,
#[serde(skip_serializing_if = "Option::is_none")]
pub height: Option<u16>,
}
impl AttachEvent {
#[must_use]
pub const fn new() -> Self {
Self {
session_id: None,
client_id: None,
width: None,
height: None,
}
}
#[must_use]
pub fn with_session(session_id: impl Into<String>) -> Self {
Self {
session_id: Some(session_id.into()),
client_id: None,
width: None,
height: None,
}
}
#[must_use]
pub const fn with_size(width: u16, height: u16) -> Self {
Self {
session_id: None,
client_id: None,
width: Some(width),
height: Some(height),
}
}
}
impl Default for AttachEvent {
fn default() -> Self {
Self::new()
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum DetachReason {
#[default]
Normal,
Disconnected,
SessionClosed,
Kicked,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct DetachEvent {
#[serde(default)]
pub reason: DetachReason,
#[serde(skip_serializing_if = "Option::is_none")]
pub message: Option<String>,
}
impl DetachEvent {
#[must_use]
pub const fn normal() -> Self {
Self {
reason: DetachReason::Normal,
message: None,
}
}
#[must_use]
pub const fn with_reason(reason: DetachReason) -> Self {
Self {
reason,
message: None,
}
}
#[must_use]
pub fn with_message(reason: DetachReason, message: impl Into<String>) -> Self {
Self {
reason,
message: Some(message.into()),
}
}
}
impl Default for DetachEvent {
fn default() -> Self {
Self::normal()
}
}
#[cfg(test)]
#[path = "session_tests.rs"]
mod tests;