obsws 0.5.3 → 0.5.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4aeda40922d842790c7aa969608fe100ad4bd1b9dfc34ba586ec4d126c64abca
4
- data.tar.gz: f2a6f162110e7bd46eaec6a5aa5fd1b30c684a8d0b4e1ab6e68b9e127ba1994f
3
+ metadata.gz: 78061cca710f6c790eacbbfce83036818edbe3c30791783af1f9131ef7407f91
4
+ data.tar.gz: e7399380cb61847004f1ff29fc5dbf0bc9f55edaa3063a89d99c089e9259c8f2
5
5
  SHA512:
6
- metadata.gz: '065915f3edb1d8e0235ce88765fe2dde21e300f905d20d569e7cd630db8446a281be695ee8059449f77f8d224eecab4ad445ad379362e5032e5fe36a1d1e675b'
7
- data.tar.gz: 562b42f5b9b0152ffe22ba3b5dda1d4553c8f09be645709e589a2cc2d0e245a091396fc6c0bc83eb0a63cb10467f10e42cb25856767ee33dbd478e8d52dc9bb1
6
+ metadata.gz: d7a6c5fc25ffc88c888d18c55e35a1410ac7780e4c64adf46a8dd52cf10a9ad2416de9acfffb7f33c2836e988103468dfc30336984c0908af11055b5dd6de60d
7
+ data.tar.gz: c65f732267e7bc4219b491f5e6ec3e5dcc6c6a36d0b891932bbdcff339dddcffea2156ef0d5fc855abdad0915c01f14262c50a33beb7842885f9895a8ff7d2f8
data/README.md CHANGED
@@ -30,13 +30,17 @@ Pass `host`, `port` and `password` as keyword arguments.
30
30
  require "obsws"
31
31
 
32
32
  class Main
33
+ INPUT = "Mic/Aux"
34
+
33
35
  def run
34
36
  OBSWS::Requests::Client
35
37
  .new(host: "localhost", port: 4455, password: "strongpassword")
36
38
  .run do |client|
37
- # Toggle the mute state of your Mic input
38
- client.toggle_input_mute("Mic/Aux")
39
- end
39
+ # Toggle the mute state of your Mic input and print its new mute state
40
+ client.toggle_input_mute(INPUT)
41
+ resp = client.get_input_mute(INPUT)
42
+ puts "Input '#{INPUT}' was set to #{resp.input_muted}"
43
+ end
40
44
  end
41
45
  end
42
46
 
@@ -115,7 +119,9 @@ If a connection attempt fails or times out an `OBSWSConnectionError` will be rai
115
119
 
116
120
  If a request fails an `OBSWSRequestError` will be raised with a status code.
117
121
 
118
- - The request name and code are retrievable through attributes {OBSWSRequestError}.req_name and {OBSWSRequestError}.code
122
+ - The request name and code are retrievable through the following attributes:
123
+ - `req_name`
124
+ - `code`
119
125
 
120
126
  For a full list of status codes refer to [Codes](https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md#requeststatus)
121
127
 
data/lib/obsws/base.rb CHANGED
@@ -1,10 +1,27 @@
1
1
  module OBSWS
2
+ class Identified
3
+ attr_accessor :state
4
+
5
+ def initialize
6
+ @state = :pending
7
+ end
8
+
9
+ def error_message
10
+ case @state
11
+ when :passwordless
12
+ "auth enabled but no password provided"
13
+ else
14
+ "failed to identify client with the websocket server"
15
+ end
16
+ end
17
+ end
18
+
2
19
  class Base
3
20
  include Logging
4
21
  include Driver::Director
5
22
  include Mixin::OPCodes
6
23
 
7
- attr_reader :closed
24
+ attr_reader :closed, :identified
8
25
  attr_writer :updater
9
26
 
10
27
  def initialize(**kwargs)
@@ -13,11 +30,12 @@ module OBSWS
13
30
  @password = kwargs[:password] || ""
14
31
  @subs = kwargs[:subs] || 0
15
32
  setup_driver(host, port) and start_driver
33
+ @identified = Identified.new
16
34
  WaitUtil.wait_for_condition(
17
35
  "successful identification",
18
36
  delay_sec: 0.01,
19
- timeout_sec: 3
20
- ) { @identified }
37
+ timeout_sec: kwargs[:connect_timeout] || 3
38
+ ) { @identified.state != :pending }
21
39
  end
