class MPV::Socket
Attributes
socket[R]
Public Class Methods
new(path)
click to toggle source
# File lib/mpv-slave/socket.rb, line 14 def initialize path @path = path @socket = UNIXSocket.new(path) end
Public Instance Methods
close()
click to toggle source
# File lib/mpv-slave/socket.rb, line 51 def close @socket.close File.delete(@path) if File.exists? @path end
command(*args)
click to toggle source
# File lib/mpv-slave/socket.rb, line 23 def command *args msg = { "command" => args, } socket.puts(JSON.dump(msg)) loop do response = get_response next if not response["event"].nil? if response["error"] != "success" warn "error: #{response} for #{msg}" end return response["data"] end end
get_response()
click to toggle source
# File lib/mpv-slave/socket.rb, line 19 def get_response JSON.parse(socket.readline) end
wait_for(event)
click to toggle source
# File lib/mpv-slave/socket.rb, line 41 def wait_for event loop do response = get_response case response["event"] when event, "idle" break end end end