Cast using Youtube app (DIAL/LoungeAPI) (#276)

* Dial+Lounge API PoC

* format

* Fix for chrome

* comments

* Rate limit and logger stuff

* rename route

* remove invalid routes

* remove device image

* Simplify device description

* command test

* Lint fix

* register pairing code

* tv code UI

* Lint fix

* Avoid creating lots of objects

* dpad command

* small refactor

* tweak

* validation

* timer

* fix

* Revert "timer"

This reverts commit e349565910882408898c9bddda55dadaa9d743de.

* Commands

* setVolume command

* lounge service timer

* Some state messages

* Lint fix

* player state sync

* voice handler

* Adjustments, and add a TODO list

* Lint fix

* comment

* play at timestamp

* Remote screen UI

* UI adjustment

* Small refactor

* Refactor long polling

* Add TODO

* Manage logging a bit better to avoid spam in DIAL server

* cache dial file

* logging

* comment

* Join lounge lazily

* long poller tweak

* ui tweak

* set shouldQuit field

* remote connect notification

* Lint fix

* Randomize device id, new device on start

* Lint fix

* Lounge disconnect on start

* Speed up lounge by not blocking on sent messages

* add version to lounge data saved

* dial server fix rendezvous

* todo

* no message

* Display network name

* playlist changes

* Lint fix

* tweak params

* tweak

* player state

* comments

* Refactor Video Queue (#295)

* Refactor Video Queue

* Video queue and playlists

* Web app casting

* queue playlist notification

* VideoQueueView work

* restore properties

* changes

* queue notification and previous/next state

* Lint fix

* very basic error handling

* Update changelog and privacy policy

---------

Co-authored-by: github-action linter <githubaction@githubaction.com>
This commit is contained in:
Brahim Hadricheandgithub-action linter authored and GitHub committed 2024-02-19 16:30:48 -05:00
1 parent ec9178d687
commit 7d1ba07286
85 files changed
+3666 -938

No files matched your search

@@ -0,0 +1,196 @@
import "pkg:/components/Dialog/DialogUtils.bs"
import "pkg:/components/Navigation/Navigation.bs"
import "pkg:/source/AsyncTask/AsyncTask.bs"
import "pkg:/source/AsyncTask/AsyncTask.bs"
import "pkg:/source/AsyncTask/Tasks.bs"
import "pkg:/source/AsyncTask/Tasks.bs"
import "pkg:/source/utils/ErrorUtils.bs"
import "pkg:/source/utils/FocusManagement.bs"
import "pkg:/source/utils/Logging.bs"
import "pkg:/source/utils/StringUtils.bs"
function Init()
m.webAppButton = m.top.findNode("WebAppButton")
m.linkWithWifiButton = m.top.findNode("LinkWithWiFiButton")
m.linkWithTvButton = m.top.findNode("LinkWithTvButton")
m.webAppPanel = m.top.findNode("WebAppPanel")
m.linkWithWifiPanel = m.top.findNode("LinkWithWiFiPanel")
m.linkWithTvPanel = m.top.findNode("LinkWithTvPanel")
m.wifiNameLabel = m.top.findNode("WifiNameLabel")
m.linkCodeLabel = m.top.findNode("LinkCodeLabel")
end function
function OnNodeReady()
SetNavigation(m.webAppButton, "down", m.linkWithWifiButton)
SetNavigation(m.linkWithWifiButton, "down", m.linkWithTvButton)
SetNavigation(m.linkWithTvButton, "up", m.linkWithWifiButton)
SetNavigation(m.linkWithWifiButton, "up", m.webAppButton)
SetNavigation(invalid, "back", m.navBar)
SetNavigation(invalid, "left", m.navBar)
address = m.webserver@.GetServerAddress()
isValidAddress = not StringUtils.IsNullOrEmpty(address)
if isValidAddress
m.top.url = address
end if
m.top.findNode("noInternet").visible = not isValidAddress
m.top.findNode("yesInternet").visible = isValidAddress
m.top.focusable = isValidAddress
m.top.observeField("visible", FuncName(OnVisibleChanged))
m.linkWithWifiPanel.observeField("visible", FuncName(OnLinkWithWifiPanelVisibleChanged))
m.linkWithWifiPanel.visible = false
m.linkWithTvPanel.observeField("visible", FuncName(OnLinkWithTvPanelVisibleChanged))
m.linkWithTvPanel.visible = false
end function
function OnFocusChange() as void
if not m.top.focus
return
end if
if m.currentNavigtionNode = invalid
m.currentNavigtionNode = m.webAppButton
end if
NodeSetFocus(m.currentNavigtionNode, true)
ShowTab(m.currentNavigtionNode)
end function
function OnUrlSet()
url = m.top.url
urlLabel = m.top.findNode("urlLabel")
urlLabel.text = url
qrCodePoster = m.top.findNode("QrCodePoster")
AsyncTask.Start(Tasks.GenerateQrCodeTask, {
poster: qrCodePoster
text: url
size: qrCodePoster.loadWidth
padding: 20
})
end function
function OnkeyEvent(key as string, press as boolean) as boolean
navigation = NavigationKeyHandler(key, press)
if navigation.handled
ShowTab(navigation.node)
return true
end if
return false
end function
function ShowTab(button as object)
if button.isSameNode(m.webAppButton)
m.webAppPanel.visible = true
m.linkWithWifiPanel.visible = false
m.linkWithTvPanel.visible = false
m.currentNavigtionNode = button
else if button.isSameNode(m.linkWithWifiButton)
m.linkWithWifiPanel.visible = true
m.webAppPanel.visible = false
m.linkWithTvPanel.visible = false
m.currentNavigtionNode = button
else if button.isSameNode(m.linkWithTvButton)
m.linkWithTvPanel.visible = true
m.webAppPanel.visible = false
m.linkWithWifiPanel.visible = false
m.currentNavigtionNode = button
end if
end function
function OnVisibleChanged()
if not m.top.visible
m.currentNavigtionNode = invalid
m.webAppPanel.visible = true
m.linkWithWifiPanel.visible = false
m.linkWithTvPanel.visible = false
end if
end function
function OnLinkWithWifiPanelVisibleChanged() as void
if not m.linkWithWifiPanel.visible
return
end if
deviceInfo = CreateObject("roDeviceInfo")
connectionInfo = deviceInfo.GetConnectionInfo()
if connectionInfo.type = "WiFiConnection"
m.wifiNameLabel.text = connectionInfo.ssid
else if connectionInfo.type = "WiredConnection"
m.wifiNameLabel.text = "Wired connection"
else
m.wifiNameLabel.text = "N/A"
end if
end function
function OnLinkWithTvPanelVisibleChanged()
if m.linkWithTvPanel.visible
GeneratePairingCode()
else
if m.linkCodeTask <> invalid
m.linkCodeTask.cancel = true
m.linkCodeTask = invalid
end if
m.linkCodeLabel.text = ""
end if
end function
function GeneratePairingCode()
if m.linkCodeTask <> invalid
m.linkCodeTask.cancel = true
end if
m.linkCodeTask = AsyncTask.Start(Tasks.LoungeGenerateManualPairingCodeTask, {
loungeService: m.loungeService
loungeToken: m.loungeService.loungeToken
screenId: m.loungeService.screenId
' Use deviceName as screenName
screenName: m.loungeService.deviceName
deviceId: m.loungeService.deviceId
}, OnLoungeGenerateManualPairingCodeTaskResult)
end function
function OnLoungeGenerateManualPairingCodeTaskResult(output as object) as void
m.linkCodeTask = invalid
if output.cancelled
return
end if
if not output.success or not output.result.success
' output.error for unhandled exception
error = output.error
if error = invalid
' output.result.error for network errors
error = output.result.error
end if
error = ErrorUtils.Format(error)
LogError(error)
message = `Failed to generate manual pairing code\n${error}`
DialogUtils.ShowDialog(message, "Get TV code fail", true)
return
end if
manualLinkCode = output.result.code
if StringUtils.IsNullOrEmpty(manualLinkCode)
m.linkCodeLabel.text = ""
return
end if
' insert a space every 3 characters.
parts = []
for i = 0 to manualLinkCode.Len() - 1 step 3
parts.Push(manualLinkCode.Mid(i, 3))
end for
linkCode = parts.Join(" ")
m.linkCodeLabel.text = linkCode
end function