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



982
983
984
985
# File 'lib/remotedroid.rb', line 982

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/action') ⇒ Object



987
988
989
990
991
992
993
994
995
996
997
998
# File 'lib/remotedroid.rb', line 987

def subscribe(topic: 'macrodroid/action')
  
  super(topic: topic) do |msg|
    
    context, json = msg.split(/:\s+/,2)
    category, action = context.split('/',2)
    @remote.control.method(action.to_sym)\
        .call(JSON.parse(json, symbolize_names: true))
    
  end
  
end