Hi guys, i need a small help
when my app opens, it need to check , if the roku device is connected to network connection
and then check if this site is working http://360abyss.com/ fine (site is up or down )
if both are working, connect to app
if not show “check network connection” message pop box in app.
here is my appMain.brs code, please help
Sub Main()
'initialize theme attributes like titles, logos and overhang color
initTheme()
'prepare the screen for display and get ready to begin
screen=preShowHomeScreen("Register", "")
if screen=invalid then
print "unexpected error in preShowHomeScreen"
return
end if
'register screen, check if linked if not show register screen, if yes connect to newhomescreen
screenFacade = CreateObject("roPosterScreen")
screenFacade.show()
doRegistration()
if isLinked()
newhomescreen()
end if
End Sub
'*************************************************************
'** Set the configurable theme attributes for the application
'**
'** Configure the custom overhang and Logo attributes
'** Theme attributes affect the branding of the application
'** and are artwork, colors and offsets specific to the app
'*************************************************************
Sub initTheme()
app = CreateObject("roAppManager")
theme = CreateObject("roAssociativeArray")
theme.OverhangOffsetSD_X = "72"
theme.OverhangOffsetSD_Y = "31"
theme.OverhangSliceSD = "pkg:/images/Overhang_Background_SD.png"
theme.OverhangLogoSD = "pkg:/images/Overhang_Logo_SD.png"
theme.OverhangOffsetHD_X = "125"
theme.OverhangOffsetHD_Y = "35"
theme.OverhangSliceHD = "pkg:/images/Overhang_Background_HD.png"
theme.OverhangLogoHD = "pkg:/images/Overhang_Logo_HD.png"
app.SetTheme(theme)
End Sub
roDeviceInfo.GetLinkStatus() will tell you whether there is a network connection.
The only way to check whether a “site” is working is to access one of the pages on the site. You can use roUrlTransfer to do that. You probably don’t really need to check the network connection first, unless you’re planning to display a different message in the two failure cases.
For an end-to-end test, how about doing roUrlTransfer.GetToString() to a page of the site and check if the result contains something you expect (say “” - or something more specific if you want to rule out error handler that returns readable html page)
hi, thank you for your responds.can you please tell me where do i need to add that function roDeviceInfo.GetLinkStatus()
im a noob to roku development. can someone please put that code to my appmain.brs
i dont know where that function will need to be placed.
Thanks
You can check the connection right before you execute anything that requires a connection. Downloading graphics/files or streaming for the most part. You can also set the device object to a port and listen for the event during normal execution of your channel if you need to know when an interruption of connection occurs during execution of your event loop
i tried putting the overhang hd, sd images and splash screen to a server and linked/replaced the link in manifest file.
and i put my website turn down and tried to open the app.
it skipped those graphics files and show white blank color on splash and in overhang hd, sd files field. it literally skipped those files ..
Your problem can be other things apart from a network connection. If other ROKU channels are working, or you see connected at the top of the home screen, or you go to settings/ network and see that there is nothing wrong with the connection - then it’s not the network. Could be invalid URL or security issues at the server
i only need to show if the user is not connected to internet show , “please connect to internet message”.
please tell me how i can add. since im a noob to roku development.
if you like to share about the rourltransfer , please tell me how i can do that also.
Sub Main ()
url = "http://360abyss.com"
If Not isConnected ()
displayMessage ("You Have a Problem", "Check network connection")
Else If Not isWorking (url)
displayMessage ("You Have a Problem", url + " is down")
Else
displayMessage ("Everything is good", url + " is working")
End If
End Sub
Function isConnected () As Boolean
Return CreateObject ("roDeviceInfo").GetLinkStatus ()
End Function
Function isWorking (url As String, timeout = 10 As Integer) As Boolean
working = False
port = CreateObject ("roMessagePort")
ut = CreateObject ("roUrlTransfer")
ut.SetPort (port)
ut.SetUrl (url)
ut.EnableEncodings (True)
If LCase (Left (url, Len ("https:"))) = "https:"
ut.SetCertificatesFile ("common:/certs/ca-bundle.crt")
End If
If ut.AsyncGetToString ()
While True
msg = Wait (timeout * 1000, port)
If msg = Invalid
ut.AsyncCancel ()
Exit While
Else If Type (msg) = "roUrlEvent"
If msg.GetInt () = 1
If msg.GetResponseCode () = 200
working = True
End If
Else
ut.AsyncCancel ()
End If
Exit While
End If
End While
End If
Return working
End Function
Function displayMessage (title, message As String) As Void
port = CreateObject ("roMessagePort")
ui = CreateObject ("roMessageDialog")
ui.SetMessagePort (port)
ui.SetTitle (title)
ui.SetText (message)
ui.AddButton (1, "OK")
ui.EnableBackButton (True)
ui.Show ()
While True
msg = Wait (0, port)
If msg <> Invalid
If Type (msg) = "roMessageDialogEvent"
If msg.IsScreenClosed ()
Exit While
Else If msg.IsButtonPressed ()
ui.Close ()
End If
End If
End If
End While
End Function
xfer = CreateObject("roUrlTransfer")
xfer.setURL("http://360abyss.com/")
if xfer.getToString() = "" then
' do something, like diagnostic popup that server cannot be contacted
end if
Above i trust that when failing a fetch, .getToString() returns empty string regardless of reason. Alternatively, one can
'accept only HTTP 200 OK
if xfer.getToFile("tmp:/junk") <> 200
'or check if the content contains a desired substring (in this case "360abyss.com" is inside many href='s)
if xfer.getToString().inStr(0, "360abyss.com") < 0 then