Compare commits

4 Commits

Author SHA1 Message Date
587e861bbe upd Gemfile.lock 2023-08-18 21:51:22 +01:00
3f255d6b45 upd attribute ssection in readme 2023-08-17 23:31:26 +01:00
9bd2b53b3d udpate attributes section in README 2023-08-17 23:28:37 +01:00
61c9a7b365 reword in readme.
remove brackets
2023-08-17 23:26:34 +01:00
4 changed files with 16 additions and 13 deletions

View File

@@ -1,7 +1,7 @@
PATH PATH
remote: . remote: .
specs: specs:
obsws (0.5.8) obsws (0.6.0)
waitutil (~> 0.2.1) waitutil (~> 0.2.1)
websocket-driver (~> 0.7.5) websocket-driver (~> 0.7.5)

View File

@@ -67,7 +67,9 @@ For a full list of requests refer to [Requests](https://github.com/obsproject/ob
### Events ### Events
Register blocks with the Event client using the `on` method. The event data will be passed to the block. Register blocks with the Event client using the `on` method. Event tokens should match the event name but snake cased.
The event data will be passed to the block.
example: example:
@@ -76,10 +78,10 @@ class Observer
def initialize def initialize
@e_client = OBSWS::Events::Client.new(host: "localhost", port: 4455, password: "strongpassword") @e_client = OBSWS::Events::Client.new(host: "localhost", port: 4455, password: "strongpassword")
# register blocks on event types. # register blocks on event types.
@e_client.on(:current_program_scene_changed) do |data| @e_client.on :current_program_scene_changed do |data|
... ...
end end
@e_client.on(:input_mute_state_changed) do |data| @e_client.on :input_mute_state_changed do |data|
... ...
end end
end end
@@ -95,11 +97,12 @@ For both request responses and event data you may inspect the available attribut
example: example:
```ruby ```ruby
resp = cl.get_version resp = @r_client.get_version
p resp.attrs p resp.attrs
def on_scene_created(data): @e_client.on :input_mute_state_changed do |data|
p data.attrs p data.attrs
end
``` ```
### Errors ### Errors

View File

@@ -6,16 +6,16 @@ class Main
@r_client = OBSWS::Requests::Client.new(**kwargs) @r_client = OBSWS::Requests::Client.new(**kwargs)
@e_client = OBSWS::Events::Client.new(**kwargs) @e_client = OBSWS::Events::Client.new(**kwargs)
@e_client.on(:current_program_scene_changed) do |data| @e_client.on :current_program_scene_changed do |data|
puts "Switched to scene #{data.scene_name}" puts "Switched to scene #{data.scene_name}"
end end
@e_client.on(:scene_created) do |data| @e_client.on :scene_created do |data|
puts "scene #{data.scene_name} has been created" puts "scene #{data.scene_name} has been created"
end end
@e_client.on(:input_mute_state_changed) do |data| @e_client.on :input_mute_state_changed do |data|
puts "#{data.input_name} mute toggled" puts "#{data.input_name} mute toggled"
end end
@e_client.on(:exit_started) do @e_client.on :exit_started do
puts "OBS closing!" puts "OBS closing!"
@r_client.close @r_client.close
@e_client.close @e_client.close

View File

@@ -14,12 +14,12 @@ class Main
subs = OBSWS::Events::SUBS::LOW_VOLUME | OBSWS::Events::SUBS::INPUTVOLUMEMETERS subs = OBSWS::Events::SUBS::LOW_VOLUME | OBSWS::Events::SUBS::INPUTVOLUMEMETERS
@e_client = OBSWS::Events::Client.new(subs:, **kwargs) @e_client = OBSWS::Events::Client.new(subs:, **kwargs)
@e_client.on(:input_mute_state_changed) do |data| @e_client.on :input_mute_state_changed do |data|
if data.input_name == DEVICE if data.input_name == DEVICE
puts "#{DEVICE} mute toggled" puts "#{DEVICE} mute toggled"
end end
end end
@e_client.on(:input_volume_meters) do |data| @e_client.on :input_volume_meters do |data|
fget = ->(x) { (x > 0) ? (20 * Math.log(x, 10)).round(1) : -200.0 } fget = ->(x) { (x > 0) ? (20 * Math.log(x, 10)).round(1) : -200.0 }
data.inputs.each do |d| data.inputs.each do |d|