Class: RemoteDroid::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/remotedroid/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(hostx = '127.0.0.1', host: hostx, port: '5777', sps_host: 'sps.home', sps_port: '59000', device: nil) ⇒ Client

Returns a new instance of Client.



6
7
8
9
10
11
12
13
14
15
# File 'lib/remotedroid/client.rb', line 6

def initialize(hostx='127.0.0.1', host: hostx, port: '5777', 
               sps_host: 'sps.home', sps_port: '59000', device: nil)
  
  raise 'supply a device name' unless device
  
  @device = device
  @drb = OneDrb::Client.new host: host, port: port    
  @sps = SPSPub.new host: sps_host, port: sps_port
  
end

Instance Method Details

#ask_alexaObject

– helpful methods —————–



61
62
63
# File 'lib/remotedroid/client.rb', line 61

def ask_alexa()
  control.ask_alexa
end

#batteryObject



65
66
67
# File 'lib/remotedroid/client.rb', line 65

def battery()
  query.battery
end

#bluetoothObject



69
70
71
# File 'lib/remotedroid/client.rb', line 69

def bluetooth()
  control.bluetooth
end

#cell_towerObject



73
74
75
# File 'lib/remotedroid/client.rb', line 73

def cell_tower()
  query.cell_tower
end

#click(s) ⇒ Object



77
78
79
# File 'lib/remotedroid/client.rb', line 77

def click(s)
  control.click content: s
end

#controlObject



17
18
19
# File 'lib/remotedroid/client.rb', line 17

def control
  @drb.control @device
end

#control_media(option = 'Play/Pause') ⇒ Object



81
82
83
# File 'lib/remotedroid/client.rb', line 81

def control_media(option='Play/Pause')
  control.control_media({option: option})
end

#disable_airplane_modeObject



85
86
87
# File 'lib/remotedroid/client.rb', line 85

def disable_airplane_mode()
  control.disable_airplane_mode
end

#disable_bluetoothObject



89
90
91
# File 'lib/remotedroid/client.rb', line 89

def disable_bluetooth()
  control.disable_bluetooth
end

#disable_macro(macro) ⇒ Object



93
94
95
# File 'lib/remotedroid/client.rb', line 93

def disable_macro(macro)
  control.disable_macro macro
end

#disable_wifiObject



97
98
99
# File 'lib/remotedroid/client.rb', line 97

def disable_wifi()
  control.disable_wifi
end

#enable_airplane_modeObject



101
102
103
# File 'lib/remotedroid/client.rb', line 101

def enable_airplane_mode()
  control.enable_airplane_mode
end

#enable_bluetoothObject



105
106
107
# File 'lib/remotedroid/client.rb', line 105

def enable_bluetooth()
  control.enable_bluetooth
end

#enable_macro(macro) ⇒ Object



109
110
111
# File 'lib/remotedroid/client.rb', line 109

def enable_macro(macro)
  control.enable_macro macro
end

#enable_wifiObject



113
114
115
# File 'lib/remotedroid/client.rb', line 113

def enable_wifi()
  control.enable_wifi
end

#export(s) ⇒ Object



21
22
23
# File 'lib/remotedroid/client.rb', line 21

def export(s)
  @drb.export(s)
end

#fill_clipboard(text) ⇒ Object Also known as: copy



117
118
119
# File 'lib/remotedroid/client.rb', line 117

def fill_clipboard(text)
  control.fill_clipboard clipboard: text
end

#hotspot(state = nil) ⇒ Object



123
124
125
# File 'lib/remotedroid/client.rb', line 123

def hotspot(state=nil)      
  control.hotspot state
end

#invoke(s, *args) ⇒ Object



25
26
27
# File 'lib/remotedroid/client.rb', line 25

def invoke(s, *args)
  @drb.invoke(@device, s, *args)
end

#ipObject



189
190
191
# File 'lib/remotedroid/client.rb', line 189

def ip()
  query.ip
end

#last_locObject



127
128
129
# File 'lib/remotedroid/client.rb', line 127

def last_loc()
  query.last_loc
end


