- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How can I detect internet connection change?
Hi to all
I am developing a channel on which I depend of internet connection to play a video.
The problem is that the solution I have found at
https://stackoverflow.com/questions/56127302/how-to-check-for-network-connection-in-brightscript
doesn't work.
This is the way I have implemented it:
in the main.brs:
main - msg type - roDeviceInfoEvent
MainScene roDeviceInfoEvent | msg = | index = 0
MainScene isStatusMessage
We are OFFline.
main - msg - <Component: roDeviceInfoEvent>
main - msg type - roDeviceInfoEvent
MainScene roDeviceInfoEvent | msg = | index = 0
MainScene isStatusMessage
We are ONline.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: How can I detect internet connection change?
I hope this works for you, I used to handle error connections
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: How can I detect internet connection change?
Thank you for your answer.
But, what is called at:
scene.callFunc("handleLinkStatusEvents",{})
?
How handleLinkStatusEvents works? What are the parameters the function must deal with?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: How can I detect internet connection change?
It's a functional field that you could add on the mainScene XML, you can send the flag with the linkStatus:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: How can I detect internet connection change?
Thank you for your answers.
Anyway, with the code you provided the link, it keeps doing the same thing:
If I disconnect the router (no internet), it will not show any message.
When I reconnect the router, after some seconds, it shows the disconnected message and the connected one, at the same time. It doesn't detect the disconnection when the router is turned off.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: How can I detect internet connection change?
After some time I realized that the solution shown above doesn't work.
Eventually it will fire when the Internet connection is lost but will no fire when the connection is restaured.
The ONLY way I have found to monitoring the Internet connection state is:
In xml:
<field id = "offline" type = "boolean" value = "false" alwaysNotify = "true" onChange = "onOfflineChanged" />
Have a timer (mine is fired every 10 seconds, but I think that it will be from 30 seconds to 1 minute).
Then, when the timer fire, this is the code to run:
function VerifyInternetConnection() ' Verify internet connection every 10 seconds (every minute?)
print chr(10) + "Verify internet connection:"
m.MainSceneDeviceInfo.ForceInternetStatusCheck(). ' This is de deviceInfo instance
m.top.offline = NOT m.MainSceneDeviceInfo.GetInternetStatus()
print "m.scene.offline = "; m.top.offline
end function
Then, in onOfflineChanged() :
function onOfflineChanged() ' m.top.offline has changed.
if(m.top.offline)
print "PlayerScene -> We are offline."
else
print "PlayerScene -> We are online."
end if
end function
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: How can I detect internet connection change?
You should be able to do it with 3 different ways:
1. Create a timer that will fire every x seconds and inside the callback function instantiate a new device info object that will read the internet connection status:
sub myTimerCallback()
deviceInfo = CreateObject("rodeviceinfo")
connectionStatus = deviceInfo.GetInternetStatus()
? connectionStatus ' this will show false or true
end sub
2. Enable the internet status change event and inside the application main loop read the event and do something with it:
sub main
deviceInfo = CreateObject("roDeviceInfo")
deviceInfo.EnableInternetStatusEvent(true)
port = CreateObject("roMessagePort")
deviceInfo.setMessagePort(port)
while (true)
msg = wait(0, port)
msgType = type(msg)
if msgType = "roDeviceInfoEvent"
connectionStatus = msg.getData()
' do something with connectionStatus
end if
end sub
3. Dont use device info and create a timer that will fetch an image with x MB of size stored in some repo. Based on the time the image needs to load, compute the current internet speed or if the user is connected to internet
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: How can I detect internet connection change?
Dear friend @danielFav:
Unfortunately the internet status change event don't work (at least for me).
I even tried it again using your code, but it still didn't work. It fires the first time but never fires again.
The only solution was using the timer.
Now it works 100%.
Thanks for your help. I appreciate.