jf-roku/components/quickConnect/QuickConnectDialog.brs

72 lines
2.2 KiB
Plaintext
Raw Normal View History

import "pkg:/source/api/userauth.brs"
import "pkg:/source/api/baserequest.brs"
import "pkg:/source/utils/config.brs"
import "pkg:/source/utils/session.bs"
2022-05-29 20:00:38 +00:00
sub init()
m.quickConnectTimer = m.top.findNode("quickConnectTimer")
m.quickConnectTimer.observeField("fire", "quickConnectStatus")
m.quickConnectTimer.control = "start"
m.top.observeFieldScoped("buttonSelected", "onButtonSelected")
end sub
sub quickConnectStatus()
m.quickConnectTimer.control = "stop"
m.checkTask = CreateObject("roSGNode", "QuickConnect")
m.checkTask.secret = m.top.quickConnectJson.secret
m.checkTask.observeField("authenticated", "OnAuthenticated")
m.checkTask.control = "run"
end sub
sub OnAuthenticated()
m.checkTask.unobserveField("authenticated")
' Did we get the A-OK to authenticate?
authenticated = m.checkTask.authenticated
if authenticated < 0
' Still waiting, check again in 3 seconds...
authenticated = 0
m.checkTask.observeField("authenticated", "OnAuthenticated")
m.quickConnectTimer.control = "start"
else if authenticated > 0
' We've been given the go ahead, try to authenticate via Quick Connect...
authenticated = AuthenticateViaQuickConnect(m.top.quickConnectJson.secret)
if authenticated <> invalid and authenticated = true
currentUser = AboutMe()
session.user.Login(currentUser)
2022-05-29 20:00:38 +00:00
LoadUserPreferences()
LoadUserAbilities()
2022-05-29 20:00:38 +00:00
m.top.close = true
m.top.authenticated = true
else
2022-05-30 12:12:43 +00:00
m.top.close = true
m.top.authenticated = false
2022-05-29 20:00:38 +00:00
end if
end if
end sub
sub quickConnectClosed()
m.quickConnectTimer.control = "stop"
if m.checkTask <> invalid
m.checkTask.unobserveField("authenticated")
end if
m.top.close = true
end sub
sub onButtonSelected()
' only one button at the moment...
quickConnectClosed()
end sub
function onKeyEvent(key as string, press as boolean) as boolean
if not press then return false
' Note that "OK" does not get sent here, hence onButtonSelected() above.
if key = "back"
quickConnectClosed()
return true
end if
return false
end function