Class: RemoteDroid::ActionSubscriber

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') ⇒ ActionSubscriber

Returns a new instance of ActionSubscriber.



617
618
619
620
621
# File 'lib/remotedroid.rb', line 617

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

Instance Method Details

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



623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
# File 'lib/remotedroid.rb', line 623

def subscribe(topic: 'macrodroid/#/action')
  
  super(topic: topic) do |msg|
    
    context, json = msg.split(/:\s+/,2)
    category, action = context.split('/',2)
    
    h = JSON.parse(json, symbolize_names: true)
    
    if h[:serverside]then
      
      if action == 'force_macro_run' then
        
        a = @remote.run_macro(h)
        a.each {|msg| self.notice 'macrodroid/action: ' + msg }
        
      else
        
        puts 'action: ' + action.inspect
        puts 'h: ' + h.inspect
        r = @remote.local(action.to_sym, h)
        puts 'r: ' + r.inspect
        
      end

    else
      
      @remote.control.method(action.to_sym).call(h)
      
    end
    
  end
  
end