obsws 0.0.1 → 0.0.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: 339b5706222511d0cf272eff7040f45dc5bc1cffdfdc6b6d0cc59ea299c325e1
4
- data.tar.gz: 2070c51a27e764297d2555bd958411fd8ee06c49f98bd09fa6144f7fba5790c8
3
+ metadata.gz: 459330fa7270cc31f26449b15ceb03e53130a7499f3272a9a9d17d8ac7de0b7f
4
+ data.tar.gz: 46897d76b4c62720f776aabb2fea69d47fadc9a0c1d1b0041d090738e2a9c394
5
5
  SHA512:
6
- metadata.gz: c80761585030c73bd304de37ead5ea8f5260116f7e2acb6a15549d920695be579c0fc0ffa9f0485569ffd56f4c11b6ca027711eeadb2ecb81c8b9b3016e68396
7
- data.tar.gz: 13fc659eb70544b51555cb9f68608927f64671377f550ae78c3d9a83b60de2f42050d17403ae72aeb701525fc15e48a5086d37f05c780b4055a24cfe252bd0a1
6
+ metadata.gz: a9bf8c54c209f1b18422babb02fcc631f773e0a5d46c9b8af49ba1a6e5e3077de1b89e1ce57cbc36fb5e868c41503a57d49292cc5bcb970c39127493bb1be3b5
7
+ data.tar.gz: 5959a9b71dceaf3af1fdbe624828e22631e45c8845e2ce232e9083565b9d62aa294690212ecc8b35f56083bb39eed94c346acf787f854414af072edbf3c9b2c8
data/CHANGELOG.md CHANGED
@@ -0,0 +1,17 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ Before any major/minor/patch bump all unit tests will be run to verify they pass.
9
+
10
+ ## [0.0.1] - 2021-10-22
11
+
12
+ ### Added
13
+
14
+ - Initial Commit
15
+ - Base class, Request and Event client classes.
16
+ - Unit tests
17
+ - README.md
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Onyx and Iris
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1,3 +1,4 @@
1
+ [![Gem Version](https://badge.fury.io/rb/obsws.svg)](https://badge.fury.io/rb/obsws)
1
2
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/onyx-and-iris/voicemeeter-api-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
 
@@ -17,7 +18,7 @@
17
18
  pass `host`, `port` and `password` as keyword arguments.
18
19
 
19
20
  ```ruby
20
- require_relative "lib/obsws"
21
+ require "obsws"
21
22
 
22
23
  def main
23
24
  r_client =
data/lib/obsws/base.rb CHANGED
@@ -37,11 +37,8 @@ module OBSWS
37
37
  @socket = TCPSocket.new(host, port)
38
38
  @driver =
39
39
  WebSocket::Driver.client(Socket.new("ws://#{host}:#{port}", @socket))
40
- @ready = false
41
- @closed = false
42
40
  @driver.on :open do |msg|
43
41
  LOGGER.debug("driver socket open")
44
- @ready = true
45
42
  end
46
43
  @driver.on :close do |msg|
47
44
  LOGGER.debug("driver socket closed")
@@ -51,21 +48,23 @@ module OBSWS
51
48
  LOGGER.debug("received [#{msg}] passing to handler")
52
49
  msg_handler(JSON.parse(msg.data, symbolize_names: true))
53
50
  end
54
- Thread.new { start_driver }
51
+ start_driver
55
52
  WaitUtil.wait_for_condition(
56
- "driver socket ready",
53
+ "waiting successful identification",
57
54
  delay_sec: 0.01,
58
- timeout_sec: 0.5
59
- ) { @ready }
55
+ timeout_sec: 3
56
+ ) { @identified }
60
57
  end
61
58
 
62
59
  def start_driver
63
- @driver.start
60
+ Thread.new do
61
+ @driver.start
64
62
 
65
- loop do
66
- @driver.parse(@socket.readpartial(4096))
67
- rescue EOFError
68
- break
63
+ loop do
64
+ @driver.parse(@socket.readpartial(4096))
65
+ rescue EOFError
66
+ break
67
+ end
69
68
  end
70
69
  end
71
70
 
@@ -75,29 +74,33 @@ module OBSWS
75
74
  )
76
75
  end
77
76
 
78
- def authenticate(auth)
79
- token = auth_token(**auth)
77
+ def authenticate(auth = nil)
80
78
  payload = {
81
79
  op: Mixin::OPCodes::IDENTIFY,
82
80
  d: {
83
81
  rpcVersion: 1,
84
- authentication: token,
85
82
  eventSubscriptions: @subs
86
83
  }
87
84
  }
85
+ payload[:d][:authentication] = auth_token(**auth) if auth
88
86
  @driver.text(JSON.generate(payload))
89
87
  end
90
88
 
91
89
  def msg_handler(data)
92
- op_code = data[:op]
93
- case op_code
90
+ case data[:op]
94
91
  when Mixin::OPCodes::HELLO
92
+ if data[:d].key? :authentication
93
+ LOGGER.debug("initiating authentication")
94
+ else
95
+ LOGGER.debug("authentication disabled... skipping.")
96
+ end
95
97
  authenticate(data[:d][:authentication])
96
98
  when Mixin::OPCodes::IDENTIFIED
97
- LOGGER.debug("Authentication successful")
99
+ LOGGER.debug("client succesfully identified with server")
100
+ @identified = true
98
101
  when Mixin::OPCodes::EVENT, Mixin::OPCodes::REQUESTRESPONSE
99
102
  changed
100
- notify_observers(op_code, data[:d])
103
+ notify_observers(data[:op], data[:d])
101
104
  end
102
105
  end
103
106
 
data/lib/obsws/req.rb CHANGED
@@ -51,6 +51,10 @@ module OBSWS
51
51
  raise OBSWSError.new(error.join("\n"))
52
52
  end
53
53
  @response[:responseData]
54
+ rescue WaitUtil::TimeoutError
55
+ msg = "no response with matching id received"
56
+ LOGGER.error(msg)
57
+ raise OBSWSError.new(msg)
54
58
  end
55
59
 
56
60
  def get_version
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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: obsws
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
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-22 00:00:00.000000000 Z
11
+ date: 2022-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: observer
@@ -106,15 +106,17 @@ dependencies:
106
106
  - - ">="
107
107
  - !ruby/object:Gem::Version
108
108
  version: 11.2.2
109
- description: A Ruby wrapper around the OBS Websocket v5 protocol
109
+ description: A Ruby wrapper around OBS Websocket v5
110
110
  email: code@onyxandiris.online
111
111
  executables: []
112
112
  extensions: []
113
113
  extra_rdoc_files:
114
114
  - README.md
115
115
  - CHANGELOG.md
116
+ - LICENSE
116
117
  files:
117
118
  - CHANGELOG.md
119
+ - LICENSE
118
120
  - README.md
119
121
  - lib/obsws.rb
120
122
  - lib/obsws/base.rb