obsws 0.3.1 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/obsws/base.rb +1 -1
- data/lib/obsws/driver.rb +26 -24
- data/lib/obsws/event.rb +13 -12
- data/lib/obsws/mixin.rb +3 -3
- data/lib/obsws/util.rb +6 -5
- 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: a79951b0215195512bd8972528425795f3893a3c9605009803f5583b36e54618
|
4
|
+
data.tar.gz: 4515b14d0bab1934e3eb1a8e5b626660a970ae1c6358c5ba2f47a6320562845b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b43b242dc256207ebf7f5ebe78e720416a68a4e9dcfc665de3a880b9a027e859db1ae805aeb9e363bb5a3f62487fb0e19ee8cda2ff2d871cec24ff82e4e7fda6
|
7
|
+
data.tar.gz: d13c2e1bfdd1931f251f52d42b2851040bb352ba7991ea5ec678dae5631349125440201b65e64a6c01d1d61f2419cac7911f2f64abd1765fab9870a5224bafab
|
data/lib/obsws/base.rb
CHANGED
data/lib/obsws/driver.rb
CHANGED
@@ -16,36 +16,38 @@ module OBSWS
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
19
|
+
module Director
|
20
|
+
def setup_driver(host, port)
|
21
|
+
@socket = TCPSocket.new(host, port)
|
22
|
+
@driver =
|
23
|
+
WebSocket::Driver.client(Socket.new("ws://#{host}:#{port}", @socket))
|
24
|
+
@driver.on :open do |msg|
|
25
|
+
logger.debug("driver socket open")
|
26
|
+
end
|
27
|
+
@driver.on :close do |msg|
|
28
|
+
logger.debug("driver socket closed")
|
29
|
+
@closed = true
|
30
|
+
end
|
31
|
+
@driver.on :message do |msg|
|
32
|
+
msg_handler(JSON.parse(msg.data, symbolize_names: true))
|
33
|
+
end
|
32
34
|
end
|
33
|
-
end
|
34
35
|
|
35
|
-
|
36
|
-
|
37
|
-
|
36
|
+
private def start_driver
|
37
|
+
Thread.new do
|
38
|
+
@driver.start
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
40
|
+
loop do
|
41
|
+
@driver.parse(@socket.readpartial(4096))
|
42
|
+
rescue EOFError
|
43
|
+
break
|
44
|
+
end
|
43
45
|
end
|
44
46
|
end
|
45
|
-
end
|
46
47
|
|
47
|
-
|
48
|
-
|
48
|
+
public def stop_driver
|
49
|
+
@driver.close
|
50
|
+
end
|
49
51
|
end
|
50
52
|
end
|
51
53
|
end
|
data/lib/obsws/event.rb
CHANGED
@@ -35,27 +35,28 @@ module OBSWS
|
|
35
35
|
end
|
36
36
|
|
37
37
|
module Callbacks
|
38
|
-
include Util
|
38
|
+
include Util::String
|
39
|
+
|
40
|
+
def observers
|
41
|
+
@observers ||= []
|
42
|
+
end
|
39
43
|
|
40
44
|
def add_observer(observer)
|
41
|
-
@observers = [] unless defined?(@observers)
|
42
45
|
observer = [observer] if !observer.respond_to? :each
|
43
|
-
observer.each { |o|
|
46
|
+
observer.each { |o| observers << o }
|
44
47
|
end
|
45
48
|
|
46
49
|
def remove_observer(observer)
|
47
|
-
|
50
|
+
observers.delete(observer)
|
48
51
|
end
|
49
52
|
|
50
53
|
def notify_observers(event, data)
|
51
|
-
|
52
|
-
|
53
|
-
if
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
o.send("on_#{event.to_snake}", data)
|
58
|
-
end
|
54
|
+
observers.each do |o|
|
55
|
+
if o.respond_to? "on_#{snakecase(event)}"
|
56
|
+
if data.empty?
|
57
|
+
o.send("on_#{snakecase(event)}")
|
58
|
+
else
|
59
|
+
o.send("on_#{snakecase(event)}", data)
|
59
60
|
end
|
60
61
|
end
|
61
62
|
end
|
data/lib/obsws/mixin.rb
CHANGED
@@ -3,11 +3,11 @@ require_relative "util"
|
|
3
3
|
module OBSWS
|
4
4
|
module Mixin
|
5
5
|
module Meta
|
6
|
-
include Util
|
6
|
+
include Util::String
|
7
7
|
|
8
8
|
def make_field_methods(*params)
|
9
9
|
params.each do |param|
|
10
|
-
define_singleton_method(param.to_s
|
10
|
+
define_singleton_method(snakecase(param.to_s)) { @resp[param] }
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
@@ -23,7 +23,7 @@ module OBSWS
|
|
23
23
|
|
24
24
|
def empty? = @fields.empty?
|
25
25
|
|
26
|
-
def attrs = @fields.map { |f| f.to_s
|
26
|
+
def attrs = @fields.map { |f| snakecase(f.to_s) }
|
27
27
|
end
|
28
28
|
|
29
29
|
class Response < MetaObject
|
data/lib/obsws/util.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
module OBSWS
|
2
2
|
module Util
|
3
|
-
|
4
|
-
def
|
5
|
-
split("_").map(&:capitalize).join
|
3
|
+
module String
|
4
|
+
def camelcase(s)
|
5
|
+
s.split("_").map(&:capitalize).join
|
6
6
|
end
|
7
7
|
|
8
|
-
def
|
9
|
-
|
8
|
+
def snakecase(s)
|
9
|
+
s
|
10
|
+
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
10
11
|
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
11
12
|
.downcase
|
12
13
|
end
|
data/lib/obsws/version.rb
CHANGED