From 40589f8e8ee75485ba241777f3b26cd35d8a05ea Mon Sep 17 00:00:00 2001 From: RblSb Date: Sat, 25 Apr 2020 02:03:49 +0300 Subject: VideoRemove api event --- res/client.js | 14 ++++++++++++++ src/client/JsApi.hx | 26 ++++++++++++++++++++------ src/client/Player.hx | 2 ++ 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/res/client.js b/res/client.js index 186f01e..2f9b418 100644 --- a/res/client.js +++ b/res/client.js @@ -877,6 +877,17 @@ client_JsApi.fireVideoChangeEvents = function(item) { var _g1 = client_JsApi.videoChange; while(_g < _g1.length) _g1[_g++](item); }; +client_JsApi.notifyOnVideoRemove = $hx_exports["client"]["JsApi"]["notifyOnVideoRemove"] = function(func) { + client_JsApi.videoRemove.push(func); +}; +client_JsApi.removeFromVideoRemove = $hx_exports["client"]["JsApi"]["removeFromVideoRemove"] = function(func) { + HxOverrides.remove(client_JsApi.videoRemove,func); +}; +client_JsApi.fireVideoRemoveEvents = function(item) { + var _g = 0; + var _g1 = client_JsApi.videoRemove; + 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"); @@ -1681,6 +1692,7 @@ client_Player.prototype = { } ,setPlayer: function(newPlayer) { if(this.player != null && this.player != newPlayer) { + client_JsApi.fireVideoRemoveEvents(this.items[this.itemPos]); this.player.removeVideo(); } this.player = newPlayer; @@ -1722,6 +1734,7 @@ client_Player.prototype = { window.document.querySelector("#currenttitle").textContent = item.title; } ,removeVideo: function() { + client_JsApi.fireVideoRemoveEvents(this.items[this.itemPos]); this.currentSrc = ""; this.player.removeVideo(); window.document.querySelector("#currenttitle").textContent = Lang.get("nothingPlaying"); @@ -3170,6 +3183,7 @@ Lang.langs = new haxe_ds_StringMap(); Lang.ids = ["en","ru"]; Lang.lang = HxOverrides.substr(window.navigator.language,0,2).toLowerCase(); client_JsApi.videoChange = []; +client_JsApi.videoRemove = []; client_Settings.isSupported = false; js_youtube_Youtube.isLoadedAPI = false; client_Main.main(); diff --git a/src/client/JsApi.hx b/src/client/JsApi.hx index 810e2f2..2df9c57 100644 --- a/src/client/JsApi.hx +++ b/src/client/JsApi.hx @@ -5,18 +5,18 @@ import js.Browser.document; private typedef VideoChangeFunc = (item:VideoItem)->Void; - class JsApi { static final videoChange:Array = []; + static final videoRemove:Array = []; @:expose - public static function addPlugin(id:String, ?onLoaded:()->Void):Void { + static function addPlugin(id:String, ?onLoaded:()->Void):Void { addScriptToHead('/plugins/$id/index.js', onLoaded); } @:expose - public static function addScriptToHead(url:String, ?onLoaded:()->Void):Void { + static function addScriptToHead(url:String, ?onLoaded:()->Void):Void { var script = document.createScriptElement(); script.type = "text/javascript"; script.onload = onLoaded; @@ -25,7 +25,7 @@ class JsApi { } @:expose - public static function hasScriptInHead(url:String):Bool { + static function hasScriptInHead(url:String):Bool { for (child in document.getElementsByTagName("head")[0].children) { if ((child : Dynamic).src == url) return true; } @@ -33,12 +33,12 @@ class JsApi { } @:expose - public static function notifyOnVideoChange(func:VideoChangeFunc):Void { + static function notifyOnVideoChange(func:VideoChangeFunc):Void { videoChange.push(func); } @:expose - public static function removeFromVideoChange(func:VideoChangeFunc):Void { + static function removeFromVideoChange(func:VideoChangeFunc):Void { videoChange.remove(func); } @@ -46,4 +46,18 @@ class JsApi { for (func in videoChange) func(item); } + @:expose + static function notifyOnVideoRemove(func:VideoChangeFunc):Void { + videoRemove.push(func); + } + + @:expose + static function removeFromVideoRemove(func:VideoChangeFunc):Void { + videoRemove.remove(func); + } + + public static function fireVideoRemoveEvents(item:VideoItem):Void { + for (func in videoRemove) func(item); + } + } diff --git a/src/client/Player.hx b/src/client/Player.hx index 780f8cc..d4ed854 100644 --- a/src/client/Player.hx +++ b/src/client/Player.hx @@ -90,6 +90,7 @@ class Player { function setPlayer(newPlayer:IPlayer):Void { if (player != null && player != newPlayer) { + JsApi.fireVideoRemoveEvents(items[itemPos]); player.removeVideo(); // playerEl.textContent = ""; } @@ -125,6 +126,7 @@ class Player { } public function removeVideo():Void { + JsApi.fireVideoRemoveEvents(items[itemPos]); currentSrc = ""; player.removeVideo(); ge("#currenttitle").textContent = Lang.get("nothingPlaying"); -- cgit v1.2.3