-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmultisocket.lua
More file actions
33 lines (27 loc) · 789 Bytes
/
multisocket.lua
File metadata and controls
33 lines (27 loc) · 789 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
-- Creates a socket for every mpv instance. The sockets are named "mpvctl"
-- followed by a number, i.e. mpvctl5.
filename = ''
function remove_socket()
print("Socket " .. filename .. " removed")
mp.set_property("input-ipc-server", "")
os.remove(filename)
end
function add_socket()
if mp.get_property("input-ipc-server") == "" then
i = 0
while true do
filename = "/tmp/mpvctl" .. i
local file, msg, err = io.open(filename)
if file == nil and err ~= 6 then -- 6 = socket (maybe not portable?)
break
else
i = i + 1
end
end
mp.set_property("input-ipc-server", filename)
mp.register_event("shutdown", remove_socket)
end
end
add_socket()
mp.register_script_message("add-socket", add_socket)
mp.register_script_message("remove-socket", remove_socket)