mirror of
https://github.com/onyx-and-iris/obsws-ruby.git
synced 2025-04-19 10:53:45 +01:00
Compare commits
No commits in common. "6dc21314e893418215ed77314c4c5554ae89dc28" and "856b7b5a5bfc6ce3e20fd6a7808b35eaddb98605" have entirely different histories.
6dc21314e8
...
856b7b5a5b
34
README.md
34
README.md
@ -28,39 +28,37 @@ bundle install
|
|||||||
|
|
||||||
#### Example `main.rb`
|
#### Example `main.rb`
|
||||||
|
|
||||||
Pass `host`, `port` and `password` as keyword arguments.
|
pass `host`, `port` and `password` as keyword arguments.
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
require "obsws"
|
require "obsws"
|
||||||
|
|
||||||
class Main
|
def main
|
||||||
def run
|
OBSWS::Requests::Client
|
||||||
OBSWS::Requests::Client
|
.new(host: "localhost", port: 4455, password: "strongpassword")
|
||||||
.new(host: "localhost", port: 4455, password: "strongpassword")
|
.run do |client|
|
||||||
.run do |client|
|
# Toggle the mute state of your Mic input
|
||||||
# Toggle the mute state of your Mic input
|
client.toggle_input_mute("Mic/Aux")
|
||||||
client.toggle_input_mute("Mic/Aux")
|
end
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
Main.new.run if $PROGRAM_NAME == __FILE__
|
main if $0 == __FILE__
|
||||||
```
|
```
|
||||||
|
|
||||||
Passing OBSWS::Requests::Client.run a block closes the socket once the block returns.
|
|
||||||
|
|
||||||
### Requests
|
### Requests
|
||||||
|
|
||||||
Method names for requests match the API calls but snake cased.
|
Method names for requests match the API calls but snake cased. `run` accepts a block that closes the socket once you are done.
|
||||||
|
|
||||||
example:
|
example:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
# GetVersion
|
r_client.run do
|
||||||
resp = r_client.get_version
|
# GetVersion
|
||||||
|
resp = r_client.get_version
|
||||||
|
|
||||||
# SetCurrentProgramScene
|
# SetCurrentProgramScene
|
||||||
r_client.set_current_program_scene("BRB")
|
r_client.set_current_program_scene("BRB")
|
||||||
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
For a full list of requests refer to [Requests](https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md#requests)
|
For a full list of requests refer to [Requests](https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md#requests)
|
||||||
|
7
examples/events/Gemfile
Normal file
7
examples/events/Gemfile
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
source "https://rubygems.org"
|
||||||
|
|
||||||
|
# gem "rails"
|
||||||
|
|
||||||
|
gem "obsws", path: "../.."
|
25
examples/events/Gemfile.lock
Normal file
25
examples/events/Gemfile.lock
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
PATH
|
||||||
|
remote: ../..
|
||||||
|
specs:
|
||||||
|
obsws (0.1.3)
|
||||||
|
observer (~> 0.1.1)
|
||||||
|
waitutil (~> 0.2.1)
|
||||||
|
websocket-driver (~> 0.7.5)
|
||||||
|
|
||||||
|
GEM
|
||||||
|
remote: https://rubygems.org/
|
||||||
|
specs:
|
||||||
|
observer (0.1.1)
|
||||||
|
waitutil (0.2.1)
|
||||||
|
websocket-driver (0.7.5)
|
||||||
|
websocket-extensions (>= 0.1.0)
|
||||||
|
websocket-extensions (0.1.5)
|
||||||
|
|
||||||
|
PLATFORMS
|
||||||
|
x64-mingw-ucrt
|
||||||
|
|
||||||
|
DEPENDENCIES
|
||||||
|
obsws!
|
||||||
|
|
||||||
|
BUNDLED WITH
|
||||||
|
2.3.22
|
@ -1,4 +1,4 @@
|
|||||||
require_relative "../../lib/obsws"
|
require "obsws"
|
||||||
require "yaml"
|
require "yaml"
|
||||||
|
|
||||||
OBSWS::LOGGER.info!
|
OBSWS::LOGGER.info!
|
||||||
@ -53,4 +53,4 @@ def conn_from_yaml
|
|||||||
YAML.load_file("obs.yml", symbolize_names: true)[:connection]
|
YAML.load_file("obs.yml", symbolize_names: true)[:connection]
|
||||||
end
|
end
|
||||||
|
|
||||||
Main.new(**conn_from_yaml).run if $PROGRAM_NAME == __FILE__
|
Main.new(**conn_from_yaml).run if $0 == __FILE__
|
||||||
|
7
examples/levels/Gemfile
Normal file
7
examples/levels/Gemfile
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
source "https://rubygems.org"
|
||||||
|
|
||||||
|
# gem "rails"
|
||||||
|
|
||||||
|
gem "obsws", path: "../.."
|
25
examples/levels/Gemfile.lock
Normal file
25
examples/levels/Gemfile.lock
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
PATH
|
||||||
|
remote: ../..
|
||||||
|
specs:
|
||||||
|
obsws (0.1.3)
|
||||||
|
observer (~> 0.1.1)
|
||||||
|
waitutil (~> 0.2.1)
|
||||||
|
websocket-driver (~> 0.7.5)
|
||||||
|
|
||||||
|
GEM
|
||||||
|
remote: https://rubygems.org/
|
||||||
|
specs:
|
||||||
|
observer (0.1.1)
|
||||||
|
waitutil (0.2.1)
|
||||||
|
websocket-driver (0.7.5)
|
||||||
|
websocket-extensions (>= 0.1.0)
|
||||||
|
websocket-extensions (0.1.5)
|
||||||
|
|
||||||
|
PLATFORMS
|
||||||
|
x64-mingw-ucrt
|
||||||
|
|
||||||
|
DEPENDENCIES
|
||||||
|
obsws!
|
||||||
|
|
||||||
|
BUNDLED WITH
|
||||||
|
2.4.15
|
@ -1,7 +1,8 @@
|
|||||||
require_relative "../../lib/obsws"
|
require "obsws"
|
||||||
require "yaml"
|
require "yaml"
|
||||||
|
|
||||||
OBSWS::LOGGER.info!
|
OBSWS::LOGGER.info!
|
||||||
|
DEVICE = "Desktop Audio"
|
||||||
|
|
||||||
module LevelTypes
|
module LevelTypes
|
||||||
VU = 0
|
VU = 0
|
||||||
@ -10,8 +11,6 @@ module LevelTypes
|
|||||||
end
|
end
|
||||||
|
|
||||||
class Main
|
class Main
|
||||||
DEVICE = "Desktop Audio"
|
|
||||||
|
|
||||||
def initialize(**kwargs)
|
def initialize(**kwargs)
|
||||||
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)
|
||||||
@ -20,7 +19,7 @@ class Main
|
|||||||
|
|
||||||
def run
|
def run
|
||||||
puts "press <Enter> to quit"
|
puts "press <Enter> to quit"
|
||||||
loop { break if gets.chomp.empty? }
|
exit if gets.chomp.empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_input_mute_state_changed(data)
|
def on_input_mute_state_changed(data)
|
||||||
@ -46,4 +45,4 @@ def conn_from_yaml
|
|||||||
YAML.load_file("obs.yml", symbolize_names: true)[:connection]
|
YAML.load_file("obs.yml", symbolize_names: true)[:connection]
|
||||||
end
|
end
|
||||||
|
|
||||||
Main.new(**conn_from_yaml).run if $PROGRAM_NAME == __FILE__
|
Main.new(**conn_from_yaml).run if $0 == __FILE__
|
||||||
|
7
examples/scene_rotate/Gemfile
Normal file
7
examples/scene_rotate/Gemfile
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
source "https://rubygems.org"
|
||||||
|
|
||||||
|
# gem "rails"
|
||||||
|
|
||||||
|
gem "obsws", path: "../.."
|
25
examples/scene_rotate/Gemfile.lock
Normal file
25
examples/scene_rotate/Gemfile.lock
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
PATH
|
||||||
|
remote: ../..
|
||||||
|
specs:
|
||||||
|
obsws (0.1.3)
|
||||||
|
observer (~> 0.1.1)
|
||||||
|
waitutil (~> 0.2.1)
|
||||||
|
websocket-driver (~> 0.7.5)
|
||||||
|
|
||||||
|
GEM
|
||||||
|
remote: https://rubygems.org/
|
||||||
|
specs:
|
||||||
|
observer (0.1.1)
|
||||||
|
waitutil (0.2.1)
|
||||||
|
websocket-driver (0.7.5)
|
||||||
|
websocket-extensions (>= 0.1.0)
|
||||||
|
websocket-extensions (0.1.5)
|
||||||
|
|
||||||
|
PLATFORMS
|
||||||
|
x64-mingw-ucrt
|
||||||
|
|
||||||
|
DEPENDENCIES
|
||||||
|
obsws!
|
||||||
|
|
||||||
|
BUNDLED WITH
|
||||||
|
2.3.22
|
@ -1,24 +1,21 @@
|
|||||||
require_relative "../../lib/obsws"
|
require "obsws"
|
||||||
require "yaml"
|
require "yaml"
|
||||||
|
|
||||||
OBSWS::LOGGER.info!
|
OBSWS::LOGGER.info!
|
||||||
|
|
||||||
class Main
|
def conn_from_yaml
|
||||||
def conn_from_yaml
|
YAML.load_file("obs.yml", symbolize_names: true)[:connection]
|
||||||
YAML.load_file("obs.yml", symbolize_names: true)[:connection]
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def run
|
def main
|
||||||
OBSWS::Requests::Client.new(**conn_from_yaml).run do |client|
|
OBSWS::Requests::Client.new(**conn_from_yaml).run do |client|
|
||||||
resp = client.get_scene_list
|
resp = client.get_scene_list
|
||||||
resp.scenes.reverse_each do |scene|
|
resp.scenes.reverse_each do |scene|
|
||||||
puts "Switching to scene #{scene[:sceneName]}"
|
puts "Switching to scene #{scene[:sceneName]}"
|
||||||
client.set_current_program_scene(scene[:sceneName])
|
client.set_current_program_scene(scene[:sceneName])
|
||||||
sleep(0.5)
|
sleep(0.5)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
main if $0 == __FILE__
|
||||||
Main.new.run if $PROGRAM_NAME == __FILE__
|
|
||||||
|
@ -114,7 +114,7 @@ module OBSWS
|
|||||||
}
|
}
|
||||||
payload[:d][:requestData] = data if data
|
payload[:d][:requestData] = data if data
|
||||||
LOGGER.debug("sending request: #{payload}")
|
LOGGER.debug("sending request: #{payload}")
|
||||||
@driver.text(JSON.generate(payload))
|
queued = @driver.text(JSON.generate(payload))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
6
main.rb
6
main.rb
@ -1,7 +1,6 @@
|
|||||||
require_relative "lib/obsws"
|
require_relative "lib/obsws"
|
||||||
|
|
||||||
class Main
|
def main
|
||||||
def run
|
|
||||||
OBSWS::Requests::Client.new(
|
OBSWS::Requests::Client.new(
|
||||||
host: "localhost",
|
host: "localhost",
|
||||||
port: 4455,
|
port: 4455,
|
||||||
@ -10,7 +9,6 @@ class Main
|
|||||||
# Toggle the mute state of your Mic input
|
# Toggle the mute state of your Mic input
|
||||||
client.toggle_input_mute("Mic/Aux")
|
client.toggle_input_mute("Mic/Aux")
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
Main.new.run if $PROGRAM_NAME == __FILE__
|
main if $0 == __FILE__
|
||||||
|
Loading…
x
Reference in New Issue
Block a user