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 | |
| parent | 24f088dfa16b4e967d7315bddeadc844d388aee7 (diff) | |
External api test
| -rw-r--r-- | res/client.js | 39 | ||||
| -rw-r--r-- | src/client/JsApi.hx | 49 | ||||
| -rw-r--r-- | src/client/Player.hx | 1 |
3 files changed, 87 insertions, 2 deletions
diff --git a/res/client.js b/res/client.js index 89d0d81..186f01e 100644 --- a/res/client.js +++ b/res/client.js @@ -1,5 +1,7 @@ // Generated by Haxe 4.0.5 -(function ($global) { "use strict"; +(function ($hx_exports, $global) { "use strict"; +$hx_exports["client"] = $hx_exports["client"] || {}; +$hx_exports["client"]["JsApi"] = $hx_exports["client"]["JsApi"] || {}; var $estr = function() { return js_Boot.__string_rec(this,''); },$hxEnums = $hxEnums || {},$_; function $extend(from, fields) { var proto = Object.create(from); @@ -844,6 +846,37 @@ client_InputWithHistory.prototype = { } } }; +var client_JsApi = function() { }; +client_JsApi.__name__ = true; +client_JsApi.addPlugin = $hx_exports["client"]["JsApi"]["addPlugin"] = function(id,onLoaded) { + client_JsApi.addScriptToHead("/plugins/" + id + "/index.js",onLoaded); +}; +client_JsApi.addScriptToHead = $hx_exports["client"]["JsApi"]["addScriptToHead"] = function(url,onLoaded) { + var script = window.document.createElement("script"); + script.type = "text/javascript"; + script.onload = onLoaded; + script.src = url; + window.document.getElementsByTagName("head")[0].appendChild(script); +}; +client_JsApi.hasScriptInHead = $hx_exports["client"]["JsApi"]["hasScriptInHead"] = function(url) { + var _g = 0; + var _g1 = window.document.getElementsByTagName("head")[0].children; + while(_g < _g1.length) if(_g1[_g++].src == url) { + return true; + } + return false; +}; +client_JsApi.notifyOnVideoChange = $hx_exports["client"]["JsApi"]["notifyOnVideoChange"] = function(func) { + client_JsApi.videoChange.push(func); +}; +client_JsApi.removeFromVideoChange = $hx_exports["client"]["JsApi"]["removeFromVideoChange"] = function(func) { + HxOverrides.remove(client_JsApi.videoChange,func); +}; +client_JsApi.fireVideoChangeEvents = function(item) { + var _g = 0; + var _g1 = client_JsApi.videoChange; + while(_g < _g1.length) _g1[_g++](item); +}; var client_Main = function(host,port) { this.matchNumbers = new EReg("^-?[0-9]+$",""); this.mask = new EReg("\\${([0-9]+)-([0-9]+)}","g"); @@ -1685,6 +1718,7 @@ client_Player.prototype = { this.currentSrc = item.url; this.isLoaded = false; this.player.loadVideo(item); + client_JsApi.fireVideoChangeEvents(item); window.document.querySelector("#currenttitle").textContent = item.title; } ,removeVideo: function() { @@ -3135,7 +3169,8 @@ js_Boot.__toStr = ({ }).toString; Lang.langs = new haxe_ds_StringMap(); Lang.ids = ["en","ru"]; Lang.lang = HxOverrides.substr(window.navigator.language,0,2).toLowerCase(); +client_JsApi.videoChange = []; client_Settings.isSupported = false; js_youtube_Youtube.isLoadedAPI = false; client_Main.main(); -})(typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : this); +})(typeof exports != "undefined" ? exports : typeof window != "undefined" ? window : typeof self != "undefined" ? self : this, typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : this); 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; } |