131
132
133
# File 'lib/remotedroid/client.rb', line 131

def last_loc_link()
  "<a href='%s' target='_blank'>map link</a>" % last_loc.link
end

#launch_activity(app) ⇒ Object Also known as: launch



135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/remotedroid/client.rb', line 135

def launch_activity(app)
        
  package = APPS[app]
  
  if package then
    control.launch_package package: package
  else       
    r = APPS.find {|k,v| k =~ /#{app}/i}
    control.launch_package(package: r[1]) if r
  end        

end

#launch_package(name) ⇒ Object



148
149
150
151
152
# File 'lib/remotedroid/client.rb', line 148

def launch_package(name)
  
  control.launch_package(package: name)

end

#locationObject



156
157
158
# File 'lib/remotedroid/client.rb', line 156

def location()
  query.location
end

#location_watch(refresh: '1 minute', interval: refresh, duration: '30 minutes') ⇒ Object



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/remotedroid/client.rb', line 160

def location_watch(refresh: '1 minute', interval: refresh, 
                   duration: '30 minutes')
  
  d = ChronicDuration.parse(duration)
  seconds = ChronicDuration.parse(interval)
  puts ("monitoring location every %s for %s" % [interval, duration]).info

  Thread.new do      
    
    t = Time.now + d

    begin

      query.location
      sleep seconds

    end until Time.now >= t
    
  end
  
end

#macrosObject



29
30
31
# File 'lib/remotedroid/client.rb', line 29

def macros()
  @drb.macros
end

#nextObject



193
194
195
# File 'lib/remotedroid/client.rb', line 193

def next()
  control_media('Next')
end

#open_website(url) ⇒ Object Also known as: goto, visit



182
183
184
# File 'lib/remotedroid/client.rb', line 182

def open_website(url)
  control.open_website url: url
end

#pauseObject



197
198
199
# File 'lib/remotedroid/client.rb', line 197

def pause()
  control_media('Pause')
end

#photoObject



209
210
211
# File 'lib/remotedroid/client.rb', line 209

def photo()
  take_picture
end

#playObject



201
202
203
# File 'lib/remotedroid/client.rb', line 201

def play()
  control_media('Play')
end

#play_pauseObject



205
206
207
# File 'lib/remotedroid/client.rb', line 205

def play_pause()
  control_media('Play/Pause')
end

#power_connected?Boolean

Returns:

  • (Boolean)


213
214
215
# File 'lib/remotedroid/client.rb', line 213

def power_connected?()
  query.power_connected?
end

#previousObject



217
218
219
# File 'lib/remotedroid/client.rb', line 217

def previous()
  control.control_media(option: 'Previous')
end

#query(id = nil) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/remotedroid/client.rb', line 33

def query(id=nil)
  
  return @drb.query(@device) unless id
  t = Time.now
  h = @drb.query(@device, id)
  h.merge({latency: (Time.now - t).round(3)})
  
end

#run_macro(name) ⇒ Object



42
43
44
45
# File 'lib/remotedroid/client.rb', line 42

def run_macro(name)
  a = @drb.run_macro name
  a.each {|msg| @sps.notice 'macrodroid/action: ' + msg }
end

#say(text) ⇒ Object



221
222
223
# File 'lib/remotedroid/client.rb', line 221

def say(text)
  control.speak_text text
end

#say_timeObject Also known as: saytime



225
226
227
# File 'lib/remotedroid/client.rb', line 225

def say_time()
  control.say_time
end

#screen(state = nil) ⇒ Object



231
232
233
# File 'lib/remotedroid/client.rb', line 231

def screen(state=nil)      
  control.screen state
end

#screen_offObject



239
240
241
# File 'lib/remotedroid/client.rb', line 239

def screen_off()
  screen :off
end

#screen_onObject



235
236
237
# File 'lib/remotedroid/client.rb', line 235

def screen_on()
  screen :on
end

#set_auto_rotate(state = nil) ⇒ Object



243
244
245
# File 'lib/remotedroid/client.rb', line 243

def set_auto_rotate(state=nil)
  control.set_auto_rotate state
end

#set_auto_rotate_offObject



251
252
253
# File 'lib/remotedroid/client.rb', line 251

def set_auto_rotate_off()
  control.set_auto_rotate 1
end

#set_auto_rotate_onObject



247
248
249
# File 'lib/remotedroid/client.rb', line 247

def set_auto_rotate_on()
  control.set_auto_rotate 0
end

#set_auto_rotate_toggleObject



255
256
257
# File 'lib/remotedroid/client.rb', line 255

def set_auto_rotate_toggle()
  control.set_auto_rotate 2
end

#stay_awakeObject



259
260
261
# File 'lib/remotedroid/client.rb', line 259

def stay_awake()
  control.stay_awake
end

#stay_awake_offObject Also known as: awake_off



263
264
265
# File 'lib/remotedroid/client.rb', line 263

def stay_awake_off()
  control.stay_awake_off
end

#stopObject



269
270
271
# File 'lib/remotedroid/client.rb', line 269

def stop()
  control_media(option: 'Stop')
end

#storeObject



51
52
53
# File 'lib/remotedroid/client.rb', line 51

def store()
  @drb.store
end

#syslogObject



55
56
57
# File 'lib/remotedroid/client.rb', line 55

def syslog()
  @drb.syslog
end

#take_picture(ftp_src: nil, fileout: '.') ⇒ Object Also known as: take_photo



273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
# File 'lib/remotedroid/client.rb', line 273

def take_picture(ftp_src: nil, fileout: '.')
  
  #screen.on
  #launch 'camera'
        
  if ftp_src then
    
    r = query.take_picture        
    # give the device a second to write the image to file
    sleep 1
    
    credentials, dir = ftp_src.match(/(ftp:\/\/[^\/]+)\/([^$]+)/).captures
    ftp = MyMediaFTP.new(credentials)
    ftp.cd dir
    filename = ftp.ls.sort_by {|x| x[:ctime]}.last[:name]
    ftp.cp filename, fileout
    
  else
    
    contro.take_picture
    
  end
  
end

#take_screenshot(ftp_src: nil, fileout: '.') ⇒ Object



300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
# File 'lib/remotedroid/client.rb', line 300

def take_screenshot(ftp_src: nil, fileout: '.')
  
  #screen.on
 
        
  if ftp_src then
     
    r = query.take_screenshot
    # give the device a second to write the image to file
    sleep 1
    
    credentials, dir = ftp_src.match(/(ftp:\/\/[^\/]+)\/([^$]+)/).captures
    ftp = MyMediaFTP.new(credentials)
    ftp.cd dir
    filename = ftp.ls.sort_by {|x| x[:ctime]}.last[:name]
    ftp.cp filename, fileout
    
  end
  
end

#toggle_airplane_modeObject



321
322
323
# File 'lib/remotedroid/client.rb', line 321

def toggle_airplane_mode()
  control.toggle_airplane_mode
end

#toggle_bluetoothObject



325
326
327
# File 'lib/remotedroid/client.rb', line 325

def toggle_bluetooth()
  control.toggle_bluetooth
end

#toggle_wifiObject



329
330
331
# File 'lib/remotedroid/client.rb', line 329

def toggle_wifi()
  control.toggle_wifi
end

#torchObject



333
334
335
# File 'lib/remotedroid/client.rb', line 333

def torch()
  control.torch
end

#update(key, val) ⇒ Object



47
48
49
# File 'lib/remotedroid/client.rb', line 47

def update(key, val)
  @drb.update key.to_sym, val
end

#vibrateObject



337
338
339
# File 'lib/remotedroid/client.rb', line 337

def vibrate
  control.vibrate
end

#voice_searchObject



341
342
343
# File 'lib/remotedroid/client.rb', line 341

def voice_search
  control.voice_search
end

#volObject



349
350
351
# File 'lib/remotedroid/client.rb', line 349

def vol()
  volume.music
end

#volume(context = nil) ⇒ Object



345
346
347
# File 'lib/remotedroid/client.rb', line 345

def volume(context=nil)      
  query.volume context
end