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.



663
664
665
666
667
# File 'lib/remotedroid.rb', line 663

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

Instance Method Details

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



669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
# File 'lib/remotedroid.rb', line 669

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