diff --git a/frontend/lib/chat.mjs b/frontend/lib/chat.mjs index 777783f..52ca8bf 100644 --- a/frontend/lib/chat.mjs +++ b/frontend/lib/chat.mjs @@ -200,10 +200,22 @@ export const logEventToChat = (event) => { } case "SetTime": { const messageContent = document.createElement("span"); - messageContent.appendChild(document.createTextNode("set the time to ")); + if (event.data.from != undefined) { + messageContent.appendChild( + document.createTextNode("set the time from ") + ); + + messageContent.appendChild( + document.createTextNode(formatTime(event.data.from)) + ); + + messageContent.appendChild(document.createTextNode(" to ")); + } else { + messageContent.appendChild(document.createTextNode("set the time to ")); + } messageContent.appendChild( - document.createTextNode(formatTime(event.data)) + document.createTextNode(formatTime(event.data.to)) ); printChatMessage("set-time", event.user, event.colour, messageContent); @@ -246,12 +258,12 @@ const beep = () => { const gain = context.createGain(); gain.connect(context.destination); gain.gain.value = 0.1; - + const oscillator = context.createOscillator(); oscillator.connect(gain); oscillator.frequency.value = 520; oscillator.type = "square"; - + oscillator.start(context.currentTime); oscillator.stop(context.currentTime + 0.22); }; diff --git a/frontend/lib/watch-session.mjs b/frontend/lib/watch-session.mjs index bb771bb..680ce66 100644 --- a/frontend/lib/watch-session.mjs +++ b/frontend/lib/watch-session.mjs @@ -137,7 +137,9 @@ const setupOutgoingEvents = (video, socket) => { socket.send( JSON.stringify({ op: "SetTime", - data: currentVideoTime(), + data: { + to: currentVideoTime(), + }, }) ); }); diff --git a/src/events.rs b/src/events.rs index d8adda7..faa7c2e 100644 --- a/src/events.rs +++ b/src/events.rs @@ -3,13 +3,20 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Serialize, Deserialize)] #[serde(tag = "op", content = "data")] pub enum WatchEventData { - SetPlaying { playing: bool, time: u64 }, - SetTime(u64), + SetPlaying { + playing: bool, + time: u64, + }, + SetTime { + #[serde(default, skip_serializing_if = "Option::is_none")] + from: Option, + to: u64, + }, UserJoin, UserLeave, ChatMessage(String), - Ping(String) + Ping(String), } #[derive(Clone, Serialize, Deserialize)] diff --git a/src/viewer_connection.rs b/src/viewer_connection.rs index 30fa9ed..00c1113 100644 --- a/src/viewer_connection.rs +++ b/src/viewer_connection.rs @@ -84,11 +84,18 @@ pub async fn ws_subscribe(session_uuid: Uuid, nickname: String, colour: String, None => continue, }; - handle_watch_event_data( - session_uuid, - &mut get_session(session_uuid).unwrap(), - event.clone(), - ); + let session = &mut get_session(session_uuid).unwrap(); + + // server side event modification where neccessary + let event: WatchEventData = match event { + WatchEventData::SetTime { from: _, to } => WatchEventData::SetTime { + from: Some(session.get_time_ms()), + to: to, + }, + _ => event, + }; + + handle_watch_event_data(session_uuid, session, event.clone()); ws_publish( session_uuid, diff --git a/src/watch_session.rs b/src/watch_session.rs index 56b6634..cda42c5 100644 --- a/src/watch_session.rs +++ b/src/watch_session.rs @@ -85,8 +85,8 @@ pub fn handle_watch_event_data( watch_session.set_playing(playing, time); } - WatchEventData::SetTime(time) => { - watch_session.set_time_ms(time); + WatchEventData::SetTime { from: _, to } => { + watch_session.set_time_ms(to); } _ => {}