obsws 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/obsws/base.rb +4 -46
- data/lib/obsws/driver.rb +51 -0
- data/lib/obsws/event.rb +1 -1
- data/lib/obsws/req.rb +1 -1
- data/lib/obsws/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ddfcc82f3a8213d04134762ce838d20cfef23f61fd12bfcdb8d414ca381aaae4
|
4
|
+
data.tar.gz: 572f30bae6af2264b9a208eb567ceea95e95b65d6311831d7155f052147ce81f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4a6aa4c301fd4f0a339b1f6b06a629d1051499b0cba82485ccbb93428318066515f51cdfda61b0f09c7ebd7a6c3b7a601e08d9d91f95f9111f3166235484e6c
|
7
|
+
data.tar.gz: 1b94ca2cf66e810b0a195fbe501518e6c87b0a26844c69303196a0f8cbe41770994d38e8613c3a7a612f723de7736b5e14afd2808fa6a70ef7dd3bfb7e5aff08
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/onyx-and-iris/obsws-ruby/blob/dev/LICENSE)
|
3
3
|
[![Ruby Code Style](https://img.shields.io/badge/code_style-standard-violet.svg)](https://github.com/standardrb/standard)
|
4
4
|
|
5
|
-
#
|
5
|
+
# Ruby Clients for OBS Studio WebSocket v5.0
|
6
6
|
|
7
7
|
## Requirements
|
8
8
|
|
data/lib/obsws/base.rb
CHANGED
@@ -1,29 +1,16 @@
|
|
1
|
-
require "socket"
|
2
|
-
require "websocket/driver"
|
3
1
|
require "digest/sha2"
|
4
2
|
require "json"
|
5
3
|
require "waitutil"
|
6
4
|
|
7
|
-
require_relative "
|
5
|
+
require_relative "driver"
|
8
6
|
require_relative "error"
|
9
7
|
require_relative "logger"
|
8
|
+
require_relative "mixin"
|
10
9
|
|
11
10
|
module OBSWS
|
12
|
-
class Socket
|
13
|
-
attr_reader :url
|
14
|
-
|
15
|
-
def initialize(url, socket)
|
16
|
-
@url = url
|
17
|
-
@socket = socket
|
18
|
-
end
|
19
|
-
|
20
|
-
def write(s)
|
21
|
-
@socket.write(s)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
11
|
class Base
|
26
12
|
include Logging
|
13
|
+
include Driver
|
27
14
|
include Mixin::OPCodes
|
28
15
|
|
29
16
|
attr_reader :closed
|
@@ -34,20 +21,7 @@ module OBSWS
|
|
34
21
|
port = kwargs[:port] || 4455
|
35
22
|
@password = kwargs[:password] || ""
|
36
23
|
@subs = kwargs[:subs] || 0
|
37
|
-
|
38
|
-
@socket = TCPSocket.new(host, port)
|
39
|
-
@driver =
|
40
|
-
WebSocket::Driver.client(Socket.new("ws://#{host}:#{port}", @socket))
|
41
|
-
@driver.on :open do |msg|
|
42
|
-
logger.debug("driver socket open")
|
43
|
-
end
|
44
|
-
@driver.on :close do |msg|
|
45
|
-
logger.debug("driver socket closed")
|
46
|
-
@closed = true
|
47
|
-
end
|
48
|
-
@driver.on :message do |msg|
|
49
|
-
msg_handler(JSON.parse(msg.data, symbolize_names: true))
|
50
|
-
end
|
24
|
+
setup_driver(host, port)
|
51
25
|
start_driver
|
52
26
|
WaitUtil.wait_for_condition(
|
53
27
|
"successful identification",
|
@@ -56,22 +30,6 @@ module OBSWS
|
|
56
30
|
) { @identified }
|
57
31
|
end
|
58
32
|
|
59
|
-
private def start_driver
|
60
|
-
Thread.new do
|
61
|
-
@driver.start
|
62
|
-
|
63
|
-
loop do
|
64
|
-
@driver.parse(@socket.readpartial(4096))
|
65
|
-
rescue EOFError
|
66
|
-
break
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
public def stop_driver
|
72
|
-
@driver.close
|
73
|
-
end
|
74
|
-
|
75
33
|
private
|
76
34
|
|
77
35
|
def auth_token(salt:, challenge:)
|
data/lib/obsws/driver.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require "socket"
|
2
|
+
require "websocket/driver"
|
3
|
+
|
4
|
+
module OBSWS
|
5
|
+
module Driver
|
6
|
+
class Socket
|
7
|
+
attr_reader :url
|
8
|
+
|
9
|
+
def initialize(url, socket)
|
10
|
+
@url = url
|
11
|
+
@socket = socket
|
12
|
+
end
|
13
|
+
|
14
|
+
def write(s)
|
15
|
+
@socket.write(s)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def setup_driver(host, port)
|
20
|
+
@socket = TCPSocket.new(host, port)
|
21
|
+
@driver =
|
22
|
+
WebSocket::Driver.client(Socket.new("ws://#{host}:#{port}", @socket))
|
23
|
+
@driver.on :open do |msg|
|
24
|
+
logger.debug("driver socket open")
|
25
|
+
end
|
26
|
+
@driver.on :close do |msg|
|
27
|
+
logger.debug("driver socket closed")
|
28
|
+
@closed = true
|
29
|
+
end
|
30
|
+
@driver.on :message do |msg|
|
31
|
+
msg_handler(JSON.parse(msg.data, symbolize_names: true))
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private def start_driver
|
36
|
+
Thread.new do
|
37
|
+
@driver.start
|
38
|
+
|
39
|
+
loop do
|
40
|
+
@driver.parse(@socket.readpartial(4096))
|
41
|
+
rescue EOFError
|
42
|
+
break
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
public def stop_driver
|
48
|
+
@driver.close
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/obsws/event.rb
CHANGED
@@ -71,7 +71,7 @@ module OBSWS
|
|
71
71
|
def initialize(**kwargs)
|
72
72
|
kwargs[:subs] ||= SUBS::LOW_VOLUME
|
73
73
|
@base_client = Base.new(**kwargs)
|
74
|
-
logger.info("#{self}
|
74
|
+
logger.info("#{self} successfully identified with server")
|
75
75
|
@base_client.updater = ->(op_code, data) {
|
76
76
|
if op_code == Mixin::OPCodes::EVENT
|
77
77
|
logger.debug("received: #{data}")
|
data/lib/obsws/req.rb
CHANGED
@@ -16,7 +16,7 @@ module OBSWS
|
|
16
16
|
|
17
17
|
def initialize(**kwargs)
|
18
18
|
@base_client = Base.new(**kwargs)
|
19
|
-
logger.info("#{self}
|
19
|
+
logger.info("#{self} successfully identified with server")
|
20
20
|
@base_client.updater = ->(op_code, data) {
|
21
21
|
logger.debug("response received: #{data}")
|
22
22
|
@response = data if op_code == Mixin::OPCodes::REQUESTRESPONSE
|
data/lib/obsws/version.rb
CHANGED
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.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- onyx_online
|
@@ -106,6 +106,7 @@ files:
|
|
106
106
|
- README.md
|
107
107
|
- lib/obsws.rb
|
108
108
|
- lib/obsws/base.rb
|
109
|
+
- lib/obsws/driver.rb
|
109
110
|
- lib/obsws/error.rb
|
110
111
|
- lib/obsws/event.rb
|
111
112
|
- lib/obsws/logger.rb
|