Class: OBSWS::Base

Inherits:
Object
  • Object
show all
Includes:
Driver::Director, Logging, Mixin::OPCodes
Defined in:
lib/obsws/base.rb

Constant Summary

Constants included from Mixin::OPCodes

Mixin::OPCodes::EVENT, Mixin::OPCodes::HELLO, Mixin::OPCodes::IDENTIFIED, Mixin::OPCodes::IDENTIFY, Mixin::OPCodes::REIDENTIFY, Mixin::OPCodes::REQUEST, Mixin::OPCodes::REQUESTBATCH, Mixin::OPCodes::REQUESTBATCHRESPONSE, Mixin::OPCodes::REQUESTRESPONSE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Driver::Director

#setup_driver, #stop_driver

Methods included from Logging

#logger

Constructor Details

#initialize(**kwargs) ⇒ Base

Returns a new instance of Base.



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/obsws/base.rb', line 27

def initialize(**kwargs)
  host = kwargs[:host] || "localhost"
  port = kwargs[:port] || 4455
  @password = kwargs[:password] || ""
  @subs = kwargs[:subs] || 0
  @identified = Identified.new
  setup_driver(host, port) and start_driver
  WaitUtil.wait_for_condition(
    "successful identification",
    delay_sec: 0.01,
    timeout_sec: kwargs[:connect_timeout] || 3
  ) { @identified.state != :pending }
end

Instance Attribute Details

#closedObject (readonly)

Returns the value of attribute closed.



24
25
26
# File 'lib/obsws/base.rb', line 24

def closed
  @closed
end

#identifiedObject (readonly)

Returns the value of attribute identified.



24
25
26
# File 'lib/obsws/base.rb', line 24

def identified
  @identified
end

#updater=(value) ⇒ Object (writeonly)

Sets the attribute updater

Parameters:

  • value

    the value to set the attribute updater to.



25
26
27
# File 'lib/obsws/base.rb', line 25

def updater=(value)
  @updater = value
end

Instance Method Details

#req(id, type_, data = nil) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/obsws/base.rb', line 79

public def req(id, type_, data = nil)
  payload = {
    op: Mixin::OPCodes::REQUEST,
    d: {
      requestType: type_,
      requestId: id
    }
  }
  payload[:d][:requestData] = data if data
  logger.debug("sending request: #{payload}")
  @driver.text(JSON.generate(payload))
end