use post task when posting device profile + post device profile when exiting the settings page

This commit is contained in:
Charles Ewert 2023-09-12 18:53:25 -04:00
parent e03f965758
commit 060519810b
4 changed files with 34 additions and 14 deletions

View File

@ -1,4 +1,5 @@
import "pkg:/source/roku_modules/log/LogMixin.brs"
import "pkg:/source/utils/deviceCapabilities.brs"
sub init()
m.log = log.Logger("SceneManager")
@ -6,6 +7,8 @@ sub init()
m.scene = m.top.getScene()
m.content = m.scene.findNode("content")
m.overhang = m.scene.findNode("overhang")
m.postTask = CreateObject("roSGNode", "PostTask")
m.postTask.observeField("responseCode", "postFinished")
end sub
'
@ -77,16 +80,21 @@ end sub
sub popScene()
group = m.groups.pop()
if group <> invalid
if group.isSubType("JFGroup")
groupType = group.subtype()
if groupType = "JFGroup"
unregisterOverhangData(group)
else if group.isSubType("JFVideo")
else if groupType = "JFVideo"
' Stop video to make sure app communicates stop playstate to server
group.control = "stop"
else if groupType = "Settings"
' update device profile after exiting the settings page - some settings affect the device profile
postProfile()
end if
group.visible = false
if group.isSubType("JFScreen")
if groupType = "JFScreen"
group.callFunc("OnScreenHidden")
end if
else
@ -355,3 +363,22 @@ end sub
function isDialogOpen() as boolean
return m.scene.dialog <> invalid
end function
' Send Device Profile information to server
function postProfile() as boolean
m.postTask.arrayData = getDeviceCapabilities()
m.postTask.apiUrl = "/Sessions/Capabilities/Full"
m.postTask.control = "RUN"
return true
end function
' Return the Post Task to it's default state
sub postFinished()
m.postTask.unobserveField("responseCode")
' Empty the Post Task data to its default state
m.postTask.apiUrl = ""
m.postTask.arrayData = {}
m.postTask.stringData = ""
m.postTask.responseCode = 0
m.postTask.observeField("responseCode", "postFinished")
end sub

View File

@ -14,6 +14,7 @@
<function name="dismissDialog" />
<function name="isDialogOpen" />
<function name="optionDialog" />
<function name="postProfile" />
<field id="currentUser" type="string" onChange="updateUser" />
<field id="returnData" type="assocarray" />
<field id="dataReturned" type="boolean" />

View File

@ -32,7 +32,7 @@ sub Main (args as dynamic) as void
' First thing to do is validate the ability to use the API
if not LoginFlow() then return
' tell jellyfin server about device capabilities
PostDeviceProfile()
m.global.sceneManager.callFunc("postProfile")
' remove previous scenes from the stack
sceneManager.callFunc("clearScenes")
@ -621,12 +621,12 @@ sub Main (args as dynamic) as void
' The audio codec capability has changed if true.
print "event.audioCodecCapabilityChanged = ", event.audioCodecCapabilityChanged
PostDeviceProfile()
m.global.sceneManager.callFunc("postProfile")
else if isValid(event.videoCodecCapabilityChanged)
' The video codec capability has changed if true.
print "event.videoCodecCapabilityChanged = ", event.videoCodecCapabilityChanged
PostDeviceProfile()
m.global.sceneManager.callFunc("postProfile")
else if isValid(event.appFocus)
' It is set to False when the System Overlay (such as the confirm partner button HUD or the caption control overlay) takes focus and True when the channel regains focus
print "event.appFocus = ", event.appFocus

View File

@ -17,14 +17,6 @@ function getDeviceCapabilities() as object
}
end function
' Send Device Profile information to server
sub PostDeviceProfile()
body = getDeviceCapabilities()
req = APIRequest("/Sessions/Capabilities/Full")
req.SetRequest("POST")
postJson(req, FormatJson(body))
end sub
function getDeviceProfile() as object
playMpeg2 = m.global.session.user.settings["playback.mpeg2"]
playAv1 = m.global.session.user.settings["playback.av1"]