Listen onoffline and ononline events

Hi.
How to listener onoffline and ononline in Cocos Creator?

Anyone can help me :frowning:

You can do that by schedule a task periodically calling a dummy Restful API. If there’s a response, there’s internet connection. Then wrap it with a listener design pattern class to observe the network state.

This way is not really convenient? In web i can use window.addEventListener. But this not working after build mobile

On web by default cross origin Rest APIs is not allowed. So my method wouldn’t work without some hacks.

On native platform, you are not actually running a web page, you are using an interface called Javascript Binding (JSB).

So I guess there’s no way but to do diff type of checking for these two environment.