Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
donavonc
Visitor

Check Network Connection before connecting Alert Box help

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


0 Kudos
11 REPLIES 11
donavonc
Visitor

Re: Check Network Connection before connecting Alert Box hel

please help me out.
0 Kudos
RokuMarkn
Visitor

Re: Check Network Connection before connecting Alert Box hel

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.

--Mark
0 Kudos
EnTerr
Roku Guru

Re: Check Network Connection before connecting Alert Box hel

Re whether player (thinks it) is conneected, see roDeviceInfo.GetLinkStatus().

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 "<html>" - or something more specific if you want to rule out error handler that returns readable html page)

ps. synchronicity!
0 Kudos
donavonc
Visitor

Re: Check Network Connection before connecting Alert Box hel

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
0 Kudos
NewManLiving
Visitor

Re: Check Network Connection before connecting Alert Box hel

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
My Channels: 2D API Framework Presentation: https://owner.roku.com/add/2M9LCVC
Updated: 11-11-2015 - Completed Keyboard interface
The Joel Channel ( Final Beta )
0 Kudos
donavonc
Visitor

Re: Check Network Connection before connecting Alert Box hel

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 ..
0 Kudos
NewManLiving
Visitor

Re: Check Network Connection before connecting Alert Box hel

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
My Channels: 2D API Framework Presentation: https://owner.roku.com/add/2M9LCVC
Updated: 11-11-2015 - Completed Keyboard interface
The Joel Channel ( Final Beta )
0 Kudos
donavonc
Visitor

Re: Check Network Connection before connecting Alert Box hel

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.

Thanks
0 Kudos
belltown
Roku Guru

Re: Check Network Connection before connecting Alert Box hel

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
0 Kudos