From 80ec4ba1747d22ec136a95d6b35ba6289e15e8ad Mon Sep 17 00:00:00 2001 From: RblSb Date: Sat, 6 Jun 2020 14:31:43 +0300 Subject: Once events api, improve pause hotkey --- src/client/JsApi.hx | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/client/JsApi.hx') 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 = []; static final videoRemove:Array = []; + static final onceListeners:Array<{type:WsEventType, func:OnceEventFunc}> = []; public static function init(main:Main, player:Player):Void { JsApi.main = main; @@ -84,6 +88,24 @@ class JsApi { player.changeVideoSrc(src); } + @: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); -- cgit v1.2.3