From d15418a660d6053708a94224a8bcd1bbfc73c922 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Wed, 26 Jul 2023 16:55:59 +0100 Subject: [PATCH] mixin only methods for directing the driver patch bump --- lib/obsws/base.rb | 2 +- lib/obsws/driver.rb | 56 +++++++++++++++++++++++--------------------- lib/obsws/version.rb | 2 +- 3 files changed, 31 insertions(+), 29 deletions(-) diff --git a/lib/obsws/base.rb b/lib/obsws/base.rb index b7f3cb4..fe21192 100644 --- a/lib/obsws/base.rb +++ b/lib/obsws/base.rb @@ -10,7 +10,7 @@ require_relative "mixin" module OBSWS class Base include Logging - include Driver + include Driver::Director include Mixin::OPCodes attr_reader :closed diff --git a/lib/obsws/driver.rb b/lib/obsws/driver.rb index 98d05d1..d38a291 100644 --- a/lib/obsws/driver.rb +++ b/lib/obsws/driver.rb @@ -16,36 +16,38 @@ module OBSWS end end - def setup_driver(host, port) - @socket = TCPSocket.new(host, port) - @driver = - WebSocket::Driver.client(Socket.new("ws://#{host}:#{port}", @socket)) - @driver.on :open do |msg| - logger.debug("driver socket open") - end - @driver.on :close do |msg| - logger.debug("driver socket closed") - @closed = true - end - @driver.on :message do |msg| - msg_handler(JSON.parse(msg.data, symbolize_names: true)) - end - end - - private def start_driver - Thread.new do - @driver.start - - loop do - @driver.parse(@socket.readpartial(4096)) - rescue EOFError - break + module Director + def setup_driver(host, port) + @socket = TCPSocket.new(host, port) + @driver = + WebSocket::Driver.client(Socket.new("ws://#{host}:#{port}", @socket)) + @driver.on :open do |msg| + logger.debug("driver socket open") + end + @driver.on :close do |msg| + logger.debug("driver socket closed") + @closed = true + end + @driver.on :message do |msg| + msg_handler(JSON.parse(msg.data, symbolize_names: true)) end end - end - public def stop_driver - @driver.close + private def start_driver + Thread.new do + @driver.start + + loop do + @driver.parse(@socket.readpartial(4096)) + rescue EOFError + break + end + end + end + + public def stop_driver + @driver.close + end end end end diff --git a/lib/obsws/version.rb b/lib/obsws/version.rb index 8ad7ab2..636cde6 100644 --- a/lib/obsws/version.rb +++ b/lib/obsws/version.rb @@ -11,7 +11,7 @@ module OBSWS end def patch - 1 + 2 end def to_a