2023-07-21 06:37:14 +01:00
|
|
|
require_relative "../../lib/obsws"
|
2023-07-19 15:13:26 +01:00
|
|
|
require "yaml"
|
2022-10-22 22:30:40 +01:00
|
|
|
|
|
|
|
|
2023-07-19 15:13:26 +01:00
|
|
|
class Main
|
2022-10-22 22:30:40 +01:00
|
|
|
attr_reader :running
|
|
|
|
|
|
|
|
def initialize(**kwargs)
|
|
|
|
@r_client = OBSWS::Requests::Client.new(**kwargs)
|
|
|
|
@e_client = OBSWS::Events::Client.new(**kwargs)
|
|
|
|
@e_client.add_observer(self)
|
|
|
|
|
2023-07-26 10:18:32 +01:00
|
|
|
puts infostring
|
2022-10-22 22:30:40 +01:00
|
|
|
@running = true
|
|
|
|
end
|
|
|
|
|
2023-07-19 15:13:26 +01:00
|
|
|
def run
|
|
|
|
sleep(0.1) while running
|
|
|
|
end
|
|
|
|
|
2023-07-26 10:18:32 +01:00
|
|
|
def infostring
|
2022-10-22 22:30:40 +01:00
|
|
|
resp = @r_client.get_version
|
|
|
|
[
|
|
|
|
"Using obs version:",
|
|
|
|
resp.obs_version,
|
|
|
|
"With websocket version:",
|
|
|
|
resp.obs_web_socket_version
|
2023-07-26 10:18:32 +01:00
|
|
|
].join("\n")
|
2022-10-22 22:30:40 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def on_current_program_scene_changed(data)
|
|
|
|
puts "Switched to scene #{data.scene_name}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def on_scene_created(data)
|
|
|
|
puts "scene #{data.scene_name} has been created"
|
|
|
|
end
|
|
|
|
|
|
|
|
def on_input_mute_state_changed(data)
|
|
|
|
puts "#{data.input_name} mute toggled"
|
|
|
|
end
|
|
|
|
|
|
|
|
def on_exit_started
|
|
|
|
puts "OBS closing!"
|
|
|
|
@r_client.close
|
|
|
|
@e_client.close
|
|
|
|
@running = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-07-19 15:13:26 +01:00
|
|
|
def conn_from_yaml
|
|
|
|
YAML.load_file("obs.yml", symbolize_names: true)[:connection]
|
2022-10-22 22:30:40 +01:00
|
|
|
end
|
|
|
|
|
2023-07-21 06:37:14 +01:00
|
|
|
Main.new(**conn_from_yaml).run if $PROGRAM_NAME == __FILE__
|