From 0aa7d8e15618c57a13c3b0ce4eaa7b34a6f41fd9 Mon Sep 17 00:00:00 2001 From: luisotavio-dev Date: Tue, 27 Oct 2026 12:03:15 -0300 Subject: [PATCH 1/3] Add Stop session to the stream menu The Back menu while streaming only offered "Stop streaming", which ends the local stream but leaves the application running on the PC, so the next connection resumes it. "Stop session", below it, sends stop-host-session: the Gateway ends the stream, cancels the Sunshine application and reports the host session as stopped. The Gateway ends the stream of a host stop without an idle session status, so the TV now closes the player and returns to the application list when that stopped (or failed) host status arrives. Co-Authored-By: Claude Opus 5.5 (cherry picked from commit 651c72e405326c0bdb5d609a31b183bce476c8c3) --- tests/TizenUiTest.js | 5 +++++ tizen/app.js | 45 ++++++++++++++++++++++++++++++++++++++++++++ tizen/index.html | 2 +- 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/tests/TizenUiTest.js b/tests/TizenUiTest.js index d20a1ba..aa5ccbd 100644 --- a/tests/TizenUiTest.js +++ b/tests/TizenUiTest.js @@ -62,6 +62,11 @@ assert.ok(html.includes('aria-disabled="true"'), "coming-soon rows must be disabled rather than focusable"); assert.ok(html.includes('id="stream-menu"') && html.includes('id="diagnostics-button"'), "the streaming Back menu and statistics control must remain available"); +assert.ok(html.indexOf('id="stop-button"') < html.indexOf('id="stop-host-stream-button"') + && appSource.includes('sendGatewayMessage({ type: "stop-host-session" })'), + "the streaming Back menu must offer Stop session below Stop streaming"); +assert.ok(/state === "stopped" \|\| state === "failed"\) \{\s*finishHostStopFromStream\(\);/.test(appSource), + "Stop session must close the player when the host stop finishes"); assert.ok(html.includes('id="toast-region"'), "notification region is missing"); assert.ok(html.includes('src="application-artwork.js"'), "the Applications screen must load the Gateway artwork transport"); diff --git a/tizen/app.js b/tizen/app.js index 67af093..456014e 100644 --- a/tizen/app.js +++ b/tizen/app.js @@ -98,6 +98,7 @@ const continueButton = document.getElementById("continue-button"); const diagnosticsButton = document.getElementById("diagnostics-button"); const performanceOverlayButton = document.getElementById("performance-overlay-button"); const stopButton = document.getElementById("stop-button"); +const stopHostStreamButton = document.getElementById("stop-host-stream-button"); const homeMessage = document.getElementById("home-message"); const gatewayStateElement = document.getElementById("gateway-state"); const sunshineStateElement = document.getElementById("sunshine-state"); @@ -259,6 +260,9 @@ let ui = null; let artworkLoader = null; let runningAppId = null; let hostOperationBusy = false; +// The Gateway ends the stream of a host stop without an idle status, so the stopped +// (or failed) host status is what closes the player. +let hostStopFromStream = false; let runningAppMenuOriginId = null; let switchTargetApplicationId = null; let currentGatewayName = "Moonlight Gateway"; @@ -1602,8 +1606,22 @@ function handleSessionStatus(message) { log("Session status: " + message.state); } +function finishHostStopFromStream() { + if (!hostStopFromStream) { + return; + } + hostStopFromStream = false; + closePeerConnection(); + currentSessionId = 0; + sessionState = "idle"; + showHome("applications"); +} + function handleHostSessionStatus(message) { const state = String(message.state || "unknown"); + if (state === "stopped" || state === "failed") { + finishHostStopFromStream(); + } if (state === "stopping") { hostOperationBusy = true; setHomeMessage("Stopping running application...", false); @@ -1694,6 +1712,32 @@ function stopCurrentSession() { } } +// Ends the stream and closes the application on the PC; "Stop streaming" keeps it running. +function stopCurrentHostSession() { + hideStreamMenu(); + if (!currentSessionId) { + showHome(); + return; + } + if (hostOperationBusy) { + return; + } + try { + hostOperationBusy = true; + hostStopFromStream = true; + sessionTeardownInProgress = true; + sessionState = "stopping"; + overlay.connection.textContent = "Stopping"; + sessionStateElement.textContent = "Stopping"; + sendGatewayMessage({ type: "stop-host-session" }); + } catch (error) { + hostOperationBusy = false; + hostStopFromStream = false; + sessionTeardownInProgress = false; + reportError("Unable to stop Sunshine application", error); + } +} + function createPeerConnection(sessionId) { closePeerConnection(); sessionTeardownInProgress = false; @@ -3104,6 +3148,7 @@ continueButton.addEventListener("click", hideStreamMenu); diagnosticsButton.addEventListener("click", toggleDiagnostics); performanceOverlayButton.addEventListener("click", togglePerformanceOverlay); stopButton.addEventListener("click", stopCurrentSession); +stopHostStreamButton.addEventListener("click", stopCurrentHostSession); resumeSessionButton.addEventListener("click", resumeRunningApplication); stopHostSessionButton.addEventListener("click", stopRunningApplication); switchCancelButton.addEventListener("click", closeSwitchAppDialog); diff --git a/tizen/index.html b/tizen/index.html index e4b336e..1b17b56 100644 --- a/tizen/index.html +++ b/tizen/index.html @@ -96,7 +96,7 @@

Preparing session

- +