obsws 0.5.3 → 0.5.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +10 -4
- data/lib/obsws/base.rb +24 -5
- data/lib/obsws/req.rb +13 -17
- data/lib/obsws/version.rb +1 -1
- data/lib/obsws.rb +3 -2
- 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
@@ -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
|
-
|
38
|
-
|
39
|
-
|
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
|
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
|
-
|
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,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
|
-
|
13
|
-
|
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
|
-
|
40
|
-
@base_client.req(
|
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] ==
|
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
|
-
|
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
|
-
|
59
|
-
|
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
data/lib/obsws.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
require "digest/sha2"
|
2
2
|
require "json"
|
3
|
-
require "
|
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"
|