diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Types.hx | 1 | ||||
| -rw-r--r-- | src/client/Main.hx | 4 | ||||
| -rw-r--r-- | src/server/Main.hx | 39 | ||||
| -rw-r--r-- | src/server/VideoTimer.hx | 2 |
4 files changed, 45 insertions, 1 deletions
diff --git a/src/Types.hx b/src/Types.hx index c2136b4..6a15bba 100644 --- a/src/Types.hx +++ b/src/Types.hx @@ -215,6 +215,7 @@ enum abstract WsEventType(String) { var SetTime; var SetRate; var Rewind; + var Flashback; var SetLeader; var PlayItem; var SetNextItem; diff --git a/src/client/Main.hx b/src/client/Main.hx index 57a2d0f..28fefe8 100644 --- a/src/client/Main.hx +++ b/src/client/Main.hx @@ -500,6 +500,7 @@ class Main { case Rewind: player.setTime(data.rewind.time); + case Flashback: // server-only case SetLeader: clients.setLeader(data.setLeader.clientName); updateUserList(); @@ -858,6 +859,9 @@ class Main { case "clear": send({type: ClearChat}); return true; + case "flashback", "fb": + send({type: Flashback}); + return false; } if (matchSimpleDate.match(command)) { send({ diff --git a/src/server/Main.hx b/src/server/Main.hx index 2f3a8a4..42abaa9 100644 --- a/src/server/Main.hx +++ b/src/server/Main.hx @@ -27,6 +27,7 @@ using StringTools; class Main { static inline var VIDEO_START_MAX_DELAY = 3000; static inline var VIDEO_SKIP_DELAY = 1000; + static inline var FLASHBACK_DIST = 30; final rootDir = '$__dirname/..'; @@ -379,9 +380,11 @@ class Main { function noTypeObj(data:WsEvent):Bool { if (data.type == GetTime) return false; + if (data.type == Flashback) return false; if (data.type == TogglePlaylistLock) return false; if (data.type == UpdatePlaylist) return false; if (data.type == Logout) return false; + // check if request has same field as type value final t:String = cast data.type; final t = t.charAt(0).toLowerCase() + t.substr(1); return js.Syntax.strictEq(Reflect.field(data, t), null); @@ -600,6 +603,9 @@ class Main { case Pause: if (videoList.length == 0) return; if (!client.isLeader) return; + if (Math.abs(data.pause.time - videoTimer.getTime()) > FLASHBACK_DIST) { + saveFlashbackTime(); + } videoTimer.setTime(data.pause.time); videoTimer.pause(); broadcast(data); @@ -607,6 +613,9 @@ class Main { case Play: if (videoList.length == 0) return; if (!client.isLeader) return; + if (Math.abs(data.play.time - videoTimer.getTime()) > FLASHBACK_DIST) { + saveFlashbackTime(); + } videoTimer.setTime(data.play.time); videoTimer.play(); broadcast(data); @@ -647,6 +656,9 @@ class Main { case SetTime: if (videoList.length == 0) return; if (!client.isLeader) return; + if (Math.abs(data.setTime.time - videoTimer.getTime()) > FLASHBACK_DIST) { + saveFlashbackTime(); + } videoTimer.setTime(data.setTime.time); broadcastExcept(client, data); @@ -661,9 +673,21 @@ class Main { if (videoList.length == 0) return; data.rewind.time += videoTimer.getTime(); if (data.rewind.time < 0) data.rewind.time = 0; + saveFlashbackTime(); videoTimer.setTime(data.rewind.time); broadcast(data); + case Flashback: + if (!checkPermission(client, RewindPerm)) return; + if (videoList.length == 0) return; + loadFlashbackTime(); + broadcast({ + type: Rewind, + rewind: { + time: videoTimer.getTime() + } + }); + case SetLeader: final clientName = data.setLeader.clientName; if (client.name == clientName) { @@ -864,6 +888,7 @@ class Main { var loadedClientsCount = 0; function restartWaitTimer():Void { + if (videoTimer.getTime() > FLASHBACK_DIST) saveFlashbackTime(); videoTimer.stop(); if (waitVideoStart != null) waitVideoStart.stop(); waitVideoStart = Timer.delay(startVideoPlayback, VIDEO_START_MAX_DELAY); @@ -882,4 +907,18 @@ class Main { broadcast({type: VideoLoaded}); videoTimer.start(); } + + var flashbackTime = 0.0; + + function saveFlashbackTime() { + final time = videoTimer.getTime(); + if (Math.abs(flashbackTime - time) < FLASHBACK_DIST) return; + flashbackTime = time; + } + + function loadFlashbackTime() { + final time = videoTimer.getTime(); + videoTimer.setTime(flashbackTime); + flashbackTime = time; + } } diff --git a/src/server/VideoTimer.hx b/src/server/VideoTimer.hx index 2dd6720..fcbb461 100644 --- a/src/server/VideoTimer.hx +++ b/src/server/VideoTimer.hx @@ -34,8 +34,8 @@ class VideoTimer { public function play():Void { if (!isStarted) start(); startTime += pauseTime(); - rateStartTime = stamp(); pauseStartTime = 0; + rateStartTime = stamp(); } public function getTime():Float { |
