obsws 0.5.6 → 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: 0e1082183fb2605b7ca64747dcd88930516b4132b02f142afa7bb6db58e62120
4
- data.tar.gz: 752365a78828d329a6d765a8920398efdf09a426122cc0e7b0380c8db27f9d5a
3
+ metadata.gz: 78061cca710f6c790eacbbfce83036818edbe3c30791783af1f9131ef7407f91
4
+ data.tar.gz: e7399380cb61847004f1ff29fc5dbf0bc9f55edaa3063a89d99c089e9259c8f2
5
5
  SHA512:
6
- metadata.gz: 812133a0bf0019e5cf59c6bcae577c256b862bc497df97f2f1265e88b0c6616277b2afa44f376ae932137b2baac499cca0acf4dbf5d139e15baac268fc629818
7
- data.tar.gz: a7ff0fe86ac3d988beee0d6ff2d31fd3b8e235b189afe9265e65d190bbb10953e85e7106578190fd4ece5e4e171d13ecf0aeefb16bd16d719ac203da62449799
6
+ metadata.gz: d7a6c5fc25ffc88c888d18c55e35a1410ac7780e4c64adf46a8dd52cf10a9ad2416de9acfffb7f33c2836e988103468dfc30336984c0908af11055b5dd6de60d
7
+ data.tar.gz: c65f732267e7bc4219b491f5e6ec3e5dcc6c6a36d0b891932bbdcff339dddcffea2156ef0d5fc855abdad0915c01f14262c50a33beb7842885f9895a8ff7d2f8
data/README.md CHANGED
@@ -119,7 +119,9 @@ If a connection attempt fails or times out an `OBSWSConnectionError` will be rai
119
119
 
120
120
  If a request fails an `OBSWSRequestError` will be raised with a status code.
121
121
 
122
- - 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`
123
125
 
124
126
  For a full list of status codes refer to [Codes](https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md#requeststatus)
125
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
37
  timeout_sec: kwargs[:connect_timeout] || 3
20
- ) { @identified }
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,6 +7,11 @@ 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
17
  logger.error("#{e.class.name}: #{e.message}")
@@ -43,11 +48,12 @@ module OBSWS
43
48
  timeout_sec: 3
44
49
  ) { @response[:requestId] == uuid }
45
50
  unless @response[:requestStatus][:result]
46
- OBSWSRequestError.new(@response[:requestType], @response[:requestStatus][:code], @response[:requestStatus][:comment]) => e
47
- logger.error(["#{e.class.name}: #{e.message}", *e.backtrace].join("\n"))
48
- raise e
51
+ raise OBSWSRequestError.new(@response[:requestType], @response[:requestStatus][:code], @response[:requestStatus][:comment])
49
52
  end
50
53
  @response[:responseData]
54
+ rescue OBSWSRequestError => e
55
+ logger.error(["#{e.class.name}: #{e.message}", *e.backtrace].join("\n"))
56
+ raise
51
57
  rescue WaitUtil::TimeoutError => e
52
58
  logger.error(["#{e.class.name}: #{e.message}", *e.backtrace].join("\n"))
53
59
  raise OBSWSError.new([e.message, *e.backtrace].join("\n"))
data/lib/obsws/version.rb CHANGED
@@ -11,7 +11,7 @@ module OBSWS
11
11
  end
12
12
 
13
13
  def patch
14
- 6
14
+ 7
15
15
  end
16
16
 
17
17
  def to_a
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.6
4
+ version: 0.5.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - onyx_online