AirConsole / airconsole-unity-plugin

A plugin for Unity to develop for AirConsole
http://developers.airconsole.com/#/guides/unity
GNU Lesser General Public License v3.0
69 stars 19 forks source link

Phone app won't connect #8

Closed all-iver closed 1 year ago

all-iver commented 8 years ago

When I try to test my game using a real device, AirConsole is really flaky trying to connect. Sometimes it connects, but most of the time this happens:

  1. The debug console says "Connections are ready"
  2. The website switches to saying "Loading..." after I enter the code into the phone app
  3. The phone says "Tap to return to the game"
  4. When I tap, the phone says "Loading..."
  5. OnConnect() is never called
  6. The phone never loads my controller.html page

Like I said, sometimes it works, but rarely. When I use "virtual controllers" it always seems to work. I've tried with two iPhones. With one of them, "leave session" also doesn't work - it just sort of flashes the screen and returns to "Loading...".

My Start() looks like this:

    void Start () {
        AirConsole.instance.onMessage += OnMessage;
        AirConsole.instance.onConnect += OnConnect;
        AirConsole.instance.onDisconnect += OnDisconnect;
    }

and OnConnect() looks like this:

    void OnConnect(int device_id) {
        Debug.Log("Device " + device_id + " connected");
                ...
    }

I've tried deleting/reinstalling the phone app, using the latest unitypackage from github, using the version on the asset store, switching wifi connections, being on the same wifi connection as the webserver, versions of Unity from 5.3.3 to 5.3.5 to 5.4.0, delaying my calls to adding the OnConnect() handler, etc. Is there something I'm doing wrong with the setup? What needs to happen to get past that "Loading..." screen and show the actual controller.html page? Why would it work sometimes and when using the virtual controllers, but usually not work with a real device? Thanks for any help.

all-iver commented 8 years ago

FYI, this also happens with the example "basic" and "pong" projects, so it seems unlikely to be a configuration issue?

all-iver commented 8 years ago

Did a little more testing today - seems like stopping and restarting the server in settings is helping? It's still being pretty flaky though. OnConnect() just doesn't reliably get called even though the console says "Connections are ready," and the phone doesn't reliably get all the way to controller.html. I'm not sure how to troubleshoot further.

alice-n-dream commented 8 years ago

You need to be in the same WiFi with all devices for it to work, but since you mention you've tried different wifi connections, I assume that doesn't solve your problem?

Have a look at these suggestions/similar issues and let us know if any of that helps: http://stackoverflow.com/questions/37380981/airconsole-on-phone-not-working-for-dev

http://stackoverflow.com/questions/34890806/airconsole-phone-controller-screen-not-loading

all-iver commented 8 years ago

I gave it another shot today. Everything is on the same wifi network. Occasionally it will work but usually not. When I browse manually to 192.168.x.x:etc/controller.html on the phone the page shows up fine. I tried remote debugging the phone's web browser and eventually it came up with a "Could not connect to server" message, but nothing more informative than that.

crashkonijn commented 8 years ago

I had the same problem, apparently when launching from unity it grabs my vpn ip. Disabling my vpn fixed this for me. Took me a while to figure out, make sure that the IP in the airconsole.com url is correct :)

alice-n-dream commented 5 years ago

AirConsole now offers a detailed workaround guide for anyone experiencing this problem: https://developers.airconsole.com/#!/guides/unity-ngrok

Doctor-Script commented 1 year ago

Noticed the issue even with the pong example.

https://www.airconsole.com/simulator/#debug:http://games.airconsole.com/pong/

Can't connect any device. The ngrok workaround doesn't help.

marc-n-dream commented 1 year ago

Thank you for bringing this to our attention @Doctor-Script

We will look at it its root and how to best address it.

Doctor-Script commented 1 year ago

Little update. I haven't solved it for pong, but found a workaround for my project.

When I try to connect to ngrok generated URL first time from a new browser I get a warning "You should only visit this website if you trust whoever sent the link to you." and need to press the "Visit Site" to load the actual page.

So I requested the controller.html page directly (f.e. ba73w2f-asd-a2312.ngrok.app/controller.html) from my device, pressed "Visit Site", and after that ngrok started to send the controller page to my device thru the airconsole.com.

Note that it happens after restarting ngrok too. It generates a new address, counts your device as new, and shows the warning again. Thus requires you to press the "Visit Site" button again from the same device.

Hope it will help someone)

marc-n-dream commented 1 year ago

An improvement for the Unity Plugin is underway successfully. This improvement will allow you to configure your ngrok custom domain as local IP which in combination with the modes Normal and Debug allows the to connect to the game running in Unity without additional steps.

marc-n-dream commented 1 year ago

The required improvements are implemented through a new feature that will be released as part of v2.14 tomorrow

marc-n-dream commented 1 year ago

Version v2.14 is now released which should address the issue with the new Local IP Override functionality. Let me know if your specific setup faces problems due to it.

There is updated documentation for it under https://developers.airconsole.com/#!/guides/unity-external-access

Not sure if that was documented before but: the free ngrok shows a user consent page the first time a user tries to access the external url with a new device. Due to this it can not work with the AirConsole Controller as we don't show the html page. The paid ngrok or the cloudflare tunnel do not have the problem.