obsws 0.3.3 → 0.4.2

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: a79951b0215195512bd8972528425795f3893a3c9605009803f5583b36e54618
4
- data.tar.gz: 4515b14d0bab1934e3eb1a8e5b626660a970ae1c6358c5ba2f47a6320562845b
3
+ metadata.gz: 9ccc4e19da8ea0f009572ea75a5f47b414c7d4e5d50955ae856eb4063081ca70
4
+ data.tar.gz: 2a5ec2b70667d2b80483a46c898920ed9a97d937478e45ff5f643b8e28919a18
5
5
  SHA512:
6
- metadata.gz: b43b242dc256207ebf7f5ebe78e720416a68a4e9dcfc665de3a880b9a027e859db1ae805aeb9e363bb5a3f62487fb0e19ee8cda2ff2d871cec24ff82e4e7fda6
7
- data.tar.gz: d13c2e1bfdd1931f251f52d42b2851040bb352ba7991ea5ec678dae5631349125440201b65e64a6c01d1d61f2419cac7911f2f64abd1765fab9870a5224bafab
6
+ metadata.gz: '0875434a8e3c58d82fbc0deb3be4478ab495000b37ee6282d321e32963d623dcc241c62a0257ef009ab6981ef134138e6e72ab76a1f552d46a3b928f1acc21d4'
7
+ data.tar.gz: 3b944c1a4ac416f12a0f5d821d73979ac4f344fa2ae186f04a0d00998bc5adf9fcf744e874d4b52f273232aec174a2da134a94f5bcd24d522d25e2b778c7bd9f
data/README.md CHANGED
@@ -16,14 +16,10 @@
16
16
  ### Bundler
17
17
 
18
18
  ```
19
- bundle add 'obsws'
19
+ bundle add obsws
20
20
  bundle install
21
21
  ```
22
22
 
23
- ### Gem
24
-
25
- `gem install 'obsws'`
26
-
27
23
  ## `Use`
28
24
 
29
25
  #### Example `main.rb`
@@ -67,23 +63,28 @@ For a full list of requests refer to [Requests](https://github.com/obsproject/ob
67
63
 
68
64
  ### Events
69
65
 
70
- Register an observer class and define `on_` methods for events. Method names should match the api event but snake cased.
66
+ Register `on_` callback methods. Method names should match the api event but snake cased.
71
67
 
72
68
  example:
73
69
 
74
70
  ```ruby
75
71
  class Observer
76
72
  def initialize
77
- @e_client = OBSWS::Events::Client.new(**kwargs)
78
- # register class with the event client
79
- @e_client.add_observer(self)
73
+ @e_client = OBSWS::Events::Client.new(host: "localhost", port: 4455, password: "strongpassword")
74
+ # register callback methods with the Event client
75
+ @e_client.register(
76
+ [
77
+ method(:on_current_program_scene_changed),
78
+ method(:on_input_mute_state_changed)
79
+ ]
80
+ )
80
81
  end
81
82
 
82
83
  # define "on_" event methods.
83
- def on_current_program_scene_changed
84
+ def on_current_program_scene_changed(data)
84
85
  ...
85
86
  end
86
- def on_input_mute_state_changed
87
+ def on_input_mute_state_changed(data)
87
88
  ...
88
89
  end
89
90
  ...
data/lib/obsws/base.rb CHANGED
@@ -21,8 +21,7 @@ module OBSWS
21
21
  port = kwargs[:port] || 4455
22
22
  @password = kwargs[:password] || ""
23
23
  @subs = kwargs[:subs] || 0
24
- setup_driver(host, port)
25
- start_driver
24
+ setup_driver(host, port) and start_driver
26
25
  WaitUtil.wait_for_condition(
27
26
  "successful identification",
28
27
  delay_sec: 0.01,
data/lib/obsws/event.rb CHANGED
@@ -42,25 +42,30 @@ module OBSWS
42
42
  end
43
43
 
44
44
  def add_observer(observer)
45
- observer = [observer] if !observer.respond_to? :each
46
- observer.each { |o| observers << o }
45
+ observer = [observer] unless observer.respond_to? :each
46
+ observer.each { |o| observers << o unless observers.include? o }
47
47
  end
48
48
 
49
49
  def remove_observer(observer)
50
- observers.delete(observer)
50
+ observer = [observer] unless observer.respond_to? :each
51
+ observers.reject! { |o| observer.include? o }
51
52
  end
52
53
 
53
- def notify_observers(event, data)
54
+ private def notify_observers(event, data)
54
55
  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)
56
+ if o.is_a? Method
57
+ if o.name.to_s == "on_#{snakecase(event)}"
58
+ data.empty? ? o.call : o.call(data)
60
59
  end
60
+ elsif o.respond_to? "on_#{snakecase(event)}"
61
+ data.empty? ? o.send("on_#{snakecase(event)}") : o.send("on_#{snakecase(event)}", data)
61
62
  end
62
63
  end
63
64
  end
65
+
66
+ alias_method :callbacks, :observers
67
+ alias_method :register, :add_observer
68
+ alias_method :deregister, :remove_observer
64
69
  end
65
70
 
66
71
  class Client
data/lib/obsws/logger.rb CHANGED
@@ -3,7 +3,7 @@ require "logger"
3
3
  module OBSWS
4
4
  module Logging
5
5
  def logger
6
- @logger = Logger.new($stdout, level: ENV.fetch("OBSWS_LOG_LEVEL", "WARN"))
6
+ @logger ||= Logger.new($stdout, level: ENV.fetch("OBSWS_LOG_LEVEL", "WARN"))
7
7
  @logger.progname = instance_of?(::Module) ? name : self.class.name
8
8
  @logger
9
9
  end
data/lib/obsws/mixin.rb CHANGED
@@ -26,11 +26,11 @@ module OBSWS
26
26
  def attrs = @fields.map { |f| snakecase(f.to_s) }
27
27
  end
28
28
 
29
- class Response < MetaObject
30
- end
29
+ class Response < MetaObject; end
30
+ # Represents a request response object
31
31
 
32
- class Data < MetaObject
33
- end
32
+ class Data < MetaObject; end
33
+ # Represents an event data object
34
34
 
35
35
  module TearDown
36
36
  def stop_driver
data/lib/obsws/req.rb CHANGED
@@ -47,12 +47,12 @@ module OBSWS
47
47
  delay_sec: 0.001,
48
48
  timeout_sec: 3
49
49
  ) { @response[:requestId] == id }
50
- if !@response[:requestStatus][:result]
50
+ unless @response[:requestStatus][:result]
51
51
  error = [
52
52
  "Request #{@response[:requestType]} returned code #{@response[:requestStatus][:code]}"
53
53
  ]
54
54
  if @response[:requestStatus].key?(:comment)
55
- error += ["With message: #{@response[:requestStatus][:comment]}"]
55
+ error << ["With message: #{@response[:requestStatus][:comment]}"]
56
56
  end
57
57
  raise OBSWSError.new(error.join("\n"))
58
58
  end
data/lib/obsws/version.rb CHANGED
@@ -7,11 +7,11 @@ module OBSWS
7
7
  end
8
8
 
9
9
  def minor
10
- 3
10
+ 4
11
11
  end
12
12
 
13
13
  def patch
14
- 3
14
+ 2
15
15
  end
16
16
 
17
17
  def to_a
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: obsws
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - onyx_online
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-26 00:00:00.000000000 Z
11
+ date: 2023-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: websocket-driver