mixin only methods for directing the driver

patch bump
This commit is contained in:
onyx-and-iris 2023-07-26 16:55:59 +01:00
parent 2883fd42cc
commit d15418a660
3 changed files with 31 additions and 29 deletions

View File

@ -10,7 +10,7 @@ require_relative "mixin"
module OBSWS module OBSWS
class Base class Base
include Logging include Logging
include Driver include Driver::Director
include Mixin::OPCodes include Mixin::OPCodes
attr_reader :closed attr_reader :closed

View File

@ -16,36 +16,38 @@ module OBSWS
end end
end end
def setup_driver(host, port) module Director
@socket = TCPSocket.new(host, port) def setup_driver(host, port)
@driver = @socket = TCPSocket.new(host, port)
WebSocket::Driver.client(Socket.new("ws://#{host}:#{port}", @socket)) @driver =
@driver.on :open do |msg| WebSocket::Driver.client(Socket.new("ws://#{host}:#{port}", @socket))
logger.debug("driver socket open") @driver.on :open do |msg|
end logger.debug("driver socket open")
@driver.on :close do |msg| end
logger.debug("driver socket closed") @driver.on :close do |msg|
@closed = true logger.debug("driver socket closed")
end @closed = true
@driver.on :message do |msg| end
msg_handler(JSON.parse(msg.data, symbolize_names: true)) @driver.on :message do |msg|
end msg_handler(JSON.parse(msg.data, symbolize_names: true))
end
private def start_driver
Thread.new do
@driver.start
loop do
@driver.parse(@socket.readpartial(4096))
rescue EOFError
break
end end
end end
end
public def stop_driver private def start_driver
@driver.close 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 end
end end

View File

@ -11,7 +11,7 @@ module OBSWS
end end
def patch def patch
1 2
end end
def to_a def to_a