diff --git a/builds/visionLabs-roku-smoketest.zip b/builds/visionLabs-roku-smoketest.zip index bfd6042..4ba66b7 100644 Binary files a/builds/visionLabs-roku-smoketest.zip and b/builds/visionLabs-roku-smoketest.zip differ diff --git a/components/MainScene.brs b/components/MainScene.brs index d2a4ec6..6603443 100644 --- a/components/MainScene.brs +++ b/components/MainScene.brs @@ -2,6 +2,7 @@ sub init() m.top.setFocus(true) m.backend = m.top.findNode("backend") m.status = m.top.findNode("status") + m.refreshTimer = m.top.findNode("refreshTimer") m.cameraPosters = [ m.top.findNode("poster1"), m.top.findNode("poster2"), @@ -14,6 +15,7 @@ sub init() m.top.findNode("cam3"), m.top.findNode("cam4") ] + m.refreshToken = 0 loadConfig() end sub @@ -27,8 +29,10 @@ sub loadConfig() return end if + m.config = config + if config.doesExist("backend") and config.backend.doesExist("baseUrl") then - m.backend.text = "Frigate: " + config.backend.baseUrl + m.backend.text = "Frigate snapshot source" end if if not config.doesExist("cameras") then @@ -36,8 +40,23 @@ sub loadConfig() return end if - cameras = config.cameras - m.status.text = cameras.count().toStr() + " cameras loaded, snapshot-first prototype" + if config.doesExist("backend") and config.backend.doesExist("refreshSeconds") then + m.refreshTimer.duration = config.backend.refreshSeconds + end if + + m.refreshTimer.observeField("fire", "onRefreshTimerFire") + m.refreshTimer.control = "start" + + renderCameras() +end sub + +sub renderCameras() + if m.config = invalid or not m.config.doesExist("cameras") then + return + end if + + cameras = m.config.cameras + m.status.text = cameras.count().toStr() + " cameras loaded, refreshing every " + m.refreshTimer.duration.toStr() + "s" for i = 0 to m.cameraNodes.count() - 1 poster = m.cameraPosters[i] @@ -45,18 +64,8 @@ sub loadConfig() if i < cameras.count() then camera = cameras[i] - label = camera.name - - if camera.doesExist("host") then - label = label + chr(10) + camera.host - end if - - if camera.doesExist("frigateCamera") then - label = label + chr(10) + "Frigate ID: " + camera.frigateCamera - end if - - poster.uri = buildSnapshotUrl(config, camera) - node.text = label + poster.uri = addCacheBust(buildSnapshotUrl(m.config, camera)) + node.text = camera.name else poster.uri = "" node.text = "Empty slot" @@ -64,6 +73,11 @@ sub loadConfig() end for end sub +sub onRefreshTimerFire() + m.refreshToken = m.refreshToken + 1 + renderCameras() +end sub + function buildSnapshotUrl(config as Object, camera as Object) as String if not config.doesExist("backend") or not config.backend.doesExist("baseUrl") then return "" @@ -88,3 +102,13 @@ function buildSnapshotUrl(config as Object, camera as Object) as String return baseUrl + path end function + +function addCacheBust(url as String) as String + token = m.refreshToken.toStr() + + if instr(1, url, "?") > 0 then + return url + "&cb=" + token + end if + + return url + "?cb=" + token +end function diff --git a/components/MainScene.xml b/components/MainScene.xml index 677304e..18b7637 100644 --- a/components/MainScene.xml +++ b/components/MainScene.xml @@ -6,7 +6,7 @@