aboutsummaryrefslogtreecommitdiffstats
path: root/src/server
diff options
context:
space:
mode:
authorRblSb <msrblsb@gmail.com>2021-08-15 13:40:01 +0300
committerRblSb <msrblsb@gmail.com>2021-08-15 13:44:32 +0300
commitf2d28c726ba46f03716ed37667d0e94c60ad3459 (patch)
treed13d389f005cbb5ba5b5f46da05bbacf5801fbbb /src/server
parent5b908e914ebfeedb2895f5de1b9167a6ce12c136 (diff)
Add /flashback (/fb)
Diffstat (limited to 'src/server')
-rw-r--r--src/server/Main.hx39
-rw-r--r--src/server/VideoTimer.hx2
2 files changed, 40 insertions, 1 deletions
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 {
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage