remotedroid 0.6.2 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cb2eedf64071cbde99c208add4801a434aa0d3ec0a8750a7c2b94d283918b580
4
- data.tar.gz: b47344083acbdd1ae6fa674249e22312e80aa91c654e2cd51150fa4cd27657d5
3
+ metadata.gz: d8b216c60a929b3c6ece03a4b5979da738a0e3f7fb2994060a605391ab8068b9
4
+ data.tar.gz: d5bfed22b7fbc59767cc1a3af2597cc95b05ddbf8aca80420305a6bdbc12960c
5
5
  SHA512:
6
- metadata.gz: a131d644b51b337e8a6ea54164306f612cae6989591eb00b0756e497ae2fa7f630e11b5c7484d95f3e12f6dbc5130403c469bf8fd96a398fdc3c82ea98dcd4d3
7
- data.tar.gz: 8148f0cae8dbecabcca111dbcbad14f0c2884c026c21c3bea3ca2f420681fe3d2f3678ca226272b9344da277f6eefea1e650086d816e81016b1389c3f3542ea1
6
+ metadata.gz: 1fb42e16c68052d50a4ac532a88997fd723178142951dfb4aaaf2da6458128ff7fedea58d56b20020dac6b631f8a439371e4ac231b43ba9dd61db96aef1dd9f0
7
+ data.tar.gz: 763dc18a3b896bb77b53d1dddf70e4b839a314301e00642e96c326b36f0cdf2d7beed025df3a7232f6879fd097f715ff813fac62913a7988a57d5deec1543b8f
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -571,10 +571,10 @@ module RemoteDroid
571
571
 
572
572
  class Server
573
573
 
574
- def initialize(s, drb_host: '127.0.0.1', deviceid: nil)
574
+ def initialize(s, drb_host: '127.0.0.1', devices: nil, debug: false)
575
575
 
576
576
  md = MacroDroid.new(s)
577
- rdc = RemoteDroid::Controller.new(md, deviceid: deviceid)
577
+ rdc = RemoteDroid::Controller.new(md, devices: devices, debug: debug)
578
578
  @drb = OneDrb::Server.new host: drb_host, port: '5777', obj: rdc
579
579
 
580
580
  end
@@ -586,20 +586,25 @@ module RemoteDroid
586
586
  end
587
587
 
588
588
  class TriggerSubscriber < SPSSub
589
+ using ColouredText
589
590
 
590
591
  def initialize(host: 'sps.home', drb_host: '127.0.0.1')
591
592
  @remote = OneDrb::Client.new host: drb_host, port: '5777'
592
593
  super(host: host)
594
+ puts 'TriggerSubscriber'.highlight
593
595
  end
594
596
 
595
- def subscribe(topic: 'macrodroid/trigger')
597
+ def subscribe(topic: 'macrodroid/#/trigger')
596
598
 
597
- super(topic: topic) do |msg|
599
+ super(topic: topic) do |msg, topic|
598
600
 
601
+ dev_id = topic.split('/')[1]
599
602
  trigger, json = msg.split(/:\s+/,2)
603
+
600
604
  a = @remote.trigger_fired trigger.to_sym,
601
605
  JSON.parse(json, symbolize_names: true)
602
- a.each {|msg| self.notice 'macrodroid/action: ' + msg }
606
+
607
+ a.each {|msg| self.notice "macrodroid/%s/action: %s" % [dev_id, msg] }
603
608
 
604
609
  end
605
610
  end
@@ -607,13 +612,15 @@ module RemoteDroid
607
612
  end
608
613
 
609
614
  class ActionSubscriber < SPSSub
615
+ using ColouredText
610
616
 
611
617
  def initialize(host: 'sps.home', drb_host: '127.0.0.1')
612
618
  @remote = OneDrb::Client.new host: drb_host, port: '5777'
613
619
  super(host: host)
620
+ puts 'ActionSubscriber'.highlight
614
621
  end
615
622
 
616
- def subscribe(topic: 'macrodroid/action')
623
+ def subscribe(topic: 'macrodroid/#/action')
617
624
 
618
625
  super(topic: topic) do |msg|
619
626
 
@@ -622,10 +629,21 @@ module RemoteDroid
622
629
 
623
630
  h = JSON.parse(json, symbolize_names: true)
624
631
 
625
- if action == 'force_macro_run' and h[:serverside] then
632
+ if h[:serverside]then
626
633
 
627
- a = @remote.run_macro(h)
628
- a.each {|msg| self.notice 'macrodroid/action: ' + msg }
634
+ if action == 'force_macro_run' then
635
+
636
+ a = @remote.run_macro(h)
637
+ a.each {|msg| self.notice 'macrodroid/action: ' + msg }
638
+
639
+ else
640
+
641
+ puts 'action: ' + action.inspect
642
+ puts 'h: ' + h.inspect
643
+ r = @remote.local(action.to_sym, h)
644
+ puts 'r: ' + r.inspect
645
+
646
+ end
629
647
 
630
648
  else
631
649
 
@@ -640,27 +658,57 @@ module RemoteDroid
640
658
  end
641
659
 
642
660
  class ResponseSubscriber < SPSSub
661
+ using ColouredText
643
662
 
644
663
  def initialize(host: 'sps.home', drb_host: '127.0.0.1')
645
664
  @remote = OneDrb::Client.new host: drb_host, port: '5777'
646
665
  super(host: host)
666
+ puts 'ResponseSubscriber'.highlight
647
667
  end
648
668
 
649
- def subscribe(topic: 'macrodroid/response')
669
+ def subscribe(topic: 'macrodroid/#/response')
650
670
 
651
671
  super(topic: topic) do |msg|
652
672
 
673
+ #puts 'msg: ' + msg.inspect
653
674
  json, id = msg.split(/:\s+/,2).reverse
654
675
 
655
676
  h = JSON.parse(json, symbolize_names: true)
656
677
  id ||= h.keys.first
678
+ #puts '->' + [id, h].inspect
657
679
  @remote.update id.to_sym, h
658
680
 
659
681
  end
660
682
 
661
683
  end
662
684
 
663
- end
685
+ end
686
+
687
+
688
+ class Clients
689
+ using ColouredText
690
+
691
+ attr_reader :devices
692
+
693
+ def initialize(hostx='127.0.0.1', host: hostx, port: '5777',
694
+ sps_host: 'sps.home', sps_port: '59000')
695
+
696
+ @drb = OneDrb::Client.new host: host, port: port
697
+ #sleep 3
698
+ @devices = @drb.devices.keys.inject({}) do |r, name|
699
+ obj = RemoteDroid::Client.new(host: host, port: port,
700
+ sps_host: sps_host, sps_port: sps_port, device: name)
701
+ r.merge!(name => obj)
702
+ end
703
+
704
+ end
705
+
706
+ def device(name)
707
+ idx = @devices.index name.to_sym
708
+ @devices[idx] if idx
709
+ end
710
+
711
+ end
664
712
  end
665
713
 
666
714
  # PASTE_END
@@ -4,15 +4,18 @@ module RemoteDroid
4
4
  using ColouredText
5
5
 
6
6
  def initialize(hostx='127.0.0.1', host: hostx, port: '5777',
7
- sps_host: 'sps.home', sps_port: '59000')
7
+ sps_host: 'sps.home', sps_port: '59000', device: nil)
8
8
 
9
+ raise 'supply a device name' unless device
10
+
11
+ @device = device
9
12
  @drb = OneDrb::Client.new host: host, port: port
10
13
  @sps = SPSPub.new host: sps_host, port: sps_port
11
14
 
12
15
  end
13
16
 
14
17
  def control
15
- @drb.control
18
+ @drb.control @device
16
19
  end
17
20
 
18
21
  def export(s)
@@ -20,7 +23,7 @@ module RemoteDroid
20
23
  end
21
24
 
22
25
  def invoke(s, *args)
23
- @drb.invoke(s, *args)
26
+ @drb.invoke(@device, s, *args)
24
27
  end
25
28
 
26
29
  def macros()
@@ -29,9 +32,9 @@ module RemoteDroid
29
32
 
30
33
  def query(id=nil)
31
34
 
32
- return @drb.query unless id
35
+ return @drb.query(@device) unless id
33
36
  t = Time.now
34
- h = @drb.query(id)
37
+ h = @drb.query(@device, id)
35
38
  h.merge({latency: (Time.now - t).round(3)})
36
39
 
37
40
  end
@@ -45,7 +45,7 @@ module RemoteDroid
45
45
 
46
46
  def self.on()
47
47
  self.enable
48
- end
48
+ end
49
49
 
50
50
  def self.disable()
51
51
  http_exec 'set-auto-rotate', {state: 1}
@@ -2,15 +2,20 @@ module RemoteDroid
2
2
 
3
3
  class Controller
4
4
 
5
- attr_reader :model, :control, :syslog
5
+ attr_reader :model, :syslog, :devices
6
6
  attr_accessor :title, :macros, :store
7
7
 
8
- def initialize(mcs, model=MODEL, deviceid: nil, debug: false)
8
+ def initialize(mcs, model=MODEL, devices: {}, debug: false)
9
9
 
10
10
  @debug = debug
11
11
  @syslog = []
12
-
13
- @control = Control.new(deviceid)
12
+
13
+ @devices = devices
14
+
15
+ @devices.each do |key, deviceid|
16
+ devices[key] = Control.new(deviceid)
17
+ end
18
+
14
19
  @macros = mcs.macros
15
20
 
16
21
  if model then
@@ -18,7 +23,7 @@ module RemoteDroid
18
23
  end
19
24
 
20
25
  @store = {}
21
- @query = Query.new(self)
26
+ #@query = Query.new(self)
22
27
 
