2021-10-24 22:48:10 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
|
|
|
#[derive(Clone, Serialize, Deserialize)]
|
|
|
|
#[serde(tag = "op", content = "data")]
|
2021-11-10 14:29:52 +00:00
|
|
|
pub enum WatchEventData {
|
|
|
|
SetPlaying { playing: bool, time: u64 },
|
2021-10-24 22:48:10 +00:00
|
|
|
SetTime(u64),
|
2021-10-25 01:59:52 +00:00
|
|
|
|
2021-11-10 14:29:52 +00:00
|
|
|
UserJoin,
|
|
|
|
UserLeave,
|
|
|
|
ChatMessage(String),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Serialize, Deserialize)]
|
|
|
|
pub struct WatchEvent {
|
|
|
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
|
|
|
pub user: Option<String>,
|
|
|
|
#[serde(flatten)]
|
|
|
|
pub data: WatchEventData,
|
|
|
|
#[serde(default)]
|
|
|
|
pub reflected: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl WatchEvent {
|
|
|
|
pub fn new(user: String, data: WatchEventData) -> Self {
|
|
|
|
WatchEvent {
|
|
|
|
user: Some(user),
|
|
|
|
data,
|
|
|
|
reflected: false,
|
|
|
|
}
|
|
|
|
}
|
2021-10-24 22:48:10 +00:00
|
|
|
}
|