Ruby clients for OBS Studio WebSocket v5.0
Go to file
dependabot[bot] 3e661b23a3
Update rake requirement from ~> 11.2, >= 11.2.2 to >= 11.2.2, ~> 13.0
Updates the requirements on [rake](https://github.com/ruby/rake) to permit the latest version.
- [Release notes](https://github.com/ruby/rake/releases)
- [Changelog](https://github.com/ruby/rake/blob/master/History.rdoc)
- [Commits](https://github.com/ruby/rake/compare/v11.3.0...v13.0.6)

---
updated-dependencies:
- dependency-name: rake
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-09-03 15:40:27 +00:00
examples reword in readme. 2023-08-17 23:26:34 +01:00
lib now using String refinement 2023-08-29 22:55:11 +01:00
test check identified state in Event::Client 2023-08-11 22:12:28 +01:00
.gitignore minor version bump 2023-07-19 15:14:46 +01:00
CHANGELOG.md initial commit 2022-10-22 22:30:40 +01:00
Gemfile initial commit 2022-10-22 22:30:40 +01:00
Gemfile.lock Update rake requirement from ~> 11.2, >= 11.2.2 to >= 11.2.2, ~> 13.0 2023-09-03 15:40:27 +00:00
LICENSE Initial commit 2022-10-22 21:47:31 +01:00
main.rb update main example to print mute state 2023-08-11 16:15:17 +01:00
obsws.gemspec Update rake requirement from ~> 11.2, >= 11.2.2 to >= 11.2.2, ~> 13.0 2023-09-03 15:40:27 +00:00
Rakefile test files renamed with test_ prefix 2023-08-11 14:44:51 +01:00
README.md upd attribute ssection in readme 2023-08-17 23:31:26 +01:00

Gem Version License: MIT Ruby Code Style

Ruby Clients for OBS Studio WebSocket v5.0

Requirements

  • OBS Studio
  • OBS Websocket v5 Plugin
    • With the release of OBS Studio version 28, Websocket plugin is included by default. But it should be manually installed for earlier versions of OBS.
  • Ruby 3.0 or greater

Installation

Bundler

bundle add obsws
bundle install

Use

Example main.rb

Pass host, port and password as keyword arguments.

require "obsws"

class Main
  INPUT = "Mic/Aux"

  def run
    OBSWS::Requests::Client
      .new(host: "localhost", port: 4455, password: "strongpassword")
      .run do |client|
      # Toggle the mute state of your Mic input and print its new mute state
      client.toggle_input_mute(INPUT)
      resp = client.get_input_mute(INPUT)
      puts "Input '#{INPUT}' was set to #{resp.input_muted}"
    end
  end
end

Main.new.run if $PROGRAM_NAME == __FILE__

Passing OBSWS::Requests::Client.run a block closes the socket once the block returns.

Requests

Method names for requests match the API calls but snake cased.

example:

# GetVersion
resp = r_client.get_version

# SetCurrentProgramScene
r_client.set_current_program_scene("BRB")

For a full list of requests refer to Requests

Events

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:

class Observer
    def initialize
        @e_client = OBSWS::Events::Client.new(host: "localhost", port: 4455, password: "strongpassword")
        # register blocks on event types.
        @e_client.on :current_program_scene_changed do |data|
          ...
        end
        @e_client.on :input_mute_state_changed do |data|
          ...
        end
    end
end

For a full list of events refer to Events

Attributes

For both request responses and event data you may inspect the available attributes using attrs.

example:

resp = @r_client.get_version
p resp.attrs

@e_client.on :input_mute_state_changed do |data|
  p data.attrs
end

Errors

If a general error occurs an OBSWSError will be raised.

If a connection attempt fails or times out an OBSWSConnectionError will be raised.

If a request fails an OBSWSRequestError will be raised with a status code.

  • The request name and code are retrievable through the following attributes:
    • req_name
    • code

For a full list of status codes refer to Codes

Logging

To enable logs set an environmental variable OBSWS_LOG_LEVEL to the appropriate level.

example in powershell:

$env:OBSWS_LOG_LEVEL="DEBUG"

Tests

To run all tests:

bundle exec rake -v

Official Documentation

For the full documentation: