Class: RemoteDroid::ResponseSubscriber

Inherits:
SPSSub
  • Object
show all
Defined in:
lib/remotedroid.rb

Instance Method Summary collapse

Constructor Details

#initialize(host: 'sps.home', drb_host: '127.0.0.1') ⇒ ResponseSubscriber

Returns a new instance of ResponseSubscriber.



796
797
798
799
# File 'lib/remotedroid.rb', line 796

def initialize(host: 'sps.home', drb_host: '127.0.0.1')
  @remote = OneDrb::Client.new host: drb_host, port: '5777'    
  super(host: host)
end

Instance Method Details

#subscribe(topic: 'macrodroid/response') ⇒ Object



801
802
803
804
805
806
807
808
809
810
811
812
# File 'lib/remotedroid.rb', line 801

def subscribe(topic: 'macrodroid/response')
  
  super(topic: topic) do |msg|
    
    json, id = msg.split(/:\s+/,2).reverse
    h = JSON.parse(json, symbolize_names: true)
    id ||= h.keys.first
    @remote.update id.to_sym, h
    
  end
  
end