* 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>
133 lines
4.0 KiB
Plaintext
133 lines
4.0 KiB
Plaintext
import "pkg:/components/parts/AutoBind/OnNodeReadyNoOp.bs"
|
|
import "pkg:/components/Services/LoungeService/LoungeApi.bs"
|
|
' TODO:P0
|
|
' 1. Add a section about the lounge in the privacy policy
|
|
|
|
function Init()
|
|
m.top.functionName = "LoungeServiceLoop"
|
|
|
|
deviceInfo = CreateObject("roDeviceInfo")
|
|
m.top.deviceId = deviceInfo.GetRandomUUID()
|
|
deviceFriendlyName = deviceInfo.GetFriendlyName()
|
|
if StringUtils.IsNullOrEmpty(deviceFriendlyName)
|
|
deviceFriendlyName = "TV"
|
|
end if
|
|
m.top.deviceName = "Playlet on " + deviceFriendlyName
|
|
end function
|
|
|
|
function StartService(_unused as dynamic) as boolean
|
|
if m.top.isRunning = true
|
|
return true
|
|
end if
|
|
|
|
m.top.control = "run"
|
|
return true
|
|
end function
|
|
|
|
function StopService(_unused as dynamic) as void
|
|
if m.top.isRunning = false
|
|
return
|
|
end if
|
|
|
|
m.top.shouldQuit = true
|
|
end function
|
|
|
|
function LoungeServiceLoop() as void
|
|
api = new LoungeApi(m.top, m.top.videoQueue, m.top.notifications, m.top.invidious)
|
|
' Mobile app can remain connected to devices even after restarts.
|
|
' Since we create a new lounge every time, we signal to the last lounge
|
|
' that we're no longer there, and we're not coming back.
|
|
api.DisconnectFromLastLounge()
|
|
|
|
messagePort = CreateObject("roMessagePort")
|
|
|
|
' We do not join a lounge until something asks us to like
|
|
' - A remote connects through DIAL
|
|
' - Generating a TV link code
|
|
m.top.observeField("join", messagePort)
|
|
wait(0, messagePort)
|
|
m.top.unobserveField("join")
|
|
|
|
|
|
screenId = api.GetScreenId()
|
|
if StringUtils.IsNullOrEmpty(screenId)
|
|
m.top.isRunning = false
|
|
return
|
|
end if
|
|
m.top.screenId = screenId
|
|
|
|
loungeToken = api.GetToken()
|
|
if StringUtils.IsNullOrEmpty(loungeToken)
|
|
m.top.isRunning = false
|
|
return
|
|
end if
|
|
m.top.loungeToken = loungeToken
|
|
|
|
m.top.observeField("outgoingMessages", messagePort)
|
|
|
|
if not api.GetSessionData()
|
|
m.top.unobserveField("outgoingMessages", messagePort)
|
|
m.top.isRunning = false
|
|
return
|
|
end if
|
|
|
|
api.SaveCurrentLoungeData()
|
|
api.FetchCommandsRpc(messagePort)
|
|
|
|
m.top.shouldQuit = false
|
|
isOpen = false
|
|
outgoingLoungeMessages = []
|
|
portMessages = []
|
|
socketMessages = []
|
|
|
|
while true
|
|
if m.top.shouldQuit = true
|
|
exit while
|
|
end if
|
|
|
|
message = wait(60000, messagePort)
|
|
portMessages.Clear()
|
|
portMessages.Push(message)
|
|
|
|
' There's a chance messages were piling up while we were sending messages to the lounge
|
|
' This could happen if we were sending things to the lounge and the player state
|
|
' changed many times.
|
|
while messagePort.PeekMessage() <> invalid
|
|
portMessages.Push(messagePort.GetMessage())
|
|
end while
|
|
|
|
' At this point:
|
|
' - We check if we need to send messages to the lounge based on player state
|
|
' - We check the lounge for new commands, which might need responding to
|
|
' - Finally, we send the outgoing messages to the lounge in one go
|
|
outgoingLoungeMessages.Clear()
|
|
socketMessages.Clear()
|
|
|
|
for each portMessage in portMessages
|
|
messageType = type(portMessage)
|
|
if messageType = "roSocketEvent"
|
|
socketMessages.Push(portMessage)
|
|
else if messageType = "roSGNodeEvent"
|
|
field = portMessage.GetField()
|
|
if field = "outgoingMessages"
|
|
messages = portMessage.GetData()
|
|
outgoingLoungeMessages.Append(messages)
|
|
end if
|
|
end if
|
|
end for
|
|
|
|
isOpen = api.Poll(socketMessages, outgoingLoungeMessages)
|
|
|
|
api.SendMessages(outgoingLoungeMessages)
|
|
api.ProcessPendingOutgoingMessages()
|
|
|
|
if not isOpen
|
|
sleep(3000)
|
|
api.FetchCommandsRpc(messagePort)
|
|
end if
|
|
end while
|
|
|
|
m.top.unobserveField("outgoingMessages", messagePort)
|
|
m.top.isRunning = false
|
|
end function
|