obsws 0.5.6 → 0.5.8

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: e289e262d4b31c03c7df28ba6d638c39d04e362fb0173f2535e0bf60f188bd41
4
+ data.tar.gz: '0925f7d4d8695401d27dfb0d01df2c4fe5751d82d04c9bec752c981c52e1be8e'
5
5
  SHA512:
6
- metadata.gz: 812133a0bf0019e5cf59c6bcae577c256b862bc497df97f2f1265e88b0c6616277b2afa44f376ae932137b2baac499cca0acf4dbf5d139e15baac268fc629818
7
- data.tar.gz: a7ff0fe86ac3d988beee0d6ff2d31fd3b8e235b189afe9265e65d190bbb10953e85e7106578190fd4ece5e4e171d13ecf0aeefb16bd16d719ac203da62449799
6
+ metadata.gz: 79e9065b4190dd974195079e31dc191fb7412fa143297b1f6dacedb1aae2100ded74abac9c1553b7fc92dce2987f40615d1101dfe5eab987f982a3bd3a7d87dd
7
+ data.tar.gz: 5137c5ca260beaedcda8936532bd4d04b6154d2c4b7e4a005e5eb12ab070e5502c7231acf2539a90304170bb75ebdd2fdf96a5a7f9bf49a4eafbb6f3370a945f
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/event.rb CHANGED
@@ -71,6 +71,11 @@ module OBSWS
71
71
  def initialize(**kwargs)
72
72
  kwargs[:subs] ||= SUBS::LOW_VOLUME
73
73
  @base_client = Base.new(**kwargs)
74
+ unless @base_client.identified.state == :identified
75
+ err_msg = @base_client.identified.error_message
76
+ logger.error(err_msg)
77
+ raise OBSWSConnectionError.new(err_msg)
78
+ end
74
79
  logger.info("#{self} successfully identified with server")
75
80
  rescue Errno::ECONNREFUSED, WaitUtil::TimeoutError => e
76
81
  msg = "#{e.class.name}: #{e.message}"
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
+ 8
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.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - onyx_online