2019-03-19 02:59:23 +00:00
|
|
|
function get_token(user as String, password as String)
|
|
|
|
url = "Users/AuthenticateByName?format=json"
|
|
|
|
req = APIRequest(url)
|
|
|
|
|
2020-01-04 21:31:07 +00:00
|
|
|
encPass = CreateObject("roUrlTransfer")
|
2020-06-26 16:55:43 +00:00
|
|
|
json = postJson(req, FormatJson({ "Username": user, "Pw": password }))
|
|
|
|
|
2019-03-19 02:59:23 +00:00
|
|
|
|
|
|
|
if json = invalid then return invalid
|
|
|
|
|
2019-04-20 17:40:06 +00:00
|
|
|
userdata = CreateObject("roSGNode", "UserData")
|
|
|
|
userdata.json = json
|
|
|
|
|
|
|
|
userdata.callFunc("setActive")
|
|
|
|
userdata.callFunc("saveToRegistry")
|
|
|
|
return userdata
|
2019-03-19 02:59:23 +00:00
|
|
|
end function
|
|
|
|
|
|
|
|
function AboutMe()
|
2019-04-20 17:40:06 +00:00
|
|
|
id = get_setting("active_user")
|
|
|
|
url = Substitute("Users/{0}", id)
|
2019-03-19 02:59:23 +00:00
|
|
|
resp = APIRequest(url)
|
|
|
|
return getJson(resp)
|
|
|
|
end function
|
2019-03-19 04:17:50 +00:00
|
|
|
|
|
|
|
function SignOut()
|
2019-04-22 19:08:10 +00:00
|
|
|
if get_setting("active_user") <> invalid
|
|
|
|
unset_user_setting("token")
|
|
|
|
end if
|
2019-03-19 04:17:50 +00:00
|
|
|
unset_setting("active_user")
|
2020-03-08 05:56:05 +00:00
|
|
|
m.overhang.currentUser = ""
|
2020-05-04 17:57:40 +00:00
|
|
|
m.overhang.showOptions = false
|
|
|
|
m.scene.unobserveField("optionsPressed")
|
2019-03-19 04:17:50 +00:00
|
|
|
end function
|
2019-04-20 17:54:24 +00:00
|
|
|
|
2019-04-22 19:08:10 +00:00
|
|
|
function AvailableUsers()
|
2019-04-22 20:07:34 +00:00
|
|
|
users = parseJson(get_setting("available_users", "[]"))
|
2019-04-22 19:08:10 +00:00
|
|
|
return users
|
|
|
|
end function
|
|
|
|
|
|
|
|
function PickUser(id as string)
|
2019-04-22 20:07:34 +00:00
|
|
|
this_user = invalid
|
|
|
|
for each user in AvailableUsers()
|
|
|
|
if user.id = id then this_user = user
|
|
|
|
end for
|
|
|
|
if this_user = invalid then return invalid
|
|
|
|
set_setting("active_user", this_user.id)
|
|
|
|
set_setting("server", this_user.server)
|
2019-04-23 03:28:25 +00:00
|
|
|
end function
|
|
|
|
|
|
|
|
function RemoveUser(id as string)
|
|
|
|
user = CreateObject("roSGNode", "UserData")
|
|
|
|
user.id = id
|
|
|
|
user.callFunc("removeFromRegistry")
|
2019-04-22 19:08:10 +00:00
|
|
|
|
2019-04-23 03:28:25 +00:00
|
|
|
if get_setting("active_user") = id then SignOut()
|
2019-04-22 19:08:10 +00:00
|
|
|
end function
|
2019-04-20 17:54:24 +00:00
|
|
|
|
|
|
|
function ServerInfo()
|
|
|
|
url = "System/Info/Public"
|
2021-04-04 13:41:44 +00:00
|
|
|
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" }
|
|
|
|
|
2019-04-20 17:54:24 +00:00
|
|
|
end function
|
2020-03-21 21:22:26 +00:00
|
|
|
|
|
|
|
function GetPublicUsers()
|
|
|
|
url = "Users/Public"
|
|
|
|
resp = APIRequest(url)
|
|
|
|
return getJson(resp)
|
|
|
|
end function
|
2020-11-29 11:18:23 +00:00
|
|
|
|
|
|
|
' Load and parse Display Settings from server
|
|
|
|
sub LoadUserPreferences()
|
|
|
|
id = get_setting("active_user")
|
|
|
|
' Currently using client "emby", which is what website uses so we get same Display prefs as web.
|
|
|
|
' May want to change to specific Roku display settings
|
|
|
|
url = Substitute("DisplayPreferences/usersettings?userId={0}&client=emby", id)
|
|
|
|
resp = APIRequest(url)
|
|
|
|
jsonResponse = getJson(resp)
|
|
|
|
|
|
|
|
if jsonResponse <> invalid and jsonResponse.CustomPrefs <> invalid and jsonResponse.CustomPrefs["landing-livetv"] <> invalid then
|
|
|
|
set_user_setting("display.livetv.landing", jsonResponse.CustomPrefs["landing-livetv"])
|
|
|
|
else
|
|
|
|
unset_user_setting("display.livetv.landing")
|
|
|
|
end if
|
|
|
|
end sub
|