Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions tests/TizenUiTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ 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(/function stopCurrentHostSession\(\)[\s\S]*?closePeerConnection\(\);[\s\S]*?showToast\("Stopping session"[\s\S]*?\{ busy: true \}/.test(appSource),
"Stop session must leave the stream at once and show a busy toast while the PC closes the app");
assert.ok(/function gamepadUiRoute\(\) \{\s*if \(hostStopFromStream\)/.test(appSource)
&& /addEventListener\("keydown", function \(event\) \{\s*if \(hostStopFromStream\)/.test(appSource),
"gamepad and remote input must be ignored until the PC confirms Stop session");
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");
Expand Down
80 changes: 80 additions & 0 deletions tizen/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -259,6 +260,13 @@ let ui = null;
let artworkLoader = null;
let runningAppId = null;
let hostOperationBusy = false;
// The server 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 hostStopToast = null;
let hostStopTimer = null;
// The server reports the host stop within its own poll window; this only clears the toast.
const HOST_STOP_TOAST_TIMEOUT_MS = 30000;
let runningAppMenuOriginId = null;
let switchTargetApplicationId = null;
let currentGatewayName = "Moonlight Gateway";
Expand Down Expand Up @@ -1526,6 +1534,11 @@ function readableState(state) {
}

function handleSessionStatus(message) {
if (hostStopFromStream) {
// The player already closed when Stop session was chosen; the host status ends the stop.
log("Session status during Stop session: " + message.state);
return;
}
sessionState = message.state;
sessionStateElement.textContent = readableState(message.state);
if (typeof message.sessionId === "number") {
Expand Down Expand Up @@ -1602,8 +1615,24 @@ function handleSessionStatus(message) {
log("Session status: " + message.state);
}

function finishHostStopFromStream() {
if (!hostStopFromStream) {
return;
}
hostStopFromStream = false;
clearTimeout(hostStopTimer);
hostStopTimer = null;
if (hostStopToast) {
hostStopToast.remove();
hostStopToast = null;
}
}

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);
Expand Down Expand Up @@ -1694,6 +1723,48 @@ 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;
}
const appTitle = selectedSession && selectedSession.appTitle ? selectedSession.appTitle : "the application";
const stoppingAppId = appSelect.value;
try {
sendGatewayMessage({ type: "stop-host-session" });
} catch (error) {
reportError("Unable to stop Sunshine application", error);
return;
}
hostOperationBusy = true;
hostStopFromStream = true;
// Leave the stream at once, as Stop streaming does, while the PC closes the application.
closePeerConnection();
currentSessionId = 0;
sessionState = "idle";
showHome("applications");
// The application keeps running on the PC until the host confirms the stop.
setRunningApplication(stoppingAppId);
setHomeMessage("Stopping " + appTitle + "...", false);
if (ui) {
hostStopToast = ui.showToast("Stopping session", "Closing " + appTitle + " on the PC", false,
{ busy: true });
}
hostStopTimer = setTimeout(function () {
finishHostStopFromStream();
hostOperationBusy = false;
setHomeMessage("The PC did not confirm the stop; check the application list.", true);
requestApplications();
updatePlayAvailability();
}, HOST_STOP_TOAST_TIMEOUT_MS);
updatePlayAvailability();
}

function createPeerConnection(sessionId) {
closePeerConnection();
sessionTeardownInProgress = false;
Expand Down Expand Up @@ -2769,6 +2840,10 @@ function exitApplication() {
}

function gamepadUiRoute() {
if (hostStopFromStream) {
// Nothing is navigable until the PC confirms Stop session; the gameplay route ignores input.
return "gameplay";
}
if (!launchingScreen.hidden) {
return "ui";
}
Expand Down Expand Up @@ -3045,6 +3120,10 @@ function openFocusedApplicationMenu() {
}

document.addEventListener("keydown", function (event) {
if (hostStopFromStream) {
event.preventDefault();
return;
}
const key = event.key;
const keyCode = event.keyCode;
const isBack = key === "Backspace" || keyCode === 10009;
Expand Down Expand Up @@ -3104,6 +3183,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);
Expand Down
2 changes: 1 addition & 1 deletion tizen/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ <h1 id="launching-heading">Preparing session</h1>
<div id="performance-fps" class="performance-hud performance-hud-left" hidden><strong id="performance-fps-value">-</strong><span>FPS</span><small id="performance-fps-target">-</small></div>
<dl id="performance-latency" class="performance-hud performance-hud-right" hidden><div><dt>Latency</dt><dd id="performance-latency-total">-</dd></div><div><dt>Average</dt><dd id="performance-latency-average">-</dd></div><div><dt>Network</dt><dd id="performance-latency-network">-</dd></div><div><dt>Jitter buffer</dt><dd id="performance-latency-jitter-buffer">-</dd></div><div><dt>Decode</dt><dd id="performance-latency-decode">-</dd></div><div><dt>To screen</dt><dd id="performance-latency-to-screen">-</dd></div><div><dt>Packet loss</dt><dd id="performance-packet-loss">-</dd></div><div><dt>Dropped</dt><dd id="performance-frames-dropped">-</dd></div></dl>
<aside id="stream-overlay" class="stream-overlay"><h2 id="overlay-app">Desktop</h2><dl class="stream-facts"><div><dt>Latency</dt><dd id="overlay-latency">-</dd></div><div><dt>Packet loss</dt><dd id="overlay-packet-loss">-</dd></div><div><dt>Resolution</dt><dd id="overlay-resolution">-</dd></div><div><dt>FPS</dt><dd id="overlay-fps">60</dd></div><div><dt>Codec</dt><dd id="overlay-codec">H.264</dd></div><div><dt>Bitrate</dt><dd id="overlay-bitrate">-</dd></div><div><dt>HDR</dt><dd id="overlay-hdr">Off</dd></div><div><dt>Gamepad</dt><dd id="overlay-gamepad">Disconnected</dd></div><div><dt>Connection</dt><dd id="overlay-connection">Starting</dd></div><div><dt>Interpolation</dt><dd id="overlay-interpolation">Off</dd></div><div><dt>Recovery</dt><dd id="overlay-recovery">No stalls</dd></div></dl></aside>
<div id="stream-menu" class="stream-menu" hidden><section class="menu-panel" aria-label="Stream menu"><h2>Streaming</h2><div class="menu-actions"><button id="continue-button" class="menu-button focusable" type="button">Resume</button><button id="performance-overlay-button" class="menu-button focusable" type="button">Show performance overlay</button><button id="diagnostics-button" class="menu-button focusable" type="button">Show statistics</button><button id="stop-button" class="menu-button menu-button-danger focusable" type="button">Stop streaming</button></div><p class="menu-hint"><kbd>OK</kbd> Select <kbd class="back-key">&#8592;</kbd> Resume</p></section></div>
<div id="stream-menu" class="stream-menu" hidden><section class="menu-panel" aria-label="Stream menu"><h2>Streaming</h2><div class="menu-actions"><button id="continue-button" class="menu-button focusable" type="button">Resume</button><button id="performance-overlay-button" class="menu-button focusable" type="button">Show performance overlay</button><button id="diagnostics-button" class="menu-button focusable" type="button">Show statistics</button><button id="stop-button" class="menu-button menu-button-danger focusable" type="button">Stop streaming</button><button id="stop-host-stream-button" class="menu-button menu-button-danger focusable" type="button">Stop session</button></div><p class="menu-hint"><kbd>OK</kbd> Select <kbd class="back-key">&#8592;</kbd> Resume</p></section></div>
</section>

<aside id="diagnostics" class="diagnostics" hidden aria-label="WebRTC diagnostics">
Expand Down
2 changes: 1 addition & 1 deletion tizen/ui.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 14 additions & 3 deletions tizen/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,9 +523,17 @@
return false;
};

TizenUi.prototype.showToast = function (title, message, isError) {
// A busy toast shows a spinner and stays until the caller removes the returned element.
TizenUi.prototype.showToast = function (title, message, isError, options) {
const busy = Boolean(options && options.busy);
const toast = document.createElement("div");
toast.className = "toast" + (isError ? " is-error" : "");
toast.className = "toast" + (isError ? " is-error" : "") + (busy ? " is-busy" : "");
if (busy) {
const spinner = document.createElement("span");
spinner.className = "toast-spinner";
spinner.setAttribute("aria-hidden", "true");
toast.appendChild(spinner);
}
const content = document.createElement("div");
content.className = "toast-content";
const heading = document.createElement("span");
Expand All @@ -540,7 +548,10 @@
}
toast.appendChild(content);
this.toastRegion.appendChild(toast);
setTimeout(function () { toast.remove(); }, 3600);
if (!busy) {
setTimeout(function () { toast.remove(); }, 3600);
}
return toast;
};

global.TizenUi = {
Expand Down
Loading