23
28
  # enable the required triggers on the Android device
24
29
  #
@@ -35,6 +40,10 @@ module RemoteDroid
35
40
  =end
36
41
  end
37
42
 
43
+ def control(device)
44
+ @devices[device]
45
+ end
46
+
38
47
  def delete_all()
39
48
  @macros = []
40
49
  end
@@ -46,12 +55,20 @@ module RemoteDroid
46
55
 
47
56
  end
48
57
 
49
- def invoke(name, options={})
58
+ def invoke(device, name, options={})
50
59
 
51
- if @control.respond_to? name.to_sym then
52
- @control.method(name.to_sym).call(options)
60
+ if control(device).respond_to? name.to_sym then
61
+ control(device).method(name.to_sym).call(options)
53
62
  else
54
- @control.http_exec name.to_sym, options
63
+ control(device).http_exec name.to_sym, options
64
+ end
65
+ end
66
+
67
+ def local(action, options={})
68
+
69
+ case action.to_sym
70
+ when :open_web_page
71
+ open(options[:url_to_open]).read
55
72
  end
56
73
  end
57
74
 
@@ -63,9 +80,9 @@ module RemoteDroid
63
80
  @model.op
64
81
  end
65
82
 
66
- def query(id=nil)
83
+ def query(device, id=nil)
67
84
 
68
- return @query unless id
85
+ return Query.new(device, self) unless id
69
86
 
70
87
  @store[id] = nil
71
88
 
@@ -79,20 +96,22 @@ module RemoteDroid
79
96
 
80
97
  # send http request via macrodroid.com API
81
98
 
82
- if id.downcase.to_sym == :location then
83
- @control.http_exec id
99
+ identifier, options = if id.downcase.to_sym == :location then
100
+ id
84
101
  elsif sys.include? id
85
- @control.http_exec :'query-setting-system', {qvar: id}
102
+ [:'query-setting-system', {qvar: id}]
86
103
  elsif global.include? id
87
- @control.http_exec :'query-setting-global', {qvar: id}
104
+ [:'query-setting-global', {qvar: id}]
88
105
  elsif secure.include? id
89
- @control.http_exec :'query-setting-secure', {qvar: id}
106
+ [:'query-setting-secure', {qvar: id}]
90
107
  elsif id.downcase.to_sym == :'take-picture'
91
- @control.http_exec id
108
+ id
92
109
  else
93
- @control.http_exec :query, {qvar: id}
110
+ [:query, {qvar: id}]
94
111
  end
95
112
 
113
+ control(device).http_exec identifier, options
114
+
96
115
  # wait for the local variable to be updated
97
116
  # timeout after 5 seoncds
98
117
  t = Time.now
@@ -155,6 +174,11 @@ module RemoteDroid
155
174
 
156
175
  def update(id, val)
157
176
 
177
+ if @debug then
178
+ puts 'inside update'
179
+ puts [id, val].inspect
180
+ end
181
+
158
182
  key = if %i(location take-picture).include? id
159
183
  id
160
184
  else
@@ -4,8 +4,8 @@ module RemoteDroid
4
4
 
5
5
  attr_accessor :locations
6
6
 
7
- def initialize(callback)
8
- @callback = callback
7
+ def initialize(device, callback)
8
+ @device, @callback = device, callback
9
9
  @locations = []
10
10
  end
11
11
 
@@ -45,7 +45,7 @@ module RemoteDroid
45
45
 
46
46
  def location()
47
47
 
48
- r = @callback.query(:location)
48
+ r = @callback.query(@device, :location)
49
49
  return r if r.nil? or r.empty? or r[:coords].nil?
50
50
 
51
51
  r[:coords] = r[:coords].split(',')
@@ -62,11 +62,11 @@ module RemoteDroid
62
62
  end
63
63
 
64
64
  def take_picture()
65
- @callback.query(:'take-picture')
65
+ @callback.query(@device, :'take-picture')
66
66
  end
67
67
 
68
68
  def take_screenshot()
69
- @callback.query(:'take-screenshot')
69
+ @callback.query(@device, :'take-screenshot')
70
70
  end
71
71
 
72
72
  def volume(context=nil)
@@ -93,7 +93,7 @@ module RemoteDroid
93
93
  private
94
94
 
95
95
  def q(id)
96
- @callback.query(id)[id]
96
+ @callback.query(@device, id)[id]
97
97
  end
98
98
 
99
99
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remotedroid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -35,7 +35,7 @@ cert_chain:
35
35
  io3WPRDjULC924M5S8wbrus31v2AUjqFBPvmHr7caf/VHErWypV482xcDhWt1eif
36
36
  0G2k2ptozXcBS9odsqGUTb5N
37
37
  -----END CERTIFICATE-----
38
- date: 2020-10-30 00:00:00.000000000 Z
38
+ date: 2020-11-01 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: onedrb
metadata.gz.sig CHANGED
Binary file