History

js: expose async commands (match 159379980e)

Avi Halachmi (:avih) committed 7 years ago

Commit 5b5f7761 parent fc567983 files · +42 −2Browse files

Showing the changes to player/javascript (1 of 3 files). Show all

Unified · Split

player/javascript/defaults.js+21−1
@@ -17,7 +17,7 @@ function new_cache() { · 16 unmodified lines
17}17}
18 18
19/**********************************************************************19/**********************************************************************
20 * event handlers, property observers, idle, client messages, hooks20 * event handlers, property observers, idle, client messages, hooks, async
21 *********************************************************************/21 *********************************************************************/
22var ehandlers = new_cache() // items of event-name: array of {maybe cb: fn}22var ehandlers = new_cache() // items of event-name: array of {maybe cb: fn}
23 23
@@ -138,6 +138,25 @@ mp.add_hook = function add_hook(name, pri, fn) { · 114 unmodified lines
138 return mp._hook_add(name, pri - 50, hooks.length);138 return mp._hook_add(name, pri - 50, hooks.length);
139}139}
140 140
141// ----- async commands -----
142var async_callbacks = new_cache(); // items of id: fn
143var async_next_id = 1;
144
145mp.command_native_async = function command_native_async(node, cb) {
146 var id = async_next_id++;
147 async_callbacks[id] = cb;
148 return mp._command_native_async(id, node);
149}
150
151function async_command_handler(ev) {
152 var cb = async_callbacks[ev.id];
153 delete async_callbacks[ev.id];
154 if (ev.error)
155 cb(false, undefined, ev.error);
156 else
157 cb(true, ev.result, "");
158}
159
141/**********************************************************************160/**********************************************************************
142 * key bindings161 * key bindings
143 *********************************************************************/162 *********************************************************************/
@@ -557,6 +576,7 @@ g.exit = function() { mp.keep_running = false }; // user-facing too · 413 unmodified lines
557mp.register_event("shutdown", g.exit);576mp.register_event("shutdown", g.exit);
558mp.register_event("property-change", notify_observer);577mp.register_event("property-change", notify_observer);
559mp.register_event("hook", run_hook);578mp.register_event("hook", run_hook);
579mp.register_event("command-reply", async_command_handler);
560mp.register_event("client-message", dispatch_message);580mp.register_event("client-message", dispatch_message);
561mp.register_script_message("key-binding", dispatch_key_binding);581mp.register_script_message("key-binding", dispatch_key_binding);
562 582

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t