diff --git a/builds/visionLabs-roku-smoketest.zip b/builds/visionLabs-roku-smoketest.zip index b5003e2..9c0f147 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..9d037df 100644 --- a/components/MainScene.brs +++ b/components/MainScene.brs @@ -37,7 +37,8 @@ sub loadConfig() end if cameras = config.cameras - m.status.text = cameras.count().toStr() + " cameras loaded, snapshot-first prototype" + m.status.text = cameras.count().toStr() + " cameras loaded, fetching snapshots..." + loadedCount = 0 for i = 0 to m.cameraNodes.count() - 1 poster = m.cameraPosters[i] @@ -55,13 +56,25 @@ sub loadConfig() label = label + chr(10) + "Frigate ID: " + camera.frigateCamera end if - poster.uri = buildSnapshotUrl(config, camera) - node.text = label + snapshotUrl = buildSnapshotUrl(config, camera) + targetPath = "tmp:/" + camera.id + ".jpg" + result = fetchSnapshot(snapshotUrl, targetPath) + + if result.success then + poster.uri = targetPath + loadedCount = loadedCount + 1 + node.text = label + else + poster.uri = "" + node.text = label + chr(10) + "Snapshot failed (" + result.code.toStr() + ")" + end if else poster.uri = "" node.text = "Empty slot" end if end for + + m.status.text = loadedCount.toStr() + " of " + cameras.count().toStr() + " snapshots loaded" end sub function buildSnapshotUrl(config as Object, camera as Object) as String @@ -88,3 +101,24 @@ function buildSnapshotUrl(config as Object, camera as Object) as String return baseUrl + path end function + +function fetchSnapshot(url as String, filePath as String) as Object + result = { + success: false + code: 0 + } + + if url = "" then + return result + end if + + transfer = CreateObject("roUrlTransfer") + transfer.SetCertificatesFile("common:/certs/ca-bundle.crt") + transfer.InitClientCertificates() + transfer.SetUrl(url) + + result.success = transfer.GetToFile(filePath) + result.code = transfer.GetResponseCode() + + return result +end function