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,30 @@
import "pkg:/source/QrCode/QrImage.bs"
import "pkg:/source/utils/StringUtils.bs"
@asynctask
function GenerateQrCodeTask(input as object)
poster = input.poster
mode = input.mode
text = input.text
size = input.size
padding = input.padding
if mode = invalid
mode = QrCode.QRMode.Byte
end if
if size = invalid
size = 200
end if
if padding = invalid
padding = 0
end if
qr = new QrCode.QRImage()
imagePath = qr.Generate(text, size, padding, mode)
if not StringUtils.IsNullOrEmpty(imagePath)
poster.uri = imagePath
end if
end function
@@ -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
@@ -0,0 +1,159 @@
<component name="RemoteScreen" extends="Group" includes="AutoBind,Focus">
<interface>
<field id="navBar" type="node" bind="/NavBar" />
<field id="webServer" type="node" bind="/WebServer" />
<field id="loungeService" type="node" bind="/LoungeService" />
<field id="url" type="string" onChange="OnUrlSet" />
<field id="qrCodeUrl" type="string" onChange="OnUrlSet" />
</interface>
<children>
<Group id="noInternet" visible="false">
<Label
height="720"
width="1280"
font="font:MediumBoldSystemFont"
horizAlign="center"
vertAlign="center"
text="Could not get IP address: are we connected to the internet?"
/>
</Group>
<Group id="yesInternet" visible="false">
<SettingCategory
id="WebAppButton"
displayText="Playlet Web App"
description="Use Playlet Remote in the browser"
minimumWidth="350"
translation="[150,178]" />
<SettingCategory
id="LinkWithWiFiButton"
displayText="Link with Wi-Fi"
description="Cast from the YouTube app to Playlet"
minimumWidth="350"
translation="[150,314]" />
<SettingCategory
id="LinkWithTvButton"
displayText="Link with TV code"
description="Cast from the YouTube app to Playlet"
minimumWidth="350"
translation="[150,450]" />
<Group id="WebAppPanel"
translation="[700,115]">
<Label
height="30"
width="400"
font="font:SmallBoldSystemFont"
horizAlign="center"
text="Scan the QR code" />
<Poster
id="QrCodePoster"
height="400"
width="400"
loadHeight="400"
loadWidth="400"
translation="[0,40]" />
<Label
id="UrlLabel"
height="30"
width="400"
font="font:SmallBoldSystemFont"
horizAlign="center"
translation="[0,460]" />
</Group>
<Group id="LinkWithWiFiPanel"
translation="[700,220]">
<LayoutGroup itemSpacings="[12]">
<LayoutGroup layoutDirection="horiz" itemSpacings="[15]">
<Label
font="font:SmallSystemFont"
text="1." />
<Label
font="font:SmallSystemFont"
width="380"
wrap="true"
text="On your phone, connect to the same Wi-Fi network as this device." />
</LayoutGroup>
<LayoutGroup layoutDirection="horiz" itemSpacings="[15]">
<Label
font="font:SmallSystemFont"
text="2." />
<Label
font="font:SmallSystemFont"
width="380"
wrap="true"
text="Open the YouTube app on your phone." />
</LayoutGroup>
<LayoutGroup layoutDirection="horiz" itemSpacings="[15]">
<Label
font="font:SmallSystemFont"
text="3." />
<Label
font="font:SmallSystemFont"
width="380"
wrap="true"
text="Tap the cast icon and select this device." />
</LayoutGroup>
</LayoutGroup>
<Label
text="Roku connected to:"
translation="[0,220]">
<Font role="font" uri="font:SystemFontFile" size="20" />
</Label>
<Label
id="WifiNameLabel"
color="#4287f5"
translation="[0,250]">
<Font role="font" uri="font:BoldSystemFontFile" size="28" />
</Label>
</Group>
<Group id="LinkWithTvPanel"
translation="[700,220]">
<LayoutGroup itemSpacings="[12]">
<LayoutGroup layoutDirection="horiz" itemSpacings="[15]">
<Label
font="font:SmallSystemFont"
text="1." />
<Label
font="font:SmallSystemFont"
width="380"
wrap="true"
text="On your phone, open the YouTube app." />
</LayoutGroup>
<LayoutGroup layoutDirection="horiz" itemSpacings="[15]">
<Label
font="font:SmallSystemFont"
text="2." />
<Label
font="font:SmallSystemFont"
width="380"
wrap="true"
text="Tap the Chromecast icon." />
</LayoutGroup>
<LayoutGroup layoutDirection="horiz" itemSpacings="[15]">
<Label
font="font:SmallSystemFont"
text="3." />
<Label
font="font:SmallSystemFont"
width="380"
wrap="true"
text="Tap &quot;Link with TV code&quot; and enter the code below." />
</LayoutGroup>
</LayoutGroup>
<Label
id="LinkCodeLabel"
font="font:LargeBoldSystemFont"
color="#4287f5"
translation="[-30,180]"
width="460"
horizAlign="center">
<Font role="font" uri="font:BoldSystemFontFile" size="48" />
</Label>
</Group>
</Group>
</children>
</component>