obsws 0.3.3 → 0.4.0

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: c275787361111b1b84f2f5023d5d24e45b174540a8e687aaaae2fa647b89eecc
4
+ data.tar.gz: 738122bc2be93730ef117240c467ec261ab6918c406dea273eefc134d5f74362
5
5
  SHA512:
6
- metadata.gz: b43b242dc256207ebf7f5ebe78e720416a68a4e9dcfc665de3a880b9a027e859db1ae805aeb9e363bb5a3f62487fb0e19ee8cda2ff2d871cec24ff82e4e7fda6
7
- data.tar.gz: d13c2e1bfdd1931f251f52d42b2851040bb352ba7991ea5ec678dae5631349125440201b65e64a6c01d1d61f2419cac7911f2f64abd1765fab9870a5224bafab
6
+ metadata.gz: 121d5bf831969d5bd92244efb4c6ae94fdea7e6a47b16c9b7bbee80626e6739664433bb04e3225aef2eaa759127ee074841e05b430331c3bd987762c8623f15c
7
+ data.tar.gz: e67e598037d689469263721e2408eacebd6469e32a5b55e50f43876efe33d5b3b581e99ec2d804ed28549079f6b4855c76e8508e65e46d504bca12e75e32fff9
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/event.rb CHANGED
@@ -43,7 +43,7 @@ module OBSWS
43
43
 
44
44
  def add_observer(observer)
45
45
  observer = [observer] if !observer.respond_to? :each
46
- observer.each { |o| observers << o }
46
+ observer.each { |o| observers << o unless observers.include? o }
47
47
  end
48
48
 
49
49
  def remove_observer(observer)
@@ -52,15 +52,18 @@ module OBSWS
52
52
 
53
53
  def notify_observers(event, data)
54
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)
55
+ if o.is_a? Method
56
+ if o.name.to_s == "on_#{snakecase(event)}"
57
+ data.empty? ? o.call : o.call(data)
60
58
  end
59
+ elsif o.respond_to? "on_#{snakecase(event)}"
60
+ data.empty? ? o.send("on_#{snakecase(event)}") : o.send("on_#{snakecase(event)}", data)
61
61
  end
62
62
  end
63
63
  end
64
+
65
+ alias_method :register, :add_observer
66
+ alias_method :deregister, :remove_observer
64
67
  end
65
68
 
66
69
  class Client
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
+ 0
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.0
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-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: websocket-driver