lounge fix

This commit is contained in:
Brahim Hadriche committed 2026-10-14 14:26:49 -04:00
1 parent 511bcbffdf
commit 9e7f5e5fed
9 files changed
+175 -14

No files matched your search

+1
View File
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Live streams buffering on slow networks
- Playback errors with a preferred quality set, on some devices
- Lounge (cast from phone) fix a sync issue after reconnecting
- Lounge (cast from phone): closing a video on the TV now updates the phone state
### Changed
@@ -75,7 +75,7 @@ enum PlayerState
PLAYING = 1
PAUSED = 2
BUFFERING = 3
STOPPED = 4
' STOPPED = 4 — never sent by the official TV client. A phone reads 4 as paused.
VIDEO_CUED = 5
ADVERTISEMENT = 1081
UNCONFIRMED = -8002
@@ -40,6 +40,11 @@ namespace LoungeMessages
if player = invalid
commandArgs[FIELD_STATE] = PlayerState.UNSTARTED
commandArgs[FIELD_CURRENT_TIME] = 0
commandArgs[FIELD_DURATION] = 0
commandArgs[FIELD_LOADED_TIME] = 0
commandArgs[FIELD_SEEKABLE_START_TIME] = 0
commandArgs[FIELD_SEEKABLE_END_TIME] = 0
message.commandArgs = commandArgs
return message
end if
@@ -132,8 +137,6 @@ namespace LoungeMessages
return PlayerState.BUFFERING
else if state = "finished"
return PlayerState.ENDED
else if state = "stopped" or state = "stopping"
return PlayerState.STOPPED
end if
return PlayerState.UNSTARTED
@@ -23,7 +23,9 @@ namespace Lounge
end function
function SendOnStateChange() as void
if StringUtils.IsNullOrEmpty(m.loungeService.loungeToken)
' A closed player's late report would land after what replaced it: the queue's empty nowPlaying, or
' the next player's loading frames.
if m.onCloseCalled = true or StringUtils.IsNullOrEmpty(m.loungeService.loungeToken)
return
end if
@@ -351,8 +351,6 @@ function OnVideoContentJobErrorDialogResponse(event as object)
m.videoQueue.closePlayer = true
end if
end if
Lounge.SendOnStateChange()
end function
function MarkVideoWatched(videoId as dynamic, playbackTrackingUrls as dynamic, cpn as dynamic) as void
@@ -1485,7 +1485,6 @@ function OnErrorDialogResponse(event as object) as void
if not shouldPlayNext or not VideoQueueUtils.PlayNext(m.videoQueue, m.invidious, m.preferences)
ClosePlayer()
end if
Lounge.SendOnStateChange()
end function
function ClosePlayer() as void
@@ -44,7 +44,7 @@ function OnPlay() as void
return
end if
m.top.closePlayer = true
RemovePlayer()
end if
player = CreateVideoPlayer()
@@ -70,7 +70,7 @@ function OnPrevious() as void
return
end if
m.top.closePlayer = true
RemovePlayer()
m.top.index -= 1
m.top.play = true
end function
@@ -80,16 +80,24 @@ function OnNext() as void
return
end if
m.top.closePlayer = true
RemovePlayer()
m.top.index += 1
m.top.play = true
end function
function OnClosePlayer() as void
if RemovePlayer()
m.top.loungeService.outgoingMessages = [LoungeMessages.NowPlaying(invalid), LoungeMessages.OnStateChange(invalid)]
end if
end function
' Returns whether a player was open. A replacement calls this, not the closePlayer field: the field tells a
' lounge sender that nothing plays, which between two videos shows an empty nowPlaying.
function RemovePlayer() as boolean
m.top.nowPlaying = invalid
player = m.top.player
if player = invalid
return
return false
end if
player.close = true
@@ -97,6 +105,7 @@ function OnClosePlayer() as void
m.previousPlayer = player
m.top.appController@.FocusTopScreen()
return true
end function
function OnPlayVideo() as void
@@ -123,7 +132,7 @@ function OnPlayVideo() as void
end if
m.top.index = index
m.top.closePlayer = true
RemovePlayer()
m.top.play = true
end function
@@ -201,7 +210,7 @@ function OnPlaylistLoadStateChange() as void
existingIndex = FindPlaylistVideosInQueue(videoNodes)
if existingIndex >= 0
m.top.index = existingIndex + playlistIndex
m.top.closePlayer = true
RemovePlayer()
m.top.play = true
return
end if
@@ -217,7 +226,7 @@ function OnPlaylistLoadStateChange() as void
m.top.index = index + playlistIndex
m.top.closePlayer = true
RemovePlayer()
m.top.play = true
else if playlistOp = "queue"
m.content.appendChildren(videoNodes)
@@ -0,0 +1,109 @@
import "pkg:/components/Services/LoungeService/LoungeConstants.bs"
namespace Tests
@SGNode("VideoQueue")
@suite
class VideoQueueLoungeTests extends Rooibos.BaseTestSuite
@describe("VideoQueue lounge reports")
' Annotated: Rooibos instruments CreateVideoPlayer only for a stubCall in a test or an annotated hook.
@beforeEach
function SetUpQueue()
m.node.loungeMessages = []
loungeService = CreateObject("roSGNode", "Node")
loungeService.addField("outgoingMessages", "array", true)
loungeService.observeFieldScoped("outgoingMessages", FuncName(Tests.RecordLoungeMessages))
m.top.loungeService = loungeService
m.top.appController = CreateObject("roSGNode", "Node")
m.top.content.removeChildrenIndex(m.top.content.getChildCount(), 0)
m.top.content.appendChildren([m.CreateVideo("AAA"), m.CreateVideo("BBB")])
m.top.index = 0
m.top.player = m.CreatePlayer("AAA")
m.stubCall(CreateVideoPlayer, m.CreatePlayer(""))
m.node.loungeMessages.Clear()
end function
function CreateVideo(videoId as string) as object
video = CreateObject("roSGNode", "ContentNode")
video.addFields({ videoId: videoId })
return video
end function
function CreatePlayer(videoId as string) as object
player = CreateObject("roSGNode", "Node")
player.addFields({ close: false, content: m.CreateVideo(videoId) })
return player
end function
function SentCommands(commandType as string) as object
commands = []
for each message in m.node.loungeMessages
if message.commandType = commandType
commands.Push(message)
end if
end for
return commands
end function
@it("tells the lounge nothing plays when the player is closed")
function closeReportsNothingPlays()
player = m.top.player
m.top.closePlayer = true
expectedState = {}
expectedState[FIELD_STATE] = PlayerState.UNSTARTED
expectedState[FIELD_CURRENT_TIME] = 0
expectedState[FIELD_DURATION] = 0
expectedState[FIELD_LOADED_TIME] = 0
expectedState[FIELD_SEEKABLE_START_TIME] = 0
expectedState[FIELD_SEEKABLE_END_TIME] = 0
m.assertEqual(m.node.loungeMessages, [{ commandType: COMMAND_NOW_PLAYING }, { commandType: COMMAND_ON_STATE_CHANGE, commandArgs: expectedState }])
m.assertTrue(player.close)
m.assertInvalid(m.top.player)
end function
@it("tells the lounge nothing when closed with no player open")
function closeWithNoPlayerSaysNothing()
m.top.closePlayer = true
m.node.loungeMessages.Clear()
m.top.closePlayer = true
m.assertEmpty(m.node.loungeMessages)
end function
@it("sends no empty nowPlaying when next replaces the player")
function nextSendsNoEmptyNowPlaying()
player = m.top.player
m.top.next = true
m.assertEmpty(m.SentCommands(COMMAND_NOW_PLAYING))
m.assertEmpty(m.SentCommands(COMMAND_ON_STATE_CHANGE))
m.assertTrue(player.close)
m.assertEqual(m.top.nowPlaying.videoId, "BBB")
end function
@it("sends no empty nowPlaying when another video replaces the player")
function playVideoSendsNoEmptyNowPlaying()
player = m.top.player
m.top.playVideo = m.CreateVideo("CCC")
m.assertEmpty(m.SentCommands(COMMAND_NOW_PLAYING))
m.assertEmpty(m.SentCommands(COMMAND_ON_STATE_CHANGE))
m.assertTrue(player.close)
m.assertEqual(m.top.nowPlaying.videoId, "CCC")
end function
end class
function RecordLoungeMessages(event as object)
m.loungeMessages.Append(event.getData())
end function
end namespace
@@ -0,0 +1,40 @@
import "pkg:/components/Services/LoungeService/LoungeMessages.bs"
namespace Tests
@suite
class LoungeMessagesTests extends Rooibos.BaseTestSuite
@describe("LoungeMessages with no player")
@it("reports an unstarted player with zeroed times")
function onStateChangeNoPlayer()
message = LoungeMessages.OnStateChange(invalid)
expected = {}
expected[FIELD_STATE] = PlayerState.UNSTARTED
expected[FIELD_CURRENT_TIME] = 0
expected[FIELD_DURATION] = 0
expected[FIELD_LOADED_TIME] = 0
expected[FIELD_SEEKABLE_START_TIME] = 0
expected[FIELD_SEEKABLE_END_TIME] = 0
m.assertEqual(message.commandType, COMMAND_ON_STATE_CHANGE)
m.assertEqual(message.commandArgs, expected)
end function
@it("reports an empty nowPlaying")
function nowPlayingNoPlayer()
m.assertEqual(LoungeMessages.NowPlaying(invalid), { commandType: COMMAND_NOW_PLAYING })
end function
@describe("LoungeMessages.GetPlayerState")
@it("reports a stopping or stopped player as unstarted")
function stoppedIsUnstarted()
m.assertEqual(LoungeMessages.GetPlayerState({ state: "stopping" }), PlayerState.UNSTARTED)
m.assertEqual(LoungeMessages.GetPlayerState({ state: "stopped" }), PlayerState.UNSTARTED)
end function
end class
end namespace