mozilla / node-firefox

node.js modules for interacting with Firefox via the DevTools remote protocol

Home Page:https://www.npmjs.org/package/firefox

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

node-firefox to work on FirefoxOS devices

arcturus opened this issue · comments

Right now we can just use the simulator if we want to use node-firefox modules, but gaia build system could get better if we can actually perform all this nice actions on real devices :)

commented

Yeah, I'd use that feature too!

@arcturus You did some work on adb+node. Do you think we could use it? My idea was this, you tell me if it could work:

  • Using adb.js (supposing it's called like that) we detect a device
  • We can then set up port forwarding to localhost:someport
  • Once we have this port listening we can use node-firefox-connect

Does it make sense?

commented

Expanding more on this:

  • We could have a find-devices module, returning the device ids that adb detects
  • Then a set-port-forwarding or similar module using the device ids found above? Edit: maybe we also need a module to unset the forwarding

What is cool about this is that we could push to all the connected devices!!!

!!!

I can't find other conversations where I mentioned this, but this summer I attempted to implement that into fxos-ports nicola/fx-ports#3, that is the place where I think it should be with some flags (adb=true)

commented

I made a module for installing an app to all ADB connected devices:
https://github.com/sole/install-to-adb

I am not 100% sure if that module is the right approach as it's very limited (BUT EFFECTIVE!) in what it does: pushing an app to devices.

The issue is that you have to run the port forwarding step before you get to connect to anything, and before you do that you need to enumerate the adb devices. Not sure if we want to hide all this, but am also not sure what would gaia need. Push just an app? @arcturus halp!

I was kind of scratching my head about this over the past week or so, too. But, my problem is that not all adb connected devices are FxOS devices. Some will be, you know, Android devices. This is especially annoying for Cordova, which is meant to work cross-platform.

I started peeking inside the ADB Helper addon. It seems to speculatively connects to the forwarded port and tries to get the FxOS version from the debugging API. If that fails, then it ignores that device as FxOS. The annoyance with that, though, is you get the connection permission prompt on every device every time unless you disable it with WebIDE first.

So, adb devices -l will list things like this:

List of devices attached
ZX1G229PZV             device usb:1D111400 product:shamu model:Nexus_6 device:shamu
3739ced5               device usb:1D111213 product:msm8610 model:Flame device:flame

I guess another way to go is to keep a list of device names, but that just seems like a big dumb task.

I'm going to poke into the ADB Helper some more, because it seems to help WebIDE detect FxOS devices without throwing up permission screens

Oh, hey, so I think this is how ADB Helper does it:

➜  adb devices -l
List of devices attached
ZX1G229PZV             device usb:1D111400 product:shamu model:Nexus_6 device:shamu
3739ced5               device usb:1D111213 product:msm8610 model:Flame device:flame

➜  adb -s ZX1G229PZV shell 'test -f /system/b2g/b2g; echo $?'
1
➜  adb -s 3739ced5 shell 'test -f /system/b2g/b2g; echo $?'
0

That's a fun hack.

Hah, that is awesome.

I hadn't seen CyberAgent/adbkit until poking through sole/install-to-adb - very cool!

So, I think I could use that shell hack from ADB Helper to look up device IDs with a combo of listDevices and shell. Then, listForwards accepts device IDs - which can then discover pre-existing port forwards specifically to FxOS devices. And, wherever a forward hasn't been done, we can make one with adbkit's forward.

Not sure about un-forwarding, though. Might not be all that necessary: If we can detect existing forwards, we reuse them. So, hopefully they won't pile up. I guess they'll all get cleaned up with the adb daemon dies?

I think I'll play with that stuff tonight / tomorrow morning. Just thinking aloud in this comment in case I forget how to computer or something

commented

They do get cleaned up :) seems that adbkit picks them up where they were. Otherwise I would have ran out of ports already on my machine specially when running it with 10 phones!

commented

For documentation we discussed on irc to have a find-devices module and a forward-devices module. Les is going to look into that.

node-firefox-find-devices is a thing! And I also have my first PR in to implement it. Tonight or tomorrow, I tackle foward-devices

commented

and https://github.com/mozilla/node-firefox-forward-ports is another thing! closing because you can now interact with ADB devices! \o/

💯