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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ddfcc82f3a8213d04134762ce838d20cfef23f61fd12bfcdb8d414ca381aaae4
4
- data.tar.gz: 572f30bae6af2264b9a208eb567ceea95e95b65d6311831d7155f052147ce81f
3
+ metadata.gz: a79951b0215195512bd8972528425795f3893a3c9605009803f5583b36e54618
4
+ data.tar.gz: 4515b14d0bab1934e3eb1a8e5b626660a970ae1c6358c5ba2f47a6320562845b
5
5
  SHA512:
6
- metadata.gz: c4a6aa4c301fd4f0a339b1f6b06a629d1051499b0cba82485ccbb93428318066515f51cdfda61b0f09c7ebd7a6c3b7a601e08d9d91f95f9111f3166235484e6c
7
- data.tar.gz: 1b94ca2cf66e810b0a195fbe501518e6c87b0a26844c69303196a0f8cbe41770994d38e8613c3a7a612f723de7736b5e14afd2808fa6a70ef7dd3bfb7e5aff08
6
+ metadata.gz: b43b242dc256207ebf7f5ebe78e720416a68a4e9dcfc665de3a880b9a027e859db1ae805aeb9e363bb5a3f62487fb0e19ee8cda2ff2d871cec24ff82e4e7fda6
7
+ data.tar.gz: d13c2e1bfdd1931f251f52d42b2851040bb352ba7991ea5ec678dae5631349125440201b65e64a6c01d1d61f2419cac7911f2f64abd1765fab9870a5224bafab
data/lib/obsws/base.rb CHANGED
@@ -10,7 +10,7 @@ require_relative "mixin"
10
10
  module OBSWS
11
11
  class Base
12
12
  include Logging
13
- include Driver
13
+ include Driver::Director
14
14
  include Mixin::OPCodes
15
15
 
16
16
  attr_reader :closed
data/lib/obsws/driver.rb CHANGED
@@ -16,36 +16,38 @@ module OBSWS
16
16
  end
17
17
  end
18
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))
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
- private def start_driver
36
- Thread.new do
37
- @driver.start
36
+ private def start_driver
37
+ Thread.new do
38
+ @driver.start
38
39
 
39
- loop do
40
- @driver.parse(@socket.readpartial(4096))
41
- rescue EOFError
42
- break
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
- public def stop_driver
48
- @driver.close
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| @observers.append(o) }
46
+ observer.each { |o| observers << o }
44
47
  end
45
48
 
46
49
  def remove_observer(observer)
47
- @observers.delete(observer)
50
+ observers.delete(observer)
48
51
  end
49
52
 
50
53
  def notify_observers(event, data)
51
- if defined?(@observers)
52
- @observers.each do |o|
53
- if o.respond_to? "on_#{event.to_snake}"
54
- if data.empty?
55
- o.send("on_#{event.to_snake}")
56
- else
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.to_snake) { @resp[param] }
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.to_snake }
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
- class ::String
4
- def to_camel
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 to_snake
9
- gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
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
@@ -11,7 +11,7 @@ module OBSWS
11
11
  end
12
12
 
13
13
  def patch
14
- 1
14
+ 3
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.3.1
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - onyx_online