aboutsummaryrefslogtreecommitdiffstats
path: root/src/client
diff options
context:
space:
mode:
authorRblSb <msrblsb@gmail.com>2020-06-06 14:31:43 +0300
committerRblSb <msrblsb@gmail.com>2020-06-06 14:31:43 +0300
commit80ec4ba1747d22ec136a95d6b35ba6289e15e8ad (patch)
treebb34c1871538085084ba3f703d4dc6e61661fb62 /src/client
parent41e8165d3d701562af4eb78d86816fd1f88766af (diff)
Once events api, improve pause hotkey
Diffstat (limited to 'src/client')
-rw-r--r--src/client/Buttons.hx5
-rw-r--r--src/client/JsApi.hx22
-rw-r--r--src/client/Main.hx5
3 files changed, 31 insertions, 1 deletions
diff --git a/src/client/Buttons.hx b/src/client/Buttons.hx
index 771f827..5eb1baf 100644
--- a/src/client/Buttons.hx
+++ b/src/client/Buttons.hx
@@ -273,7 +273,10 @@ class Buttons {
case L: ge("#leader_btn").onclick();
case P:
if (!main.isLeader()) {
- Timer.delay(() -> player.pause(), 500);
+ JsApi.once(SetLeader, event -> {
+ final name = event.setLeader.clientName;
+ if (name == main.getName()) player.pause();
+ });
}
ge("#leader_btn").onclick();
default: return;
diff --git a/src/client/JsApi.hx b/src/client/JsApi.hx
index 7528f42..66d0516 100644
--- a/src/client/JsApi.hx
+++ b/src/client/JsApi.hx
@@ -1,11 +1,14 @@
package client;
+import Types.WsEventType;
+import Types.WsEvent;
import Types.VideoItem;
import js.Browser.document;
import js.Browser.window;
import js.Syntax;
private typedef VideoChangeFunc = (item:VideoItem)->Void;
+private typedef OnceEventFunc = (event:WsEvent)->Void;
class JsApi {
@@ -13,6 +16,7 @@ class JsApi {
static var player:Player;
static final videoChange:Array<VideoChangeFunc> = [];
static final videoRemove:Array<VideoChangeFunc> = [];
+ static final onceListeners:Array<{type:WsEventType, func:OnceEventFunc}> = [];
public static function init(main:Main, player:Player):Void {
JsApi.main = main;
@@ -85,6 +89,24 @@ class JsApi {
}
@:expose
+ public static function once(type:WsEventType, func:OnceEventFunc):Void {
+ onceListeners.push({type: type, func: func});
+ }
+
+ public static function fireOnceEvent(event:WsEvent):Void {
+ var i = 0;
+ while (i < onceListeners.length) {
+ final listener = onceListeners[i];
+ if (listener.type == event.type) {
+ listener.func(event);
+ onceListeners.remove(listener);
+ continue;
+ }
+ i++;
+ }
+ }
+
+ @:expose
static function notifyOnVideoChange(func:VideoChangeFunc):Void {
videoChange.push(func);
}
diff --git a/src/client/Main.hx b/src/client/Main.hx
index 0f6b31e..1cf4b04 100644
--- a/src/client/Main.hx
+++ b/src/client/Main.hx
@@ -178,6 +178,10 @@ class Main {
return personal.isAdmin;
}
+ public inline function getName():String {
+ return personal.name;
+ }
+
final mask = ~/\${([0-9]+)-([0-9]+)}/g;
function handleUrlMasks(links:Array<String>):Void {
@@ -325,6 +329,7 @@ class Main {
final t = t.charAt(0).toLowerCase() + t.substr(1);
trace('Event: ${data.type}', Reflect.field(data, t));
}
+ JsApi.fireOnceEvent(data);
switch (data.type) {
case Connected:
onConnected(data);
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage