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.



644
645
646
647
# File 'lib/remotedroid.rb', line 644

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



649
650
651
652
653
654
655
656
657
658
659
660
661
# File 'lib/remotedroid.rb', line 649

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