From aafcd185d008bb8e058e7ee56c6dc57d0155de42 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Fri, 25 Nov 2022 17:57:56 +0000 Subject: [PATCH] patch bump add full request payload to logger. raise OBSWSError if auth enabled but no password provided add example tasks to rake file add logging section to README --- Gemfile.lock | 2 +- README.md | 13 +++++++++++++ Rakefile | 14 ++++++++++++++ lib/obsws/base.rb | 27 ++++++++++++++++----------- lib/obsws/req.rb | 4 ++-- lib/obsws/version.rb | 2 +- 6 files changed, 47 insertions(+), 15 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 7eb99f7..e259bc6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - obsws (0.1.1) + obsws (0.1.2) observer (~> 0.1.1) waitutil (~> 0.2.1) websocket-driver (~> 0.7.5) diff --git a/README.md b/README.md index 6ffa35d..4e83221 100644 --- a/README.md +++ b/README.md @@ -115,6 +115,19 @@ If a request fails an `OBSWSError` will be raised with a status code. For a full list of status codes refer to [Codes](https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md#requeststatus) +### Logging + +To see the raw messages set log level to debug + +example: + +```ruby +require "obsws" + +OBSWS::LOGGER.debug! +... +``` + ### Tests To run all tests: diff --git a/Rakefile b/Rakefile index 6cb6cf9..6174374 100644 --- a/Rakefile +++ b/Rakefile @@ -1,5 +1,7 @@ require "minitest/test_task" +HERE = File.expand_path File.dirname(__FILE__) + Minitest::TestTask.create(:test) do |t| t.libs << "test" t.warning = false @@ -7,3 +9,15 @@ Minitest::TestTask.create(:test) do |t| end task default: :test +task :events do + filepath = File.join(HERE, "examples", "events", "main.rb") + ruby filepath +end +task :levels do + filepath = File.join(HERE, "examples", "levels", "main.rb") + ruby filepath +end +task :scene_rotate do + filepath = File.join(HERE, "examples", "scene_rotate", "main.rb") + ruby filepath +end diff --git a/lib/obsws/base.rb b/lib/obsws/base.rb index 504713b..ed44c39 100644 --- a/lib/obsws/base.rb +++ b/lib/obsws/base.rb @@ -45,12 +45,12 @@ module OBSWS @closed = true end @driver.on :message do |msg| - LOGGER.debug("received [#{msg}] passing to handler") + LOGGER.debug("received: #{msg.data}") msg_handler(JSON.parse(msg.data, symbolize_names: true)) end start_driver WaitUtil.wait_for_condition( - "waiting successful identification", + "successful identification", delay_sec: 0.01, timeout_sec: 3 ) { @identified } @@ -75,15 +75,20 @@ module OBSWS end def identify(auth) - LOGGER.info("initiating authentication") if auth - payload = { - op: Mixin::OPCodes::IDENTIFY, - d: { - rpcVersion: 1, - eventSubscriptions: @subs + if auth + if @password.empty? + raise OBSWSError("auth enabled but no password provided") + end + LOGGER.info("initiating authentication") + payload = { + op: Mixin::OPCodes::IDENTIFY, + d: { + rpcVersion: 1, + eventSubscriptions: @subs + } } - } - payload[:d][:authentication] = auth_token(**auth) if auth + payload[:d][:authentication] = auth_token(**auth) + end @driver.text(JSON.generate(payload)) end @@ -108,8 +113,8 @@ module OBSWS } } payload[:d][:requestData] = data if data + LOGGER.debug("sending request: #{payload}") queued = @driver.text(JSON.generate(payload)) - LOGGER.debug("request with id #{id} queued? #{queued}") end end end diff --git a/lib/obsws/req.rb b/lib/obsws/req.rb index 2b33859..d683c6b 100644 --- a/lib/obsws/req.rb +++ b/lib/obsws/req.rb @@ -28,7 +28,7 @@ module OBSWS ensure close WaitUtil.wait_for_condition( - "driver has closed", + "driver to close", delay_sec: 0.01, timeout_sec: 1 ) { @base_client.closed } @@ -42,7 +42,7 @@ module OBSWS id = rand(1..1000) @base_client.req(id, req, data) WaitUtil.wait_for_condition( - "reponse id matches request id", + "reponse id to match request id", delay_sec: 0.001, timeout_sec: 3 ) { @response[:requestId] == id } diff --git a/lib/obsws/version.rb b/lib/obsws/version.rb index fe2dfa7..9cd2216 100644 --- a/lib/obsws/version.rb +++ b/lib/obsws/version.rb @@ -11,7 +11,7 @@ module OBSWS end def patch - 1 + 2 end def to_a