aboutsummaryrefslogtreecommitdiffstats
path: root/src/client/Main.hx
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/Main.hx')
-rw-r--r--src/client/Main.hx28
1 files changed, 19 insertions, 9 deletions
diff --git a/src/client/Main.hx b/src/client/Main.hx
index c29604e..5631594 100644
--- a/src/client/Main.hx
+++ b/src/client/Main.hx
@@ -22,6 +22,7 @@ using ClientTools;
class Main {
public var isSyncActive = true;
+ public var synchThreshold(default, null) = 2;
final clients:Array<Client> = [];
var pageTitle = document.title;
final host:String;
@@ -32,7 +33,7 @@ class Main {
var isConnected = false;
var ws:WebSocket;
final player:Player;
- final onTimeGet = new Timer(2000);
+ var onTimeGet = new Timer(2000);
var onBlinkTab:Null<Timer>;
static function main():Void new Main();
@@ -46,11 +47,7 @@ class Main {
if (port == "") port = "80";
initListeners();
- onTimeGet.run = () -> {
- if (!isSyncActive) return;
- if (player.isListEmpty()) return;
- send({type: GetTime});
- }
+ onTimeGet.run = requestTime;
document.onvisibilitychange = () -> {
if (!document.hidden && onBlinkTab != null) {
document.title = getPageTitle();
@@ -63,6 +60,12 @@ class Main {
});
}
+ function requestTime():Void {
+ if (!isSyncActive) return;
+ if (player.isListEmpty()) return;
+ send({type: GetTime});
+ }
+
function openWebSocket(host:String, port:String):Void {
ws = new WebSocket('ws://$host:$port');
ws.onmessage = onMessage;
@@ -273,19 +276,19 @@ class Main {
if (isLeader()) {
// if video is loading on leader
// move other clients back in time
- if (Math.abs(time - newTime) < 2) return;
+ if (Math.abs(time - newTime) < synchThreshold) return;
player.setTime(time, false);
return;
}
if (!data.getTime.paused) player.play();
else player.pause();
- if (Math.abs(time - newTime) < 2) return;
+ if (Math.abs(time - newTime) < synchThreshold) return;
player.setTime(newTime);
case SetTime:
final newTime = data.setTime.time;
final time = player.getTime();
- if (Math.abs(time - newTime) < 2) return;
+ if (Math.abs(time - newTime) < synchThreshold) return;
player.setTime(newTime);
case Rewind:
@@ -589,6 +592,13 @@ class Main {
}
}
+ public function setSynchThreshold(s:Int):Void {
+ synchThreshold = s;
+ onTimeGet.stop();
+ onTimeGet = new Timer(s * 1000);
+ onTimeGet.run = requestTime;
+ }
+
function escapeRegExp(regex:String):String {
return ~/([.*+?^${}()|[\]\\])/g.replace(regex, "\\$1");
}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage