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,338 @@
import "pkg:/components/Services/LoungeService/LoungeMessages.bs"
import "pkg:/components/VideoFeed/FeedLoadState.bs"
import "pkg:/components/VideoQueue/Notifications/VideoQueueNotificationUtils.bs"
import "pkg:/source/AsyncTask/AsyncTask.bs"
import "pkg:/source/AsyncTask/Tasks.bs"
import "pkg:/source/utils/FocusManagement.bs"
import "pkg:/source/utils/Logging.bs"
import "pkg:/source/utils/MathUtils.bs"
import "VideoQueueFunctions.bs"
function Init()
m.content = m.top.findNode("Content")
m.top.content = m.content
m.content.addField("index", "integer", false)
m.content.index = m.top.index
end function
function OnIndexChange()
index = m.top.index
m.content.index = index
nodes = m.content.getChildren(-1, 0)
for each node in nodes
node.queueIndex = index
end for
UpdateHasPreviousNext()
end function
function OnPlay() as void
videoNode = m.content.getChild(m.top.index)
if videoNode = invalid
m.top.nowPlaying = invalid
return
end if
player = m.top.player
if player <> invalid
content = player.content
if content <> invalid and content.videoId = videoNode.videoId
if player.state = "paused"
player.control = "resume"
else
player.control = "play"
end if
return
end if
m.top.closePlayer = true
end if
player = CreateVideoPlayer()
player@.PlayWithContent(videoNode)
m.top.player = player
m.top.nowPlaying = videoNode
end function
function OnPause() as void
player = m.top.player
if player = invalid
return
end if
player.control = "pause"
end function
function OnPrevious() as void
if not m.top.hasPrevious
return
end if
m.top.closePlayer = true
m.top.index -= 1
m.top.play = true
end function
function OnNext() as void
if not m.top.hasNext
return
end if
m.top.closePlayer = true
m.top.index += 1
m.top.play = true
end function
function OnClosePlayer() as void
m.top.nowPlaying = invalid
player = m.top.player
if player = invalid
return
end if
player@.Close()
m.top.player = invalid
m.top.appController@.FocusTopScreen()
end function
function OnPlayVideo() as void
videoNode = m.top.playVideo
if videoNode = invalid
return
end if
m.top.playVideo = invalid
nodeParent = videoNode.getParent()
if not m.content.isSameNode(nodeParent)
videoNode = videoNode.clone(false)
end if
queueCount = m.content.getChildCount()
index = m.top.index
index += 1
if index >= queueCount
m.content.appendChild(videoNode)
index = m.content.getChildCount() - 1
else
m.content.insertChild(videoNode, index)
end if
m.top.index = index
m.top.closePlayer = true
m.top.play = true
end function
function OnPlayPlaylist() as void
playPlaylist = m.top.playPlaylist
if playPlaylist = invalid
return
end if
m.top.playPlaylist = invalid
if m.loadingPlaylist <> invalid
m.loadingPlaylist.UnobserveFieldScoped("loadState")
m.loadingPlaylist = invalid
end if
playlistNode = playPlaylist.playlistNode
playlistIndex = playPlaylist.playlistIndex
if playlistNode = invalid or playlistIndex < 0
return
end if
m.loadingPlaylist = playlistNode
m.loadingPlaylistIndex = playlistIndex
m.loadingPlaylistOp = "play"
if playlistNode.loadState = FeedLoadState.Loaded
OnPlaylistLoadStateChange()
return
end if
playlistNode.ObserveFieldScoped("loadState", FuncName(OnPlaylistLoadStateChange))
playlistNode@.LoadPlaylistAll(m.top.invidious)
end function
function OnPlaylistLoadStateChange() as void
if m.loadingPlaylist = invalid
return
end if
loadState = m.loadingPlaylist.loadState
if loadState = FeedLoadState.None or loadState = FeedLoadState.Error
m.loadingPlaylist.UnobserveFieldScoped("loadState")
m.loadingPlaylist = invalid
return
end if
if loadState <> FeedLoadState.Loaded
return
end if
playlistNode = m.loadingPlaylist
playlistIndex = m.loadingPlaylistIndex
playlistOp = m.loadingPlaylistOp
m.loadingPlaylist.UnobserveFieldScoped("loadState")
m.loadingPlaylist = invalid
videoNodes = playlistNode.getChildren(-1, 0)
if videoNodes.Count() = 0
return
end if
LogInfo("Adding", videoNodes.Count(), "videos to the queue")
for i = 0 to videoNodes.Count() - 1
videoNodes[i] = videoNodes[i].clone(false)
end for
if playlistOp = "play"
queueCount = m.content.getChildCount()
index = m.top.index
index += 1
if index >= queueCount
m.content.appendChildren(videoNodes)
else
m.content.insertChildren(videoNodes, index)
end if
playlistIndex = MathUtils.Clamp(playlistIndex, 0, videoNodes.Count() - 1)
index = index + playlistIndex
m.top.index = index
m.top.closePlayer = true
m.top.play = true
else if playlistOp = "queue"
m.content.appendChildren(videoNodes)
UpdateHasPreviousNext()
queueNotifications = m.top.preferences["misc.queue_notifications"]
if queueNotifications
hintVisible = m.top.player = invalid or not m.top.videoContainer.fullscreen
VideoQueue.ShowNotifcation(m.top.notifications, playlistNode, hintVisible)
end if
end if
end function
function OnClearQueue()
queueCount = m.content.getChildCount()
if queueCount > 0
m.content.removeChildrenIndex(queueCount, 0)
end if
m.top.closePlayer = true
m.top.index = -1
end function
function OnAddToQueue() as void
videoNodes = m.top.addToQueue
if videoNodes = invalid
return
end if
m.top.addToQueue = invalid
if videoNodes.Count() = 0
return
end if
for i = 0 to videoNodes.Count() - 1
videoNodes[i] = videoNodes[i].clone(false)
end for
m.content.appendChildren(videoNodes)
UpdateHasPreviousNext()
queueNotifications = m.top.preferences["misc.queue_notifications"]
if queueNotifications
node = videoNodes[0]
hintVisible = m.top.player = invalid or not m.top.videoContainer.fullscreen
VideoQueue.ShowNotifcation(m.top.notifications, node, hintVisible)
end if
end function
function OnAddToQueuePlaylist() as void
playlistNode = m.top.addToQueuePlaylist
if playlistNode = invalid
return
end if
m.top.addToQueuePlaylist = invalid
if m.loadingPlaylist <> invalid
m.loadingPlaylist.UnobserveFieldScoped("loadState")
m.loadingPlaylist = invalid
end if
m.loadingPlaylist = playlistNode
m.loadingPlaylistOp = "queue"
if playlistNode.loadState = FeedLoadState.Loaded
OnPlaylistLoadStateChange()
return
end if
playlistNode.ObserveFieldScoped("loadState", FuncName(OnPlaylistLoadStateChange))
playlistNode@.LoadPlaylistAll(m.top.invidious)
end function
function OnSetQueueAndIndex() as void
setQueueAndIndex = m.top.setQueueAndIndex
if setQueueAndIndex = invalid
return
end if
m.top.setQueueAndIndex = invalid
videoNodes = setQueueAndIndex.videoNodes
index = setQueueAndIndex.index
queueCount = m.content.getChildCount()
if queueCount > 0
m.content.removeChildrenIndex(queueCount, 0)
end if
if videoNodes.Count() > 0
m.content.appendChildren(videoNodes)
end if
m.top.index = index
end function
function UpdateHasPreviousNext()
queueCount = m.content.getChildCount()
index = MathUtils.Clamp(m.top.index, 0, queueCount - 1)
m.top.hasPrevious = index > 0
m.top.hasNext = index < queueCount - 1
end function
function OnHasPrevious()
message = LoungeMessages.OnHasPreviousNextChanged(m.top.hasPrevious, m.top.hasNext)
m.top.loungeService.outgoingMessages = [message]
end function
function OnHasNext()
' TODO:P1 the hasNext currently does not account for autoplay.
message = LoungeMessages.OnHasPreviousNextChanged(m.top.hasPrevious, m.top.hasNext)
m.top.loungeService.outgoingMessages = [message]
end function
function CreateVideoPlayer() as object
container = m.top.videoContainer
videoPlayer = container.createChild("VideoPlayer")
videoPlayer.id = "VideoPlayer"
videoPlayer@.BindNode()
if container.fullscreen
NodeSetFocus(videoPlayer, true)
dialog = m.top.getScene().dialog
if dialog <> invalid
dialog.close = true
end if
end if
return videoPlayer
end function