summaryrefslogtreecommitdiffstats
path: root/player/javascript
Commit message (Collapse)AuthorAgeFilesLines
* lua/js: mp.get_mouse_pos: use the mouse-pos propertyAvi Halachmi (:avih)2020-11-161-0/+1
| | | | | | | mp.get_mouse_pos() is undocumented and is no longer required - the property can be used officially by any client now, however, osc.lua uses it, and also some user scripts learnt to rely on it, so we keep it - as a trivial wrapper around the new mouse-pos property.
* js: hooks: allow deferred continuation (match d0ab562b)Avi Halachmi (:avih)2020-08-071-2/+9
| | | | | | | | | | The callback now gets an object argument with defer/cont functions. Like the lua code, the behavior is that each hook event allows at most one continue, but nothing enforces the order of continuations if more hook events arrive before prior ones were continued - which is possible now with the defer option, but wasn't possible before (continuation was synchronous from the hook event handler).
* js: mp.set_osd_ass: ignore identical inputs (match ccbb8b1c)Avi Halachmi (:avih)2020-05-101-0/+5
|
* js: osd-overlay update: return the command result (match 7a76b577)Avi Halachmi (:avih)2020-03-071-2/+1
| | | | Currently only useful for the new 'compute_bounds' command key.
* js: osd-overlay update: support arbitrary key namesAvi Halachmi (:avih)2020-03-071-9/+11
| | | | | | | | | | | | | | | | | | | | 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`.
* js: require: directory-scripts: first look at <dir>/modules/Avi Halachmi (:avih)2020-02-071-0/+3
| | | | | Also, add the function mp.get_script_directory() to let scripts know if they're loaded as a directory and where.
* js: require: don't use ~~/scripts/modules.js/Avi Halachmi (:avih)2020-02-071-1/+6
| | | | | | | | | Directories inside ~~/scripts/ are now loaded as scripts, so don't use it also for modules. Now there are no default module paths. To compensate, we now try to run ~~/.init.js right after defaults.js, so the user may extend the js init procedure via this script, e.g. for adding default paths to mp.module_paths .
* js: use osd-dimentions for mp.get_osd_{size,margins}Avi Halachmi (:avih)2020-01-081-4/+7
| | | | | | | | | | | This matches lua's 11b9315b but with the lagacy field names which the js code used previously. Currently the property always returns an object (with dummy/last/null field values if there are no dimensions), but the code is ready for a future case where it might return null if there are no dimensions - at which case it will forward the null, breaking backward compatibility for a better API.
* js: support mp.create_osd_overlay (match 07287262)Avi Halachmi (:avih)2019-12-231-0/+53
| | | | | The legacy mp.set_osd_ass(...) is still supported (but also still undocumented) as a wrapper for the new mp.create_osd_overlay(...).
* js: batch key bindings updates (match 96932fe7)Avi Halachmi (:avih)2019-12-231-3/+12
| | | | | | | Implemented using one-time idle observer (i.e. setTimeout), to avoid additional function call(back) every time the event loop enters idle. The lua mp.flush_key_bindings() is also available, also undocumented.
* js: read_options: on_update: don't re-read the config fileAvi Halachmi (:avih)2019-12-221-3/+3
| | | | | | | | | | | | | Now that 00af718a made the lua read_options behavior much more similar to the js behavior, the main difference was that lua does not re-read the config file at on_update (but it does re-apply its stored content) while js did re-read it. Now the js on_update also does not re-read the config file and instead applies its stored original content. This is slightly hacky by adding an undocumented optional 4th argument to read_options which allows overriding the config file content.
* js: read_options: support on_update (match 478a321d)Avi Halachmi (:avih)2019-12-211-2/+16
| | | | | | | | | | | | | This is a bit different than the lua code: on script-opts change it simply re-applies the conf-file and script-opts to the options object, and if this results in any changed value at options then on_update is called with the changelist as argument. This allows a value to revert back to the conf-file value if the matching script-opts key had a different value and then got deleted. It also guarantees to call back whenever the options object is modified, which the lua code doesn't do (e.g. if the caller changed a value and the observer changed it back - it won't detect a change).
* js: support shared script properties (match 7e4819e7)Avi Halachmi (:avih)2019-12-191-0/+22
|
* js: require: allow custom module search paths via mp.module_pathsAvi Halachmi (:avih)2019-12-191-4/+10
|
* js: mp.add_key_binding: allow false-y name (match 311cc5b)Avi Halachmi (:avih)2019-11-301-1/+3
| | | | | This is in addition to the allowed omission of name and/or flags (as documented).
* js: complex key binding: use key_name like the docs sayAvi Halachmi (:avih)2019-11-201-1/+1
|
* js: report key name for "complex" key bindings - match b08c8f50Avi Halachmi (:avih)2019-11-201-4/+5
|
* js: expose mpv_abort_async_command() (match dbe831bd)Avi Halachmi (:avih)2019-09-111-1/+14
| | | | With minor difference from lua, as documented.
* js: reimplement subprocess_detached using the run command (match 7f91e268)Avi Halachmi (:avih)2019-09-111-0/+5
|
* js: reimplement subprocess using the subprocess command (match 548ef078)Avi Halachmi (:avih)2019-09-111-0/+14
| | | | | | | | | Semantics changes are the same as at 548ef078 . Also, the previous C implementation returnd a string for the `stdout` value, but stdout of the subprocess command is MPV_FORMAT_BYTE_ARRAY which js previously didn't support, so support it too (at pushnode) by returning it as a string - the same as the lua code does.
* js: expose async commands (match 159379980e)Avi Halachmi (:avih)2019-09-111-1/+21
|
* js: use new hooks API (match f60826c3)Avi Halachmi (:avih)2018-04-071-10/+8
|
* js: dump(..): fix incorrect <VISITED> with array argumentAvi Halachmi (:avih)2018-04-071-1/+1
| | | | | | | | | | | | | | | | | | | | | When dump's argument is an array, it was displaying <VISITED> for all the array's object elements (objects, arrays, etc), regardless if they're actually visited or not. The reason is that we try to stringify twice: once normally which may throw (on cycles), and a second time while excluding visited items which is indicated by binding the replacer to an empty array - in which we hold the visited items, where the replacer tests if its 'this' is an array or not and acts accordingly. However, its "this" may also be an array even if we don't bind it to one, because its "normal" this is the main stringified object, so the test of Array.isArray(this) is true when the top object is an array, and the object items are indeed are in it - so the replacer considers them visited. Fix by binding to null on the first attempt such that "this" is an array only when we want it to test for visited items and not when the argument itself is an array.
* js: implement mp.register_idleAvi Halachmi (:avih)2018-04-071-2/+37
| | | | | | | | | | Due to earlier misinterpretation of the Lua docs as if mp.register_idle registers a one-shot callback, the JS docs suggested to use setTimeout. But the behavior and Lua docs are such that it's a repeating callback which fires just before the script thread goes to sleep. Implement it for JS too.
* js: implement mp.options.read_optionsAvi Halachmi (:avih)2018-04-071-0/+52
|
* js: implement mp.msg.trace()TheAMM2017-12-161-1/+1
| | | | | | | To match the new Lua helper introduced in 1afdeee1ad8bca1c703e741002fa3b882d162968 Add documentation for both.
* js: add javascript scripting support using MuJSAvi Halachmi (:avih)2017-06-141-0/+495
Implements JS with almost identical API to the Lua support. Key differences from Lua: - The global mp, mp.msg and mp.utils are always available. - Instead of returning x, error, return x and expose mp.last_error(). - Timers are JS standard set/clear Timeout/Interval. - Supports CommonJS modules/require. - Added at mp.utils: getenv, read_file, write_file and few more. - Global print and dump (expand objects) functions. - mp.options currently not supported. See DOCS/man/javascript.rst for more details.