2021-10-24 22:48:10 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
2022-02-13 17:23:20 +00:00
|
|
|
#[derive(Clone, Serialize, Deserialize)]
|
|
|
|
pub struct Viewer {
|
|
|
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
|
|
|
pub nickname: Option<String>,
|
|
|
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
|
|
|
pub colour: Option<String>,
|
|
|
|
}
|
|
|
|
|
2021-10-24 22:48:10 +00:00
|
|
|
#[derive(Clone, Serialize, Deserialize)]
|
|
|
|
#[serde(tag = "op", content = "data")]
|
2021-11-10 14:29:52 +00:00
|
|
|
pub enum WatchEventData {
|
2022-02-13 16:58:31 +00:00
|
|
|
SetPlaying {
|
|
|
|
playing: bool,
|
|
|
|
time: u64,
|
|
|
|
},
|
|
|
|
SetTime {
|
|
|
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
|
|
|
from: Option<u64>,
|
|
|
|
to: u64,
|
|
|
|
},
|
2021-10-25 01:59:52 +00:00
|
|
|
|
2021-11-10 14:29:52 +00:00
|
|
|
UserJoin,
|
|
|
|
UserLeave,
|
|
|
|
ChatMessage(String),
|
2022-02-13 16:58:31 +00:00
|
|
|
Ping(String),
|
2022-02-13 17:23:20 +00:00
|
|
|
UpdateViewerList(Vec<Viewer>),
|
2021-11-10 14:29:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Serialize, Deserialize)]
|
|
|
|
pub struct WatchEvent {
|
|
|
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
|
|
|
pub user: Option<String>,
|
2022-01-18 11:42:55 +00:00
|
|
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
|
|
|
pub colour: Option<String>,
|
2021-11-10 14:29:52 +00:00
|
|
|
#[serde(flatten)]
|
|
|
|
pub data: WatchEventData,
|
|
|
|
#[serde(default)]
|
|
|
|
pub reflected: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl WatchEvent {
|
2022-01-18 11:42:55 +00:00
|
|
|
pub fn new(user: String, colour: String, data: WatchEventData) -> Self {
|
2021-11-10 14:29:52 +00:00
|
|
|
WatchEvent {
|
|
|
|
user: Some(user),
|
2022-01-18 11:42:55 +00:00
|
|
|
colour: Some(colour),
|
2021-11-10 14:29:52 +00:00
|
|
|
data,
|
|
|
|
reflected: false,
|
|
|
|
}
|
|
|
|
}
|
2021-10-24 22:48:10 +00:00
|
|
|
}
|