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:
’ The roSGScreen object is a SceneGraph canvas that displays the contents of a Scene node instance
m.screen = CreateObject(“roSGScreen”)
m.deviceInfo = CreateObject(“roDeviceInfo”)
’ message port is the place where events are sent
m.port = CreateObject(“roMessagePort”)
’ sets the message port which will be used for events from the screen
m.screen.SetMessagePort(m.port)
m.deviceInfo.setMessagePort(m.port)
’ Network connection status
’ https://stackoverflow.com/questions/56127302/how-to-check-for-network-connection-in-brightscript
if(m.deviceInfo.EnableLinkStatusEvent(true)) then
print “deviceInfo Link Status IS enabled!”
else
print “deviceInfo Link Status NOT enabled!”
end if
’ every screen object must have a Scene node, or a node that derives from the Scene node
m.scene = m.screen.CreateScene(“MainScene”)
m.screen.Show() ’ Init method in MainScene.brs is invoked
m.scene.offline = not m.deviceInfo.GetLinkStatus()
’ event loop
while(true)
’ waiting for events from screen
msg = wait(0, m.port)
msgType = type(msg)
print "main - msg - ";msg
print "main - msg type - ";msgType
if (msgType = “roDeviceInfoEvent”) then
print "MainScene roDeviceInfoEvent | msg = "; msg.getMessage() " | index = "; msg.GetIndex()
if (msg.isScreenClosed()) then
print “MainScene Screen closed”
end if
if(msg.isStatusMessage()) then
print “MainScene isStatusMessage”
’ m.scene.offline = not msg.getInfo().linkStatus
m.scene.offline = not m.deviceInfo.GetLinkStatus()
end if
end if
if (msgType = “roSGScreenEvent”) then
if (msg.IsScreenClosed()) then
print “MainScene Screen closed”
return
end if
end if
end while
In the MainScene.xml:
And, in the MainScene.brs:
function onOfflineChanged()
if(m.top.offline)
print “We are OFFline.”
else
print “We are ONline.”
end if
end function
The problem is that the code works only when I start the channel (app).
If, after the channel is running, I turn off my wifi router (and the Roku device gets disconnected from internet), I don’t get notified of disconnection, BUT, when I reconnect the power to the wifi router, after some seconds, I get the disconnection message AND the connection message.
main - msg - <Component: roDeviceInfoEvent>
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.
Can somebody shows some solution to have some notification of network connection/disconnection?
There is NOTHING about this in the Roku documentation examples, as always.
Thanks to all
