From 265b3e1fb56bb0e5f797b3b35227a616b108a0c3 Mon Sep 17 00:00:00 2001 From: RblSb Date: Sun, 6 Jun 2021 21:50:14 +0300 Subject: More JsApi methods getVideoItems/addVideoItem/removeVideoItem closes #24 --- src/client/JsApi.hx | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/client/JsApi.hx') diff --git a/src/client/JsApi.hx b/src/client/JsApi.hx index b97c0f0..a236570 100644 --- a/src/client/JsApi.hx +++ b/src/client/JsApi.hx @@ -65,6 +65,24 @@ class JsApi { return false; } + @:expose + static function getVideoItems():VideoList { + final items = player.getItems(); + return [ + for (item in items) Reflect.copy(item) + ]; + } + + @:expose + static function addVideoItem(url:String, atEnd:Bool, isTemp:Bool, ?callback:() -> Void):Void { + main.addVideo(url, atEnd, isTemp, callback); + } + + @:expose + static function removeVideoItem(url:String):Void { + main.removeVideoItem(url); + } + @:expose static function getTime():Float { return player.getTime(); @@ -102,6 +120,13 @@ class JsApi { return main.globalIp; } + /** + * If plugin adds any subtitle format (like `ass`), + * you will see subtitle input below video url input on client page. + * Plugins can listen to `notifyOnVideoChange(item => {...}` + * for raw videos and load that input data from `item.subs` url to do something. + * See `https://github.com/RblSb/SyncTube-octosubs` as example. + */ @:expose static function addSubtitleSupport(format:String):Void { format = format.trim().toLowerCase(); @@ -115,6 +140,13 @@ class JsApi { return subtitleFormats.contains(format); } + /** + * Listen to server event once before that event is parsed by client. + * Example: + * `JsApi.once("RemoveVideo", event => {` + * ` if (event.removeVideo.url == url) {...}` + * `});` + */ @:expose public static function once(type:WsEventType, func:OnceEventFunc):Void { onceListeners.push({type: type, func: func}); -- cgit v1.2.3