aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRblSb <msrblsb@gmail.com>2021-06-06 21:50:14 +0300
committerRblSb <msrblsb@gmail.com>2021-06-06 21:50:14 +0300
commit265b3e1fb56bb0e5f797b3b35227a616b108a0c3 (patch)
treead3fbf3bfddeca1c51813f6667f0181a69dfe4fe
parent13127249ddd1f61f8ed6b75803b0de1f4d25f96e (diff)
More JsApi methods
getVideoItems/addVideoItem/removeVideoItem closes #24
-rw-r--r--res/client.js38
-rw-r--r--src/client/JsApi.hx32
-rw-r--r--src/client/Main.hx12
-rw-r--r--src/client/Player.hx6
4 files changed, 78 insertions, 10 deletions
diff --git a/res/client.js b/res/client.js
index 692b833..b1891da 100644
--- a/res/client.js
+++ b/res/client.js
@@ -265,6 +265,20 @@ Reflect.compareMethods = function(f1,f2) {
return false;
}
};
+Reflect.copy = function(o) {
+ if(o == null) {
+ return null;
+ }
+ var o2 = { };
+ var _g = 0;
+ var _g1 = Reflect.fields(o);
+ while(_g < _g1.length) {
+ var f = _g1[_g];
+ ++_g;
+ o2[f] = Reflect.field(o,f);
+ }
+ return o2;
+};
var Std = function() { };
Std.__name__ = true;
Std.string = function(s) {
@@ -931,6 +945,19 @@ client_JsApi.hasScriptInHead = $hx_exports["client"]["JsApi"]["hasScriptInHead"]
}
return false;
};
+client_JsApi.getVideoItems = $hx_exports["client"]["JsApi"]["getVideoItems"] = function() {
+ var _g = [];
+ var _g1 = 0;
+ var _g2 = client_JsApi.player.getItems();
+ while(_g1 < _g2.length) _g.push(Reflect.copy(_g2[_g1++]));
+ return _g;
+};
+client_JsApi.addVideoItem = $hx_exports["client"]["JsApi"]["addVideoItem"] = function(url,atEnd,isTemp,callback) {
+ client_JsApi.main.addVideo(url,atEnd,isTemp,callback);
+};
+client_JsApi.removeVideoItem = $hx_exports["client"]["JsApi"]["removeVideoItem"] = function(url) {
+ client_JsApi.main.removeVideoItem(url);
+};
client_JsApi.getTime = $hx_exports["client"]["JsApi"]["getTime"] = function() {
return client_JsApi.player.getTime();
};
@@ -1233,7 +1260,9 @@ client_Main.prototype = {
data.url = url;
}
_gthis.send({ type : "AddVideo", addVideo : { item : { url : data.url, title : data.title, author : _gthis.personal.name, duration : data.duration, isTemp : isTemp, subs : data.subs, isIframe : data.isIframe == true}, atEnd : atEnd}});
- callback();
+ if(callback != null) {
+ callback();
+ }
});
}
,addIframe: function(atEnd) {
@@ -1265,6 +1294,9 @@ client_Main.prototype = {
_gthis.send({ type : "AddVideo", addVideo : { item : { url : data.url, title : data.title, author : _gthis.personal.name, duration : data.duration, isTemp : isTemp, isIframe : true}, atEnd : atEnd}});
});
}
+ ,removeVideoItem: function(url) {
+ this.send({ type : "RemoveVideo", removeVideo : { url : url}});
+ }
,toggleVideoElement: function() {
if(this.player.hasVideo()) {
this.player.removeVideo();
@@ -1296,7 +1328,7 @@ client_Main.prototype = {
var data = JSON.parse(e.data);
if(this.config != null && this.config.isVerbose) {
var t = data.type;
- haxe_Log.trace("Event: " + data.type,{ fileName : "src/client/Main.hx", lineNumber : 352, className : "client.Main", methodName : "onMessage", customParams : [Reflect.field(data,t.charAt(0).toLowerCase() + HxOverrides.substr(t,1,null))]});
+ haxe_Log.trace("Event: " + data.type,{ fileName : "src/client/Main.hx", lineNumber : 360, className : "client.Main", methodName : "onMessage", customParams : [Reflect.field(data,t.charAt(0).toLowerCase() + HxOverrides.substr(t,1,null))]});
}
client_JsApi.fireOnceEvent(data);
switch(data.type) {
@@ -1898,7 +1930,7 @@ client_Player.prototype = {
_gthis.main.send({ type : "ToggleItemType", toggleItemType : { pos : i}});
}
if(btn.classList.contains("qbtn-delete")) {
- _gthis.main.send({ type : "RemoveVideo", removeVideo : { url : item.querySelector(".qe_title").getAttribute("href")}});
+ _gthis.main.removeVideoItem(item.querySelector(".qe_title").getAttribute("href"));
}
};
}
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
@@ -66,6 +66,24 @@ class JsApi {
}
@: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});
diff --git a/src/client/Main.hx b/src/client/Main.hx
index b9c9892..1d9ac34 100644
--- a/src/client/Main.hx
+++ b/src/client/Main.hx
@@ -242,7 +242,7 @@ class Main {
addVideo(link, atEnd, isTemp, () -> addVideoArray(links, atEnd, isTemp));
}
- function addVideo(url:String, atEnd:Bool, isTemp:Bool, callback:()->Void):Void {
+ public function addVideo(url:String, atEnd:Bool, isTemp:Bool, ?callback:()->Void):Void {
final protocol = Browser.location.protocol;
if (url.startsWith("/")) {
final host = Browser.location.hostname;
@@ -275,7 +275,7 @@ class Main {
},
atEnd: atEnd
}});
- callback();
+ if (callback != null) callback();
});
}
@@ -316,6 +316,14 @@ class Main {
});
}
+ public function removeVideoItem(url:String) {
+ send({
+ type: RemoveVideo, removeVideo: {
+ url: url
+ }
+ });
+ }
+
public function toggleVideoElement():Bool {
if (player.hasVideo()) player.removeVideo();
else if (!player.isListEmpty()) {
diff --git a/src/client/Player.hx b/src/client/Player.hx
index 735f73c..c9b379c 100644
--- a/src/client/Player.hx
+++ b/src/client/Player.hx
@@ -64,11 +64,7 @@ class Player {
});
}
if (btn.classList.contains("qbtn-delete")) {
- main.send({
- type: RemoveVideo, removeVideo: {
- url: item.querySelector(".qe_title").getAttribute("href")
- }
- });
+ main.removeVideoItem(item.querySelector(".qe_title").getAttribute("href"));
}
}
}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage