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 +4 -4
- data/README.md +3 -1
- data/lib/obsws/base.rb +23 -4
- data/lib/obsws/req.rb +9 -3
- data/lib/obsws/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 78061cca710f6c790eacbbfce83036818edbe3c30791783af1f9131ef7407f91
|
4
|
+
data.tar.gz: e7399380cb61847004f1ff29fc5dbf0bc9f55edaa3063a89d99c089e9259c8f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
-
|
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 =
|
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])
|
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