diff options
| author | RblSb <msrblsb@gmail.com> | 2020-04-24 20:37:43 +0300 |
|---|---|---|
| committer | RblSb <msrblsb@gmail.com> | 2020-04-24 20:37:43 +0300 |
| commit | ec15079f99724cc0ad40f550687fcca2735c9afc (patch) | |
| tree | 3bae1b4c57138381591b02ea49de3c226d76c91f /src/client | |
| parent | 24f088dfa16b4e967d7315bddeadc844d388aee7 (diff) | |
External api test
Diffstat (limited to 'src/client')
| -rw-r--r-- | src/client/JsApi.hx | 49 | ||||
| -rw-r--r-- | src/client/Player.hx | 1 |
2 files changed, 50 insertions, 0 deletions
diff --git a/src/client/JsApi.hx b/src/client/JsApi.hx new file mode 100644 index 0000000..810e2f2 --- /dev/null +++ b/src/client/JsApi.hx @@ -0,0 +1,49 @@ +package client; + +import Types.VideoItem; +import js.Browser.document; + +private typedef VideoChangeFunc = (item:VideoItem)->Void; + + +class JsApi { + + static final videoChange:Array<VideoChangeFunc> = []; + + @:expose + public static function addPlugin(id:String, ?onLoaded:()->Void):Void { + addScriptToHead('/plugins/$id/index.js', onLoaded); + } + + @:expose + public static function addScriptToHead(url:String, ?onLoaded:()->Void):Void { + var script = document.createScriptElement(); + script.type = "text/javascript"; + script.onload = onLoaded; + script.src = url; + document.getElementsByTagName("head")[0].appendChild(script); + } + + @:expose + public static function hasScriptInHead(url:String):Bool { + for (child in document.getElementsByTagName("head")[0].children) { + if ((child : Dynamic).src == url) return true; + } + return false; + } + + @:expose + public static function notifyOnVideoChange(func:VideoChangeFunc):Void { + videoChange.push(func); + } + + @:expose + public static function removeFromVideoChange(func:VideoChangeFunc):Void { + videoChange.remove(func); + } + + public static function fireVideoChangeEvents(item:VideoItem):Void { + for (func in videoChange) func(item); + } + +} diff --git a/src/client/Player.hx b/src/client/Player.hx index 92cee1c..780f8cc 100644 --- a/src/client/Player.hx +++ b/src/client/Player.hx @@ -120,6 +120,7 @@ class Player { currentSrc = item.url; isLoaded = false; player.loadVideo(item); + JsApi.fireVideoChangeEvents(item); ge("#currenttitle").textContent = item.title; } |
