History

js: use unified events (match 218d6643, 8a58a699)

Avi Halachmi (:avih) committed 6 years ago

Commit c4cc48c1 parent 8a58a691 file · +4 −98Browse files

Showing the changes to player/javascript.c (1 of 1 file). Show all

Unified · Split

player/javascript.c+4−98
@@ -1086,107 +1086,13 @@ static void makenode(void *ta_ctx, mpv_node *dst, js_State *J, int idx) · 1085 unmodified lines
10861086 // args: wait in secs (infinite if negative) if mpv doesn't send events earlier.
10871087 static void script_wait_event(js_State *J)
10881088 {
1089− int top = js_gettop(J);
10901089 double timeout = js_isnumber(J, 1) ? js_tonumber(J, 1) : -1;
10911090 mpv_event *event = mpv_wait_event(jclient(J), timeout);
10921091
1093− js_newobject(J); // the reply
1094− js_pushstring(J, mpv_event_name(event->event_id));
1095− js_setproperty(J, -2, "event"); // reply.event (is an event name)
1096−
1097− if (event->reply_userdata) {
1098− js_pushnumber(J, event->reply_userdata);
1099− js_setproperty(J, -2, "id"); // reply.id
1100− }
1101−
1102− if (event->error < 0) {
1103− // TODO: untested
1104− js_pushstring(J, mpv_error_string(event->error));
1105− js_setproperty(J, -2, "error"); // reply.error
1106− }
1107−
1108− switch (event->event_id) {
1109− case MPV_EVENT_LOG_MESSAGE: {
1110− mpv_event_log_message *msg = event->data;
1111−
1112− js_pushstring(J, msg->prefix);
1113− js_setproperty(J, -2, "prefix"); // reply.prefix (e.g. "cplayer")
1114− js_pushstring(J, msg->level);
1115− js_setproperty(J, -2, "level"); // reply.level (e.g. "v" or "info")
1116− js_pushstring(J, msg->text);
1117− js_setproperty(J, -2, "text"); // reply.text
1118− break;
1119− }
1120−
1121− case MPV_EVENT_CLIENT_MESSAGE: {
1122− mpv_event_client_message *msg = event->data;
1123−
1124− js_newarray(J); // reply.args
1125− for (int n = 0; n < msg->num_args; n++) {
1126− js_pushstring(J, msg->args[n]);
1127− js_setindex(J, -2, n);
1128− }
1129− js_setproperty(J, -2, "args"); // reply.args (is a strings array)
1130− break;
1131− }
1132−
1133− case MPV_EVENT_END_FILE: {
1134− mpv_event_end_file *eef = event->data;
1135− const char *reason;
1136−
1137− switch (eef->reason) {
1138− case MPV_END_FILE_REASON_EOF: reason = "eof"; break;
1139− case MPV_END_FILE_REASON_STOP: reason = "stop"; break;
1140− case MPV_END_FILE_REASON_QUIT: reason = "quit"; break;
1141− case MPV_END_FILE_REASON_ERROR: reason = "error"; break;
1142− case MPV_END_FILE_REASON_REDIRECT: reason = "redirect"; break;
1143− default:
1144− reason = "unknown";
1145− }
1146− js_pushstring(J, reason);
1147− js_setproperty(J, -2, "reason"); // reply.reason
1148−
1149− if (eef->reason == MPV_END_FILE_REASON_ERROR) {
1150− js_pushstring(J, mpv_error_string(eef->error));
1151− js_setproperty(J, -2, "error"); // reply.error
1152− }
1153− break;
1154− }
1155−
1156− case MPV_EVENT_PROPERTY_CHANGE: {
1157− mpv_event_property *prop = event->data;
1158− js_pushstring(J, prop->name);
1159− js_setproperty(J, -2, "name"); // reply.name (is a property name)
1160−
1161− switch (prop->format) {
1162− case MPV_FORMAT_NODE: pushnode(J, prop->data); break;
1163− case MPV_FORMAT_DOUBLE: js_pushnumber(J, *(double *)prop->data); break;
1164− case MPV_FORMAT_INT64: js_pushnumber(J, *(int64_t *)prop->data); break;
1165− case MPV_FORMAT_FLAG: js_pushboolean(J, *(int *)prop->data); break;
1166− case MPV_FORMAT_STRING: js_pushstring(J, *(char **)prop->data); break;
1167− default:
1168− js_pushnull(J); // also for FORMAT_NONE, e.g. observe type "none"
1169− }
1170− js_setproperty(J, -2, "data"); // reply.data (value as observed type)
1171− break;
1172− }
1173−
1174− case MPV_EVENT_HOOK: {
1175− mpv_event_hook *hook = event->data;
1176− js_pushnumber(J, hook->id);
1177− js_setproperty(J, -2, "hook_id"); // reply.hook_id (is a number)
1178− break;
1179− }
1180−
1181− case MPV_EVENT_COMMAND_REPLY: {
1182− mpv_event_command *cmd = event->data;
1183− pushnode(J, &cmd->result);
1184− js_setproperty(J, -2, "result"); // reply.result (mpv node)
1185− break;
1186− }
1187− } // switch (event->event_id)
1188−
1189− assert(top == js_gettop(J) - 1);
1092+ struct mpv_node rn;
1093+ mpv_event_to_node(&rn, event);
1094+ pushnode(J, &rn);
1095+ mpv_free_node_contents(&rn);
11901096 }
11911097
11921098 /**********************************************************************

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