obsws 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -1
- data/lib/obsws/base.rb +9 -13
- data/lib/obsws/event.rb +5 -0
- data/lib/obsws/mixin.rb +2 -2
- data/lib/obsws/req.rb +5 -0
- data/lib/obsws/version.rb +2 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8812e43e45759a458a445608809725e4a270daa04a3b715997541eed5bc85e5b
|
4
|
+
data.tar.gz: 0500dfc0223ad3f489016791fc0ca51800ec903d0bf7e57305216ff0844ee722
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef31376738aa182535f924e6981dab5eb8b83ec0e8254335d15e6fbab6ce952638c43c9769f21bd50c79b4b4e61750a7d16bdd2dc3910636b7e44957177bfdb2
|
7
|
+
data.tar.gz: fb4f85815ecfce661e4c46ba63bf008b4eb3c3d89d728a646b1a9c3ce40f22dea1ea00ded2b272abf82d4bb53e79ac275f1345ba87de45e2e4beb2d57f611f82
|
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
[![
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/obsws.svg)](https://badge.fury.io/rb/obsws)
|
2
|
+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/onyx-and-iris/obsws-ruby/blob/dev/LICENSE)
|
2
3
|
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/plugin-ruby)
|
3
4
|
|
4
5
|
# A Ruby wrapper around OBS Studio WebSocket v5.0
|
@@ -10,6 +11,19 @@
|
|
10
11
|
- With the release of OBS Studio version 28, Websocket plugin is included by default. But it should be manually installed for earlier versions of OBS.
|
11
12
|
- Ruby 3.0 or greater
|
12
13
|
|
14
|
+
## Installation
|
15
|
+
|
16
|
+
### Bundler
|
17
|
+
|
18
|
+
```
|
19
|
+
bundle add 'obsws'
|
20
|
+
bundle install
|
21
|
+
```
|
22
|
+
|
23
|
+
### Gem
|
24
|
+
|
25
|
+
`gem install 'obsws'`
|
26
|
+
|
13
27
|
## `Use`
|
14
28
|
|
15
29
|
#### Example `main.rb`
|
data/lib/obsws/base.rb
CHANGED
@@ -50,10 +50,10 @@ module OBSWS
|
|
50
50
|
end
|
51
51
|
start_driver
|
52
52
|
WaitUtil.wait_for_condition(
|
53
|
-
"waiting
|
53
|
+
"waiting successful identification",
|
54
54
|
delay_sec: 0.01,
|
55
55
|
timeout_sec: 3
|
56
|
-
) { @
|
56
|
+
) { @identified }
|
57
57
|
end
|
58
58
|
|
59
59
|
def start_driver
|
@@ -74,32 +74,28 @@ module OBSWS
|
|
74
74
|
)
|
75
75
|
end
|
76
76
|
|
77
|
-
def
|
78
|
-
|
77
|
+
def identify(auth)
|
78
|
+
LOGGER.info("initiating authentication") if auth
|
79
79
|
payload = {
|
80
80
|
op: Mixin::OPCodes::IDENTIFY,
|
81
81
|
d: {
|
82
82
|
rpcVersion: 1,
|
83
|
-
authentication: token,
|
84
83
|
eventSubscriptions: @subs
|
85
84
|
}
|
86
85
|
}
|
87
|
-
|
86
|
+
payload[:d][:authentication] = auth_token(**auth) if auth
|
88
87
|
@driver.text(JSON.generate(payload))
|
89
88
|
end
|
90
89
|
|
91
90
|
def msg_handler(data)
|
92
|
-
|
93
|
-
case op_code
|
91
|
+
case data[:op]
|
94
92
|
when Mixin::OPCodes::HELLO
|
95
|
-
|
96
|
-
authenticate(data[:d][:authentication])
|
93
|
+
identify(data[:d][:authentication])
|
97
94
|
when Mixin::OPCodes::IDENTIFIED
|
98
|
-
|
99
|
-
@authenticated = true
|
95
|
+
@identified = true
|
100
96
|
when Mixin::OPCodes::EVENT, Mixin::OPCodes::REQUESTRESPONSE
|
101
97
|
changed
|
102
|
-
notify_observers(
|
98
|
+
notify_observers(data[:op], data[:d])
|
103
99
|
end
|
104
100
|
end
|
105
101
|
|
data/lib/obsws/event.rb
CHANGED
@@ -77,9 +77,14 @@ module OBSWS
|
|
77
77
|
def initialize(**kwargs)
|
78
78
|
kwargs[:subs] = SUBS.low_volume
|
79
79
|
@base_client = Base.new(**kwargs)
|
80
|
+
LOGGER.info("#{self} succesfully identified with server")
|
80
81
|
@base_client.add_observer(self)
|
81
82
|
end
|
82
83
|
|
84
|
+
def to_s
|
85
|
+
"#{self.class.name.split("::").last(2).join("::")}"
|
86
|
+
end
|
87
|
+
|
83
88
|
def update(op_code, data)
|
84
89
|
if op_code == Mixin::OPCodes::EVENT
|
85
90
|
event = data[:eventType]
|
data/lib/obsws/mixin.rb
CHANGED
@@ -5,7 +5,7 @@ module OBSWS
|
|
5
5
|
module Meta
|
6
6
|
include Util
|
7
7
|
|
8
|
-
def
|
8
|
+
def make_field_methods(*params)
|
9
9
|
params.each do |param|
|
10
10
|
define_singleton_method(param.to_s.to_snake) { @resp[param] }
|
11
11
|
end
|
@@ -18,7 +18,7 @@ module OBSWS
|
|
18
18
|
def initialize(resp, fields)
|
19
19
|
@resp = resp
|
20
20
|
@fields = fields
|
21
|
-
self.
|
21
|
+
self.make_field_methods *fields
|
22
22
|
end
|
23
23
|
|
24
24
|
def empty? = @fields.empty?
|
data/lib/obsws/req.rb
CHANGED
@@ -14,10 +14,15 @@ module OBSWS
|
|
14
14
|
|
15
15
|
def initialize(**kwargs)
|
16
16
|
@base_client = Base.new(**kwargs)
|
17
|
+
LOGGER.info("#{self} succesfully identified with server")
|
17
18
|
@base_client.add_observer(self)
|
18
19
|
@response = { requestId: 0 }
|
19
20
|
end
|
20
21
|
|
22
|
+
def to_s
|
23
|
+
"#{self.class.name.split("::").last(2).join("::")}"
|
24
|
+
end
|
25
|
+
|
21
26
|
def run
|
22
27
|
yield
|
23
28
|
ensure
|
data/lib/obsws/version.rb
CHANGED
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.0
|
4
|
+
version: 0.1.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: 2022-10-
|
11
|
+
date: 2022-10-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: observer
|
@@ -146,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
146
146
|
- !ruby/object:Gem::Version
|
147
147
|
version: '0'
|
148
148
|
requirements: []
|
149
|
-
rubygems_version: 3.3.
|
149
|
+
rubygems_version: 3.3.12
|
150
150
|
signing_key:
|
151
151
|
specification_version: 4
|
152
152
|
summary: OBS Websocket v5 wrapper
|