Skip to content

Xbox Cloud Gaming app for PS5 Homebrew

C

Keep streaming after the server's idle warning

Rafael Abud Ferreiraf59423c791ed
diff --git a/src/app/stream_player.cpp b/src/app/stream_player.cpp
index b003b01..66650ad 100644
--- a/src/app/stream_player.cpp
+++ b/src/app/stream_player.cpp
@@ -8,6 +8,7 @@
#include "media/decoder.h"
#include "platform/platform.h"
#include "stream/stream_session.h"
+#include "ui/strings.h"
#include "util/log.h"
#include <algorithm>
@@ -220,6 +221,9 @@ struct StreamPlayer::Impl {
auto scale = [](uint8_t pct) { return static_cast<uint8_t>(std::min<int>(pct, 100) * 255 / 100); };
input::setRumble(scale(v.leftMotor), scale(v.rightMotor), v.durationMs);
};
+ cb.idleWarning = [](int seconds) {
+ platform::notify(ui::trf(ui::Str::IdleWarning, std::to_string(seconds)));
+ };
cb.closed = [this](const std::string& reason) { end(reason); };
stream::StreamOptions opts;
diff --git a/src/stream/stream_session.cpp b/src/stream/stream_session.cpp
index d312cf4..8941776 100644
--- a/src/stream/stream_session.cpp
+++ b/src/stream/stream_session.cpp
@@ -290,9 +290,17 @@ struct StreamSession::Impl {
std::string id = (*j)["id"].str();
XC_LOGI("message %s %s", type.c_str(), target.c_str());
if (target == "/streaming/sessionLifetimeManagement/serverInitiatedDisconnect") {
- XC_LOGW("server disconnect: %s", (*j)["content"].str().substr(0, 300).c_str());
+ std::string body = (*j)["content"].str();
+ XC_LOGW("server disconnect: %s", body.substr(0, 300).c_str());
completeTransaction(id, json::Value(""));
- fail("the server ended the session");
+ // A warning shares this message with the real kicks: the session
+ // goes on (the xbox.com client only shows a notice).
+ auto content = json::parse(body);
+ if (content && (*content)["reason"].str() == "WarningForBeingIdle") {
+ if (cb.idleWarning) cb.idleWarning(static_cast<int>((*content)["secondsUntilKick"].asInt(120)));
+ } else {
+ fail("the server ended the session");
+ }
} else if (target == "/streaming/systemUi/messages/ShowMessageDialog") {
// No dialog UI yet: log it and pick the first (default) button.
auto content = json::parse((*j)["content"].str());
diff --git a/src/stream/stream_session.h b/src/stream/stream_session.h
index 479f654..4f33c42 100644
--- a/src/stream/stream_session.h
+++ b/src/stream/stream_session.h
@@ -23,6 +23,9 @@ struct StreamCallbacks {
std::function<void(const uint8_t* data, size_t len, uint32_t rtpTimestamp)> video;
std::function<void(const uint8_t* data, size_t len, uint32_t rtpTimestamp)> audio;
std::function<void(const Vibration&)> vibration;
+ // The server will end the session for inactivity in `seconds` unless
+ // input arrives.
+ std::function<void(int seconds)> idleWarning;
// The stream ended (server disconnect, connection lost). Called once.
std::function<void(const std::string& reason)> closed;
};
diff --git a/src/ui/strings.cpp b/src/ui/strings.cpp
index ade3b14..47f4e3c 100644
--- a/src/ui/strings.cpp
+++ b/src/ui/strings.cpp
@@ -75,6 +75,7 @@ constexpr Column kEnglish = {
"Sign-in failed: %s", // SignInFailed
"Could not load the game list: %s", // LibraryFailed
"Could not start the stream: %s", // StreamFailed
+ "No input for a while: you will be disconnected in %s seconds", // IdleWarning
};
constexpr Column kPortugueseBR = {
@@ -120,6 +121,7 @@ constexpr Column kPortugueseBR = {
"Falha ao entrar: %s",
"Não foi possível carregar a lista de jogos: %s",
"Não foi possível iniciar o streaming: %s",
+ "Sem atividade: você será desconectado em %s segundos",
};
constexpr Column kSpanish = {
@@ -165,6 +167,7 @@ constexpr Column kSpanish = {
"Error al iniciar sesión: %s",
"No se pudo cargar la lista de juegos: %s",
"No se pudo iniciar el streaming: %s",
+ "Sin actividad: se te desconectará en %s segundos",
};
constexpr Column kFrench = {
@@ -210,6 +213,7 @@ constexpr Column kFrench = {
"Échec de la connexion : %s",
"Impossible de charger la liste des jeux : %s",
"Impossible de démarrer le streaming : %s",
+ "Aucune activité : vous serez déconnecté dans %s secondes",
};
constexpr Column kGerman = {
@@ -255,6 +259,7 @@ constexpr Column kGerman = {
"Anmeldung fehlgeschlagen: %s",
"Die Spieleliste konnte nicht geladen werden: %s",
"Das Streaming konnte nicht gestartet werden: %s",
+ "Keine Aktivität: Die Verbindung wird in %s Sekunden getrennt",
};
constexpr Column kItalian = {
@@ -300,6 +305,7 @@ constexpr Column kItalian = {
"Accesso non riuscito: %s",
"Impossibile caricare l'elenco dei giochi: %s",
"Impossibile avviare lo streaming: %s",
+ "Nessuna attività: verrai disconnesso tra %s secondi",
};
constexpr std::array<const Column*, kLangs> kTable = {&kEnglish, &kPortugueseBR, &kSpanish,
diff --git a/src/ui/strings.h b/src/ui/strings.h
index 3f698cd..db0f7cc 100644
--- a/src/ui/strings.h
+++ b/src/ui/strings.h
@@ -52,6 +52,7 @@ enum class Str {
SignInFailed, // "%s" = technical detail
LibraryFailed, // "%s" = technical detail
StreamFailed, // "%s" = technical detail
+ IdleWarning, // "%s" = seconds until the server disconnects
Count
};