summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAvi Halachmi (:avih) <avihpit@yahoo.com>2020-03-07 12:00:33 +0200
committerAvi Halachmi (:avih) <avihpit@yahoo.com>2020-03-07 12:37:35 +0200
commit9cf45d8300b4e89927e61af9e4a9381cc3d75078 (patch)
tree6a1e6e3bb43af4c5b011b2bb2a427a25b7318882
parentba70b150fbe89c00e4ef7dcb975ec695b49dac8d (diff)
downloadmpv-9cf45d8300b4e89927e61af9e4a9381cc3d75078.tar.bz2
mpv-9cf45d8300b4e89927e61af9e4a9381cc3d75078.tar.xz
js: osd-overlay update: support arbitrary key names
Until now the 'update' method used mp.command_native with a hardcoded list of key names. Change it to use whatever keys the user set to this object, so that we can remain oblivious to new keys which 'osd-overlay' may support. This is how the lua code did it from the begining. We didn't, and now we pay the price. Note: could be implemented either as we have now (clone `this` excluding the methods) or by moving the methods up the prototype chain (i.e. class methods) so they don't get enumerated and use `this` as the command object itself. However, in the latter approach we'll have to save the values which we change (name, res_x, res_y) and restore them after the command, so it's simpler to just clone `this`.
-rw-r--r--player/javascript/defaults.js20
1 files changed, 11 insertions, 9 deletions
diff --git a/player/javascript/defaults.js b/player/javascript/defaults.js
index dcea6734a0..31f944727d 100644
--- a/player/javascript/defaults.js
+++ b/player/javascript/defaults.js
@@ -204,15 +204,17 @@ mp.create_osd_overlay = function create_osd_overlay(format) {
z: 0,
update: function ass_update() {
- mp.command_native({
- name: "osd-overlay",
- format: this.format,
- id: this.id,
- data: this.data,
- res_x: Math.round(this.res_x),
- res_y: Math.round(this.res_y),
- z: this.z,
- });
+ var cmd = {}; // shallow clone of `this', excluding methods
+ for (var k in this) {
+ if (typeof this[k] != "function")
+ cmd[k] = this[k];
+ }
+
+ cmd.name = "osd-overlay";
+ cmd.res_x = Math.round(this.res_x);
+ cmd.res_y = Math.round(this.res_y);
+
+ mp.command_native(cmd);
return mp.last_error() ? undefined : true;
},