Class: RemoteDroid::Client
- Inherits:
-
Object
- Object
- RemoteDroid::Client
- Defined in:
- lib/remotedroid/client.rb
Instance Method Summary collapse
-
#ask_alexa ⇒ Object
– helpful methods —————–.
- #battery ⇒ Object
- #bluetooth ⇒ Object
- #cell_tower ⇒ Object
- #click(s) ⇒ Object
- #control ⇒ Object
- #control_media(option = 'Play/Pause') ⇒ Object
- #disable_airplane_mode ⇒ Object
- #disable_bluetooth ⇒ Object
- #disable_macro(macro) ⇒ Object
- #disable_wifi ⇒ Object
- #enable_airplane_mode ⇒ Object
- #enable_bluetooth ⇒ Object
- #enable_macro(macro) ⇒ Object
- #enable_wifi ⇒ Object
- #export(s) ⇒ Object
- #fill_clipboard(text) ⇒ Object (also: #copy)
- #hotspot(state = nil) ⇒ Object
-
#initialize(hostx = '127.0.0.1', host: hostx, port: '5777', sps_host: 'sps.home', sps_port: '59000', device: nil) ⇒ Client
constructor
A new instance of Client.
- #invoke(s, *args) ⇒ Object
- #ip ⇒ Object
- #last_loc ⇒ Object
- #last_loc_link ⇒ Object
- #launch_activity(app) ⇒ Object (also: #launch)
- #launch_package(name) ⇒ Object
- #location ⇒ Object
- #location_watch(refresh: '1 minute', interval: refresh, duration: '30 minutes') ⇒ Object
- #macros ⇒ Object
- #next ⇒ Object
- #open_website(url) ⇒ Object (also: #goto, #visit)
- #pause ⇒ Object
- #photo ⇒ Object
- #play ⇒ Object
- #play_pause ⇒ Object
- #power_connected? ⇒ Boolean
- #previous ⇒ Object
- #query(id = nil) ⇒ Object
- #run_macro(name) ⇒ Object
- #say(text) ⇒ Object
- #say_time ⇒ Object (also: #saytime)
- #screen(state = nil) ⇒ Object
- #screen_off ⇒ Object
- #screen_on ⇒ Object
- #set_auto_rotate(state = nil) ⇒ Object
- #set_auto_rotate_off ⇒ Object
- #set_auto_rotate_on ⇒ Object
- #set_auto_rotate_toggle ⇒ Object
- #stay_awake ⇒ Object
- #stay_awake_off ⇒ Object (also: #awake_off)
- #stop ⇒ Object
- #store ⇒ Object
- #syslog ⇒ Object
- #take_picture(ftp_src: nil, fileout: '.') ⇒ Object (also: #take_photo)
- #take_screenshot(ftp_src: nil, fileout: '.') ⇒ Object
- #toggle_airplane_mode ⇒ Object
- #toggle_bluetooth ⇒ Object
- #toggle_wifi ⇒ Object
- #torch ⇒ Object
- #update(key, val) ⇒ Object
- #vibrate ⇒ Object
- #voice_search ⇒ Object
- #vol ⇒ Object
- #volume(context = nil) ⇒ Object
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_alexa ⇒ Object
– helpful methods —————–
61 62 63 |
# File 'lib/remotedroid/client.rb', line 61 def ask_alexa() control.ask_alexa end |
#battery ⇒ Object
65 66 67 |
# File 'lib/remotedroid/client.rb', line 65 def battery() query.battery end |
#bluetooth ⇒ Object
69 70 71 |
# File 'lib/remotedroid/client.rb', line 69 def bluetooth() control.bluetooth end |
#cell_tower ⇒ Object
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 |
#control ⇒ Object
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_mode ⇒ Object
85 86 87 |
# File 'lib/remotedroid/client.rb', line 85 def disable_airplane_mode() control.disable_airplane_mode end |
#disable_bluetooth ⇒ Object
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_wifi ⇒ Object
97 98 99 |
# File 'lib/remotedroid/client.rb', line 97 def disable_wifi() control.disable_wifi end |
#enable_airplane_mode ⇒ Object
101 102 103 |
# File 'lib/remotedroid/client.rb', line 101 def enable_airplane_mode() control.enable_airplane_mode end |
#enable_bluetooth ⇒ Object
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_wifi ⇒ Object
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 |
#ip ⇒ Object
189 190 191 |
# File 'lib/remotedroid/client.rb', line 189 def ip() query.ip end |
#last_loc ⇒ Object
127 128 129 |
# File 'lib/remotedroid/client.rb', line 127 def last_loc() query.last_loc end |
#last_loc_link ⇒ Object
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 |
#location ⇒ Object
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 |
#macros ⇒ Object
29 30 31 |
# File 'lib/remotedroid/client.rb', line 29 def macros() @drb.macros end |
#next ⇒ Object
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 |
#pause ⇒ Object
197 198 199 |
# File 'lib/remotedroid/client.rb', line 197 def pause() control_media('Pause') end |
#photo ⇒ Object
209 210 211 |
# File 'lib/remotedroid/client.rb', line 209 def photo() take_picture end |
#play ⇒ Object
201 202 203 |
# File 'lib/remotedroid/client.rb', line 201 def play() control_media('Play') end |
#play_pause ⇒ Object
205 206 207 |
# File 'lib/remotedroid/client.rb', line 205 def play_pause() control_media('Play/Pause') end |
#power_connected? ⇒ Boolean
213 214 215 |
# File 'lib/remotedroid/client.rb', line 213 def power_connected?() query.power_connected? end |
#previous ⇒ Object
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_time ⇒ Object 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_off ⇒ Object
239 240 241 |
# File 'lib/remotedroid/client.rb', line 239 def screen_off() screen :off end |
#screen_on ⇒ Object
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_off ⇒ Object
251 252 253 |
# File 'lib/remotedroid/client.rb', line 251 def set_auto_rotate_off() control.set_auto_rotate 1 end |
#set_auto_rotate_on ⇒ Object
247 248 249 |
# File 'lib/remotedroid/client.rb', line 247 def set_auto_rotate_on() control.set_auto_rotate 0 end |
#set_auto_rotate_toggle ⇒ Object
255 256 257 |
# File 'lib/remotedroid/client.rb', line 255 def set_auto_rotate_toggle() control.set_auto_rotate 2 end |
#stay_awake ⇒ Object
259 260 261 |
# File 'lib/remotedroid/client.rb', line 259 def stay_awake() control.stay_awake end |
#stay_awake_off ⇒ Object Also known as: awake_off
263 264 265 |
# File 'lib/remotedroid/client.rb', line 263 def stay_awake_off() control.stay_awake_off end |
#stop ⇒ Object
269 270 271 |
# File 'lib/remotedroid/client.rb', line 269 def stop() control_media(option: 'Stop') end |
#store ⇒ Object
51 52 53 |
# File 'lib/remotedroid/client.rb', line 51 def store() @drb.store end |
#syslog ⇒ Object
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_mode ⇒ Object
321 322 323 |
# File 'lib/remotedroid/client.rb', line 321 def toggle_airplane_mode() control.toggle_airplane_mode end |
#toggle_bluetooth ⇒ Object
325 326 327 |
# File 'lib/remotedroid/client.rb', line 325 def toggle_bluetooth() control.toggle_bluetooth end |
#toggle_wifi ⇒ Object
329 330 331 |
# File 'lib/remotedroid/client.rb', line 329 def toggle_wifi() control.toggle_wifi end |
#torch ⇒ Object
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 |
#vibrate ⇒ Object
337 338 339 |
# File 'lib/remotedroid/client.rb', line 337 def vibrate control.vibrate end |
#voice_search ⇒ Object
341 342 343 |
# File 'lib/remotedroid/client.rb', line 341 def voice_search control.voice_search end |
#vol ⇒ Object
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 |