22
40
 
23
41
  private
@@ -38,7 +56,8 @@ module OBSWS
38
56
  }
39
57
  if auth
40
58
  if @password.empty?
41
- raise OBSWSError("auth enabled but no password provided")
59
+ @identified.state = :passwordless
60
+ return
42
61
  end
43
62
  logger.info("initiating authentication")
44
63
  payload[:d][:authentication] = auth_token(**auth)
@@ -51,7 +70,7 @@ module OBSWS
51
70
  when Mixin::OPCodes::HELLO
52
71
  identify(data[:d][:authentication])
53
72
  when Mixin::OPCodes::IDENTIFIED
54
- @identified = true
73
+ @identified.state = :identified
55
74
  when Mixin::OPCodes::EVENT, Mixin::OPCodes::REQUESTRESPONSE
56
75
  @updater.call(data[:op], data[:d])
57
76
  end
data/lib/obsws/req.rb CHANGED
@@ -7,11 +7,15 @@ module OBSWS
7
7
 
8
8
  def initialize(**kwargs)
9
9
  @base_client = Base.new(**kwargs)
10
+ unless @base_client.identified.state == :identified
11
+ err_msg = @base_client.identified.error_message
12
+ logger.error(err_msg)
13
+ raise OBSWSConnectionError.new(err_msg)
14
+ end
10
15
  logger.info("#{self} successfully identified with server")
11
16
  rescue Errno::ECONNREFUSED, WaitUtil::TimeoutError => e
12
- msg = "#{e.class.name}: #{e.message}"
13
- logger.error(msg)
14
- raise OBSWSConnectionError.new(msg)
17
+ logger.error("#{e.class.name}: #{e.message}")
18
+ raise OBSWSConnectionError.new(e.message)
15
19
  else
16
20
  @base_client.updater = ->(op_code, data) {
17
21
  logger.debug("response received: #{data}")
@@ -36,31 +40,23 @@ module OBSWS
36
40
  end
37
41
 
38
42
  def call(req, data = nil)
39
- id = rand(1..1000)
40
- @base_client.req(id, req, data)
43
+ uuid = SecureRandom.uuid
44
+ @base_client.req(uuid, req, data)
41
45
  WaitUtil.wait_for_condition(
42
46
  "reponse id to match request id",
43
47
  delay_sec: 0.001,
44
48
  timeout_sec: 3
45
- ) { @response[:requestId] == id }
49
+ ) { @response[:requestId] == uuid }
46
50
  unless @response[:requestStatus][:result]
47
51
  raise OBSWSRequestError.new(@response[:requestType], @response[:requestStatus][:code], @response[:requestStatus][:comment])
48
52
  end
49
53
  @response[:responseData]
50
54
  rescue OBSWSRequestError => e
51
- err_msg = [
52
- "#{e.class.name}: #{e.message}",
53
- *e.backtrace
54
- ]
55
- logger.error(err_msg.join("\n"))
55
+ logger.error(["#{e.class.name}: #{e.message}", *e.backtrace].join("\n"))
56
56
  raise
57
57
  rescue WaitUtil::TimeoutError => e
58
- err_msg = [
59
- "#{e.class.name}: #{e.message}",
60
- *e.backtrace
61
- ]
62
- logger.error(err_msg)
63
- raise OBSWSError.new(err_msg)
58
+ logger.error(["#{e.class.name}: #{e.message}", *e.backtrace].join("\n"))
59
+ raise OBSWSError.new([e.message, *e.backtrace].join("\n"))
64
60
  end
65
61
 
66
62
  def get_version
data/lib/obsws/version.rb CHANGED
@@ -11,7 +11,7 @@ module OBSWS
11
11
  end
12
12
 
13
13
  def patch
14
- 3
14
+ 7
15
15
  end
16
16
 
17
17
  def to_a
data/lib/obsws.rb CHANGED
@@ -1,9 +1,10 @@
1
1
  require "digest/sha2"
2
2
  require "json"
3
- require "waitutil"
3
+ require "logger"
4
+ require "securerandom"
4
5
  require "socket"
6
+ require "waitutil"
5
7
  require "websocket/driver"
6
- require "logger"
7
8
 
8
9
  require_relative "obsws/logger"
9
10
  require_relative "obsws/driver"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: obsws
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.5.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - onyx_online