aboutsummaryrefslogtreecommitdiffstats
path: root/src/client/JsApi.hx
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/JsApi.hx')
-rw-r--r--src/client/JsApi.hx22
1 files changed, 22 insertions, 0 deletions
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);
}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage