teamclouday / AndroidMic

Use your Android phone as a mic to Windows PC
MIT License
113 stars 9 forks source link

Usb adb #19

Closed wiiznokes closed 1 year ago

wiiznokes commented 1 year ago

I implemented the communication via USB adb thanks to the other branch. I needed usb because I'm on a public network so it's perfect. Not as fast as wifi but faster than bluetooth.

We need to first click the connect button with Android and then Windows.

teamclouday commented 1 year ago

Cool, it's nice to see the adb branch revived🙂. And yes, USB would be very helpful if on public network. I'll take a look today!

teamclouday commented 1 year ago

Hey, I've tested the update. There's probably bug on the C# adb server side. The desktop app shows connected even if the phone is not trying to connect.

teamclouday commented 1 year ago

And if you look at other 2 streamers, I usually TestClient first before receiving data from a client. It is a trivial thing, but I feel like it is a good way to avoid unexpected connection (e.g. a local app randomly connects to pc localhost at the same port).\ Of course, I can implement that after the merge of this PR, in case you would like to work on something else🙂

Edit: Never mind, I just found that the Android app is the server here. So no need of TestClient

wiiznokes commented 1 year ago

Hey, yes I know, I tried to solve this by getting the stream in Connect function

stream = mTcpClient.GetStream();

but it connect anyway, idk what to do.

teamclouday commented 1 year ago

but it connect anyway, idk what to do.

I just took another look into it. The adb first forwards port from pc to android device.\ So here connect from pc is connecting to the local port on localhost. Once adb has started port forwarding, the connection from pc app may always be successful. But the Android device is not necessarily listening on the other side.

I think a better approach is to let PC acting as a server, and do adb reverse, the opposite of port forwarding to allow Android connect talk to PC as a client.

SharpAdbClient: adb reverse

wiiznokes commented 1 year ago

Ok good then, I'm not sure to fully understand this approach so you can implement it if you want. I also implemented a way to choose port in Android side but idk if it's useful, I'm too lazy to do it on Windows side lol.

teamclouday commented 1 year ago

Haha sounds good! Let me know when you have finished so I'll merge and apply the changes.

wiiznokes commented 1 year ago

It's good, you can merge it👍

teamclouday commented 1 year ago

Hey, I've updated to use adb reverse. Should be working well now.\ Btw the streamer is in essence TCP connection, so the implementation is very similar to the WifiStreamer 😂

wiiznokes commented 1 year ago

I just tested, it work really well, tanks👍