How to check internet connection?

Hi all!

I need the game to check every N amount of time if the player is online. I could use the fetch() function for this. However, I found the sys.getNetworkType() function. I read that if it returns any type other than NONE, then it is the Internet. Is it so? How does it check it herself? Is it possible to subscribe to an event during a status change?

I am worried about the following. I will be uploading the game to a platform that prohibits access to other servers (only to its own). And if the Cocos Creator engine checks the network status by accessing another site, the platform may not take it well and not accept my game at all. What can be configured here?

sys.getNetworkType() just query the network type using OS function. And i don’t quite understand your issue.

First of all, I don’t understand whether the sys.getNetworkType() function makes any query or whether it just returns a pre-prepared value.

Secondly, for the Web-desktop/mobile platform, will the network status be determined by accessing some server or not? If it does, I need to be able to either disable this behavior or specify a site it will contact to determine if there is a network.

The point is this. I will make buildings for Web-desktop and for Web-mobile. Where I will place these assemblies, it is forbidden to make any requests to other servers, different from this server.

That’s why I want to know if the method via the sys.getNetworkType() function will be sufficient for me.

I think sys.getNetworkType() is not sufficient for you. It doesn’t do anything but return a network type.

Thanks! Then use fetch().