odyshewroman / AndroidTVRemoteControl

MIT License
31 stars 9 forks source link

Check if already connected #12

Closed Jacky154 closed 11 months ago

Jacky154 commented 11 months ago

Hi, thanks for this great library. I am using it to control my android tv device. It works great.

But I don't know how to check whether I am already paired with this same device or not? If already paired then I want to skip pairing process. Should I use connected case in remoteState or connected case in pairing state.

Also its a very strange question I want know that if i connected with one tv and after want to connect with another tv using same app will it works in this case ???

Thanks

odyshewroman commented 11 months ago

Hi. I have not investigated how to check if the Android TV device remembers you because I believe it depends on the TV's implementation. Instead, I initially try to connect without pairing, using the RemoteManager. If you encounter a specific error, it means you are not paired, and you should establish pairing first. This is why Pairing and Remote managers have a stateChanged closure, allowing you to implement your logic. I have implemented this in the Demo project; you can check the code of the connect function in the RemoteTVManager. It's the scenario I described above.

Regarding multiple TVs in the same session, you have options: disconnect from the first device before connecting to another one or use multiple instances of Pairing and Remote managers.

Jacky154 commented 11 months ago

Thanks for suggestion actually I am using callback function in the connect method of RemoteTVManager in .error case. Where I implement case that if case .connected in remoteSatae then skip pairing process.

But I don't understand the 2nd answer. I don't know how to disconnect from 1st device. Is it possible that without disconnecting I can use it for controlling other android tvs.

odyshewroman commented 11 months ago

@Jacky154 I just mean that RemoteManager can work only with one device. If you wanna connect to another device without disconnecting from first, you should create one more instance of RemoteManager and establish connection with new device.

Jacky154 commented 11 months ago

Oh I got it now. Thanks

Actually I am implementing an app in which there is multiple android tvs brand names like sony, toshiba, sansui, tcl etc. Whenever I click on the name then I navigate to screen where I am using remoteManager object for connect to tv.

In this way whenever user need to attach with another tv then he must have to navigate back and then again select any modal name. In this case the user again go to screen where I am using remoteManager object for connect and sending commands to android tvs.

I think In this case I can connect to multiple android tv without creating multiple instance.

Jacky154 commented 11 months ago

Hey @odyshewroman can you please answer my above question. Am i right or wrong ?

Oh I got it now. Thanks

Actually I am implementing an app in which there is multiple android tvs brand names like sony, toshiba, sansui, tcl etc. Whenever I click on the name then I navigate to screen where I am using remoteManager object for connect to tv.

In this way whenever user need to attach with another tv then he must have to navigate back and then again select any modal name. In this case the user again go to screen where I am using remoteManager object for connect and sending commands to android tvs.

I think In this case I can connect to multiple android tv without creating multiple instance.

odyshewroman commented 11 months ago

Sorry for the late reply. Yes, you can, but you should call the disconnect method before connecting to the next device. It might work without calling disconnect because the last device will close the connection when you try to establish a new connection with a new device. However, it's better to manually disconnect from one device before connecting to a new one.

Jacky154 commented 11 months ago

Ok thanks

I want to know that is there any way or library through which I can get the all smart tv devices names with their IP address under wifi connection. I tried multiple way but not success.

odyshewroman commented 11 months ago

Yes, indeed, there is a technology that allows obtaining information about all devices in the local network and identifying them. Unfortunately, I can't disclose it due to contractual obligations with my previous employer. You can use network protocols such as SSDP and mDNS to obtain information from well-known TV brands like Samsung, LG, Sony, etc., but it's not enough if you want to work with lesser-known brands or generic devices.

Jacky154 commented 11 months ago

I just want to get the hostname and IP addresses of the devices under local wifi.I tried the multiple ways like msearch or also try ssdp discovery but not get proper result. Actually Its like discovery of different tv devices under local wifi and when I click on any device then It navigates me to connection page where I connect and send commands to tv using your library. Just problem is I can't find the ip addresses and names of tv devices.

It would be grateful if you know how to perform this action or you have already implemented such type of work.

Thanks

Jacky154 commented 11 months ago

Bro can you please tell me how to find out all devices on local network. Actually I can find IP addresses but how to find hostname it is difficult. Please need a help

odyshewroman commented 11 months ago

Why you need hostname? My library work with IP address of devices, it's enough. I guess that not all devices in local network have domain name, but most of AndroidTV have, you should realise mDNS protocol for discovery hostnames of devices, but idk why you need it.

Jacky154 commented 11 months ago

Actually I am building app like Universal TV Remote Controller (and of course I will add the reference of your library for production purpose). I am using your project for controlling different android tv like toshiba, panasonic, sony, oneplus and more. The difficulty is that I want to scan all tv devices IP addresses with name, so that when user click on any name then I wil use corresponding IP for connection and sending commands. But I want to use some type of swift library (either it is on github or swift standard library) which made it easy.

odyshewroman commented 11 months ago

You mean you need vendor name or Smart TV model name? if you have ip address of Android TV device you can grab these information from http://TV_IP:8008/setup/eureka_info

Jacky154 commented 11 months ago

Thanks @odyshewroman

But I am getting all IP addresses available on the wifi network using MMLanScanner github Library. But I just want the IP address of the smart tv on the wifi. Do you know how to handle such situation ??

odyshewroman commented 11 months ago

As I messaged before, I can't share this technology cause of contractual obligations. But, if you have ip address list, you can check each ip by address from my last reply for recognize Android TV OS devices. It's easiest way.

Jacky154 commented 11 months ago

Ok I understand it. Thanks for help