From 8d2cc774aca37a84269fa6b90261760f341ac69e Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Sun, 27 Aug 2023 17:24:25 +0100 Subject: [PATCH] register blocks on the event client object remove running attribute reader --- examples/obs/Gemfile | 2 +- examples/obs/main.rb | 34 ++++++++++++++-------------------- 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/examples/obs/Gemfile b/examples/obs/Gemfile index ce79feb..10b6430 100644 --- a/examples/obs/Gemfile +++ b/examples/obs/Gemfile @@ -2,4 +2,4 @@ source "https://rubygems.org" -gem "obsws", "~> 0.4.0" +gem "obsws", "~> 0.5.8" diff --git a/examples/obs/main.rb b/examples/obs/main.rb index 3fd72f2..6e77d14 100644 --- a/examples/obs/main.rb +++ b/examples/obs/main.rb @@ -4,34 +4,28 @@ require "yaml" require "pathname" class Main - attr_reader :running - def initialize(vm, **kwargs) @vm = vm @obsws = OBSWS::Events::Client.new(**kwargs) - @obsws.register([ - method(:on_current_program_scene_changed), - method(:on_exit_started) - ]) - @running = true - end - def run - sleep(0.1) while running - end + @obsws.on :on_current_program_scene_changed do |data| + scene = data.scene_name + puts "Switched to scene #{scene}" + if respond_to?("on_#{scene.downcase}") + send("on_#{scene.downcase}") + end + end - def on_current_program_scene_changed(data) - scene = data.scene_name - puts "Switched to scene #{scene}" - if respond_to?("on_#{scene.downcase}") - send("on_#{scene.downcase}") + @obsws.on :on_exit_started do |data| + puts "OBS closing!" + @obsws.close + @running = false end end - def on_exit_started - puts "OBS closing!" - @obsws.close - @running = false + def run + @running = true + sleep(0.1) while @running end def on_start