Improve server connection feedback
This commit is contained in:
parent
2060cc38d3
commit
666fe2cf38
|
@ -19,8 +19,10 @@
|
|||
translation="[150, 450]" />
|
||||
<label text=""
|
||||
id="alert"
|
||||
wrap="true"
|
||||
width="1620"
|
||||
font="font:MediumSystemFont"
|
||||
translation="[150, 555]" />
|
||||
translation="[150, 580]" />
|
||||
</children>
|
||||
<script type="text/brightscript" uri="ConfigScene.brs"/>
|
||||
</component>
|
||||
|
|
|
@ -441,7 +441,21 @@ function LoginFlow(startOver = false as boolean)
|
|||
end if
|
||||
'Collect Jellyfin server and user information
|
||||
start_login:
|
||||
if get_setting("server") = invalid or ServerInfo() = invalid or startOver = true then
|
||||
|
||||
if get_setting("server") = invalid then startOver = true
|
||||
|
||||
if not startOver then
|
||||
' Show Connecting to Server spinner
|
||||
dialog = createObject("roSGNode", "ProgressDialog")
|
||||
dialog.title = tr("Connecting to Server")
|
||||
m.scene.dialog = dialog
|
||||
|
||||
serverInfoResult = ServerInfo()
|
||||
|
||||
dialog.close = true
|
||||
end if
|
||||
|
||||
if serverInfoResult.Error or startOver then
|
||||
print "Get server details"
|
||||
SendPerformanceBeacon("AppDialogInitiate") ' Roku Performance monitoring - Dialog Starting
|
||||
serverSelection = CreateServerGroup()
|
||||
|
|
|
@ -53,12 +53,34 @@ function CreateServerGroup()
|
|||
set_setting("password", "")
|
||||
endif
|
||||
set_setting("server", server_hostname.value)
|
||||
if ServerInfo() = invalid then
|
||||
|
||||
' Show Connecting to Server spinner
|
||||
dialog = createObject("roSGNode", "ProgressDialog")
|
||||
dialog.title = tr("Connecting to Server")
|
||||
m.scene.dialog = dialog
|
||||
|
||||
serverInfoResult = ServerInfo()
|
||||
|
||||
dialog.close = true
|
||||
|
||||
if serverInfoResult = invalid then
|
||||
' Maybe don't unset setting, but offer as a prompt
|
||||
' Server not found, is it online? New values / Retry
|
||||
print "Server not found, is it online? New values / Retry"
|
||||
group.findNode("alert").text = tr("Server not found, is it online?")
|
||||
SignOut()
|
||||
else if serverInfoResult.Error <> invalid and serverInfoResult.Error
|
||||
' If server redirected received, update the URL
|
||||
if serverInfoResult.UpdatedUrl <> invalid then
|
||||
server_hostname.value = serverInfoResult.UpdatedUrl
|
||||
end if
|
||||
' Display Error Message to user
|
||||
message = tr("Error: ")
|
||||
if serverInfoResult.ErrorCode <> invalid then
|
||||
message = message + "[" + serverInfoResult.ErrorCode.toStr() + "] "
|
||||
end if
|
||||
group.findNode("alert").text = message + tr(serverInfoResult.ErrorMessage)
|
||||
SignOut()
|
||||
else
|
||||
group.visible = false
|
||||
return "true"
|
||||
|
|
|
@ -58,8 +58,54 @@ end function
|
|||
|
||||
function ServerInfo()
|
||||
url = "System/Info/Public"
|
||||
resp = APIRequest(url)
|
||||
return getJson(resp)
|
||||
req = APIRequest(url)
|
||||
|
||||
req.setMessagePort(CreateObject("roMessagePort"))
|
||||
req.AsyncGetToString()
|
||||
|
||||
' wait 15 seconds for a server response
|
||||
resp = wait(35000, req.GetMessagePort())
|
||||
|
||||
' handle unknown errors
|
||||
if type(resp) <> "roUrlEvent"
|
||||
return { "Error": true, "ErrorMessage": "Unknown" }
|
||||
end if
|
||||
|
||||
' check for a location redirect header in the response
|
||||
headers = resp.GetResponseHeaders()
|
||||
if headers <> invalid and headers.location <> invalid then
|
||||
|
||||
' only follow redirect if it the API Endpoint path is the same (/System/Info/Public)
|
||||
' set the server to new location and try again
|
||||
if right(headers.location, 19) = "/System/Info/Public" then
|
||||
set_setting("server", left(headers.location, len(headers.location) - 19))
|
||||
info = ServerInfo()
|
||||
if info.Error then
|
||||
info.UpdatedUrl = left(headers.location, len(headers.location) - 19)
|
||||
info.ErrorMessage = info.ErrorMessage + " (Note: Server redirected us to " + info.UpdatedUrl + ")"
|
||||
end if
|
||||
return info
|
||||
end if
|
||||
end if
|
||||
|
||||
' handle any non 200 responses, returning the error code and message
|
||||
if resp.GetResponseCode() <> 200 then
|
||||
return { "Error": true, "ErrorCode": resp.GetResponseCode(), "ErrorMessage": resp.GetFailureReason() }
|
||||
end if
|
||||
|
||||
' return the parsed response string
|
||||
responseString = resp.GetString()
|
||||
if responseString <> invalid and responseString <> "" then
|
||||
result = ParseJson(responseString)
|
||||
if result <> invalid then
|
||||
result.Error = false
|
||||
return result
|
||||
end if
|
||||
end if
|
||||
|
||||
' otherwise return error message
|
||||
return { "Error": true, "ErrorMessage": "Does not appear to be a Jellyfin Server" }
|
||||
|
||||
end function
|
||||
|
||||
function GetPublicUsers()
|
||||
|
|
Loading…
Reference in New Issue
Block a user