aboutsummaryrefslogtreecommitdiffstats
path: root/src/client/JsApi.hx
diff options
context:
space:
mode:
authorRblSb <msrblsb@gmail.com>2025-01-26 23:22:33 +0300
committerRblSb <msrblsb@gmail.com>2025-01-28 15:46:30 +0300
commit0592564264fff57ccfd9677957196951f9f1c6cf (patch)
treec360c2e5d45d9ac8706f836b0466b88221e1f10d /src/client/JsApi.hx
parentc7518e58788c17ad2ca8340ab5c7633489aa9518 (diff)
Video upload feature
And you can play video as soon as upload starts! This is pretty useful for thicc ones. Video will be keeped in cache and will comply cache size limit. I'm also implemented system storage check to change cache limit if it's lower than config value, so upload will be blocked if there is lower than 10MiB available on disk.
Diffstat (limited to 'src/client/JsApi.hx')
-rw-r--r--src/client/JsApi.hx24
1 files changed, 20 insertions, 4 deletions
diff --git a/src/client/JsApi.hx b/src/client/JsApi.hx
index defcc4d..b576b47 100644
--- a/src/client/JsApi.hx
+++ b/src/client/JsApi.hx
@@ -8,7 +8,7 @@ import js.Browser.window;
import js.Syntax;
private typedef VideoChangeFunc = (item:VideoItem) -> Void;
-private typedef OnceEventFunc = (event:WsEvent) -> Void;
+private typedef EventCallback = (event:WsEvent) -> Void;
class JsApi {
static var main:Main;
@@ -16,7 +16,8 @@ class JsApi {
static final subtitleFormats = [];
static final videoChange:Array<VideoChangeFunc> = [];
static final videoRemove:Array<VideoChangeFunc> = [];
- static final onceListeners:Array<{type:WsEventType, callback:OnceEventFunc}> = [];
+ static final onListeners:Array<{type:WsEventType, callback:EventCallback}> = [];
+ static final onceListeners:Array<{type:WsEventType, callback:EventCallback}> = [];
public static function init(main:Main, player:Player):Void {
JsApi.main = main;
@@ -147,11 +148,26 @@ class JsApi {
* `});`
*/
@:expose
- public static function once(type:WsEventType, callback:OnceEventFunc):Void {
+ public static function once(type:WsEventType, callback:EventCallback):Void {
onceListeners.unshift({type: type, callback: callback});
}
- public static function fireOnceEvent(event:WsEvent):Void {
+ public static function on(type:WsEventType, callback:EventCallback):Void {
+ onListeners.unshift({type: type, callback: callback});
+ }
+
+ public static function off(type:WsEventType, callback:EventCallback):Void {
+ final listener = onListeners.find(item -> {
+ return item.type == type && item.callback == callback;
+ });
+ onListeners.remove(listener);
+ }
+
+ public static function fireEvents(event:WsEvent):Void {
+ for (listener in onListeners.reversed()) {
+ if (listener.type != event.type) continue;
+ listener.callback(event);
+ }
for (listener in onceListeners.reversed()) {
if (listener.type != event.type) continue;
listener.callback(event);
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage