diff options
| author | RblSb <msrblsb@gmail.com> | 2020-06-06 14:31:43 +0300 |
|---|---|---|
| committer | RblSb <msrblsb@gmail.com> | 2020-06-06 14:31:43 +0300 |
| commit | 80ec4ba1747d22ec136a95d6b35ba6289e15e8ad (patch) | |
| tree | bb34c1871538085084ba3f703d4dc6e61661fb62 /src/client/JsApi.hx | |
| parent | 41e8165d3d701562af4eb78d86816fd1f88766af (diff) | |
Once events api, improve pause hotkey
Diffstat (limited to 'src/client/JsApi.hx')
| -rw-r--r-- | src/client/JsApi.hx | 22 |
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); } |
