pragma Singleton import QtQuick import "catalog" import "settings" import "account" import "reporting" QtObject { id: root signal backgroundStreamReminderRequested() property ConnectionHealthState connectionHealth: ConnectionHealthState { active: root.activeSession !== null && root.streamerStatus === "streaming" && !root.streamerStopExpected sessionId: String(root.activeSession && root.activeSession.sessionId || "") } property BackgroundStreamState backgroundStreamState: BackgroundStreamState { settings: root.settings applicationActive: Qt.application.state === Qt.ApplicationActive streaming: root.activeSession !== null && root.streamerStatus === "streaming" nativeRuntimeReady: root.nativeRuntimeReady onAudioMuteRequested: muted => root.sendNativeCommand("setAudioMuted", {muted: muted}) onReminderRequested: root.backgroundStreamReminderRequested() } property CatalogState catalogOwnerState: CatalogState { id: catalogOwner coreClient: CoreClient appController: AppController ready: root.ready signedIn: root.signedIn settings: root.settings setSetting: root.setSetting applySetting: root.applySetting acceptsScope: root.matchesAuthScope authScope: ({generation:root.authGeneration, userId:root.authSession && root.authSession.user ? root.authSession.user.userId : "", providerIdpId:root.authSession && root.authSession.provider ? root.authSession.provider.idpId : ""}) detailVisible: AppController.route === "game-detail" definitions: accountServicesOwner.catalogDefinitions onAccessibilityAnnounced: message => root.accessibilityMessage = message onStoreSessionReset: root.storeSessionReset() onLaunchContextInvalidated: root.invalidateLaunchInspection() onLibraryRefreshFinished: (complete, message) => accountServicesOwner.libraryRefreshFinished(complete, message) } property ArtworkState artworkOwnerState: ArtworkState { id: artworkOwner coreClient: CoreClient ready: root.ready } property SettingsState settingsOwnerState: SettingsState { id: settingsOwner coreClient: CoreClient appController: AppController i18n: I18n ready: root.ready subscription: root.subscription authSession: root.authSession scopeGeneration: root.authGeneration settingsActive: String(AppController.route).indexOf("settings") === 0 capabilitiesActive: String(AppController.route).indexOf("settings") === 0 || root.onboardingRequired nativeHdrOutputSupported: HdrOutput.supported providerIdpId: root.authSession && root.authSession.provider ? String(root.authSession.provider.idpId || "") : "" providerCode: root.authSession && root.authSession.provider ? String(root.authSession.provider.code || "") : "" nativeRuntimeReady: root.nativeRuntimeReady nativeRuntimeCapabilities: root.nativeRuntimeCapabilities refreshAccountServices: root.refreshAccountServices refreshStreamerDetection: root.refreshStreamerDetection syncDiscordPresence: root.syncDiscordPresence lastError: root.lastError onConsoleSurfaceRequested: enabled => root.consoleSurfaceRequested(enabled) onAccessibilityAnnounced: message => root.accessibilityMessage = message onErrorReported: message => root.lastError = message onSettingWriteFinished: (token, result, message) => { catalogOwner.finishCollectionWrite(token, result, message) if (result) onboardingOwner.acceptResponse(token, result) else onboardingOwner.acceptFailure(token, message) } onResetStarted: onboardingOwner.interruptForSettingsReset() } property AccountServicesState accountServicesOwnerState: AccountServicesState { id: accountServicesOwner coreClient: CoreClient appController: AppController ready: root.ready signedIn: root.signedIn refreshCatalogAfterAccountChange: catalogOwner.refreshCatalogAfterAccountChange refreshAccountServices: root.refreshAccountServices acceptsScope: root.matchesAuthScope authScope: catalogOwner.authScope onAccessibilityAnnounced: message => root.accessibilityMessage = message } property BugReportState bugReports: BugReportState { coreClient: CoreClient setSetting: root.setSetting ready: root.ready signedIn: root.signedIn settings: root.settings sessionId: String(root.activeSession && root.activeSession.sessionId || "") streaming: root.activeSession !== null && root.streamerStatus === "streaming" && !root.streamerStopExpected uiSurface: root.desktopUiActive ? "desktop" : "console" gameId: String(root.activeSession && root.activeSession.appId || "") decoderBackend: String(root.streamer && root.streamer.mediaBackend || "") } property alias settings: settingsOwner.settings readonly property string selectedRegion: settingsOwner.selectedRegion readonly property string selectedRegionName: { if (!selectedRegion) return "" const region = regions.find(item => item.url === selectedRegion || item.name === selectedRegion) return region ? String(region.name) : qsTr("Selected region") } property alias keyboardLayoutItems: settingsOwner.keyboardLayoutItems property var onboardingAwdlController: MacAwdl readonly property bool onboardingAwdlReady: true property OnboardingState onboardingOwnerState: OnboardingState { id: onboardingOwner persistSetting: (key, value) => settingsOwner.setSetting(key, value, "onboarding") persistedSettings: root.settings ready: root.ready signedIn: root.signedIn checkRequirements: root.checkOnboardingRequirements replayAllowed: root.ready && !root.activeSession && !root.streamBusy && root.activeSessionRequestId === "" && root.sessionClaimRequestId === "" && ["idle", "error"].indexOf(root.streamState) >= 0 && ["starting", "streaming", "stopping"].indexOf(root.streamerStatus) < 0 onRestartRequested: AppController.restartApplication() onRequirementsMissing: root.onboardingRequirementsMissing() onCompleted: { root.consoleSurfaceRequested(root.settings.launchInConsoleMode === true) root.onboardingCompleted() Qt.callLater(root.resolveDirectLaunch) } } readonly property bool onboardingRequired: onboardingOwner.needed readonly property var onboardingSettings: onboardingOwner.settings readonly property bool onboardingSaving: onboardingOwner.saving readonly property string onboardingError: onboardingOwner.error readonly property bool onboardingReplayAvailable: onboardingOwner.replayAllowed && !onboardingOwner.saving && !onboardingOwner.replaying readonly property bool onboardingReplaying: onboardingOwner.replaying readonly property string onboardingReplayError: onboardingOwner.replayError signal onboardingCompleted() signal onboardingRequirementsMissing() function checkOnboardingRequirements() { return "" } function verifyOnboardingRequirements() { return onboardingOwner.verifyRequirements() } function setOnboardingSetting(key, value) { onboardingOwner.setSetting(key, value) if (key === "resolution" || key === "fps") onboardingOwner.setSetting("fps", settingsOwner.resolveEntitledFps( onboardingSettings.resolution, onboardingSettings.fps)) } function resetOnboardingSettings(keys) { onboardingOwner.resetSettings(keys) } function finishOnboarding() { onboardingOwner.finish() } function replayOnboarding() { onboardingOwner.replay() } property alias previewThemePack: settingsOwner.previewThemePack property string accessibilityMessage: "" property alias settingsRequestId: settingsOwner.settingsRequestId property alias shortcutUpdateRequestId: settingsOwner.shortcutUpdateRequestId property alias shortcutUpdateError: settingsOwner.shortcutUpdateError property string lastError: "" property var streamEndNotice: null property var focusPositions: ({}) property var providers: [] property string selectedProviderIdpId: "" readonly property var selectedProvider: selectedProviderIdpId === "" ? (providers.length ? providers[0] : null) : (providers.find(provider => provider.idpId === selectedProviderIdpId) || null) property bool providerDiscoveryDegraded: false property var clockSkewMs: null property bool clockSkewDismissed: false readonly property string clockSkewMessage: { if (clockSkewMs === null) return "" const minutes = Math.ceil(Math.abs(clockSkewMs) / 60000) const amount = minutes >= 90 ? qsTr("about %1 hours").arg(Math.round(minutes / 60)) : qsTr("%1 minutes").arg(minutes) const offset = clockSkewMs > 0 ? qsTr("Your computer's clock is %1 ahead of GeForce NOW.").arg(amount) : qsTr("Your computer's clock is %1 behind GeForce NOW.").arg(amount) return offset + " " + qsTr("Signing in, your library and server list need the correct time. Turn on automatic date and time in your system settings, then restart OpenNOW.") } property int providerRetryAttempts: 0 property Timer providerRetryTimer: Timer { interval: 31000 repeat: false onTriggered: { root.providerRetryAttempts += 1 root.refreshProviders() } } function refreshProviders(manual) { if (!ready || providersRequestId !== "") return if (manual === true) { providerRetryAttempts = 0 providerRetryTimer.stop() } providersRequestId = CoreClient.request("auth.providers.list", {}, 10000) if (providersRequestId === "") scheduleProviderRetry(0) } function scheduleProviderRetry(retryAfterMs) { providerDiscoveryDegraded = true if (ready && providerRetryAttempts < 3) { providerRetryTimer.interval = Math.max(31000, Number(retryAfterMs || 0) + 1000) providerRetryTimer.restart() } } property var authSession: null property var authChallenge: null property string authState: "idle" property string authMessage: "" function settledAuthState(session) { if (session) return "signed-in" return authState === "error" ? "error" : "idle" } property bool addingAccount: false property string accountMessage: "" property Connections accountNavigation: Connections { target: AppController function onRouteChanged() { if (AppController.route !== "sign-in") root.addingAccount = false } } property alias catalogGames: catalogOwner.catalogGames readonly property var gameCollections: catalogOwner.gameCollections property alias activeCollectionId: catalogOwner.activeCollectionId readonly property var activeCollection: catalogOwner.activeCollection readonly property bool collectionsBusy: catalogOwner.collectionsBusy property alias collectionError: catalogOwner.collectionError signal collectionSaved(string collectionId) property Connections collectionSignals: Connections { target: catalogOwner function onCollectionSaved(collectionId) { root.collectionSaved(collectionId) } } function collectionNameError(name, exceptId) { return catalogOwner.collectionNameError(name, exceptId) } function createCollection(name, game) { return catalogOwner.createCollection(name, game) } function renameCollection(id, name) { return catalogOwner.renameCollection(id, name) } function deleteCollection(id) { return catalogOwner.deleteCollection(id) } function toggleCollectionGame(id, game) { return catalogOwner.toggleCollectionGame(id, game) } function isInCollection(game, id) { return catalogOwner.isInCollection(game, id) } property alias selectedGame: catalogOwner.selectedGame property alias catalogTotalCount: catalogOwner.catalogTotalCount property alias catalogState: catalogOwner.catalogState property alias catalogComplete: catalogOwner.catalogComplete property alias catalogError: catalogOwner.catalogError property alias catalogNextCursor: catalogOwner.catalogNextCursor property alias catalogLastCompleteAt: catalogOwner.catalogLastCompleteAt function continueCatalog() { catalogOwner.continueCatalog() } function refreshSelectedMetadata() { catalogOwner.refreshSelectedMetadata() } function readinessNotice(game) { return catalogOwner.readinessNotice(game) } function catalogGenreLabel(genre) { return catalogOwner.genreLabel(genre) } property alias detailMetadataError: catalogOwner.detailError property alias catalogSource: catalogOwner.catalogSource property alias storeGames: catalogOwner.storeGames property alias storeFacets: catalogOwner.storeFacets property alias storeFilters: catalogOwner.storeFilters property alias storeUsesLocalIndex: catalogOwner.storeUsesLocalIndex signal storeSessionReset() property alias storeTotalCount: catalogOwner.storeTotalCount property alias storeState: catalogOwner.storeState property alias storeSource: catalogOwner.storeSource property alias storeError: catalogOwner.storeError property alias storeWarning: catalogOwner.storeWarning property alias storeSearchQuery: catalogOwner.storeSearchQuery property alias storeNextCursor: catalogOwner.storeNextCursor property alias storeHasMore: catalogOwner.storeHasMore property alias storeReplacePage: catalogOwner.storeReplacePage property alias storePageCount: catalogOwner.storePageCount property alias storeSeenCursors: catalogOwner.storeSeenCursors property alias storePresentationRequestId: catalogOwner.storePresentationRequestId property alias storePresentationIndex: catalogOwner.storePresentationIndex property alias storeBrowseCache: catalogOwner.storeBrowseCache property alias storeForceRefresh: catalogOwner.storeForceRefresh property alias storeLastPageCached: catalogOwner.storeLastPageCached readonly property bool storeLoading: catalogOwner.storeLoading property alias storePageTimer: catalogOwner.storePageTimer property alias storeMarquee: catalogOwner.storeMarquee property alias storePanels: catalogOwner.storePanels property alias storeFilterGroups: catalogOwner.storeFilterGroups property string sessionPersistence: "none" property double authGeneration: 0 property var authWarnings: [] property bool authRestorePending: true property bool pendingStaySignedIn: true signal consoleSurfaceRequested(bool enabled) property alias consoleSurfaceRequestId: settingsOwner.consoleSurfaceRequestId property alias consoleSurfaceConfirmedValue: settingsOwner.consoleSurfaceConfirmedValue property alias consoleSurfaceDesiredValue: settingsOwner.consoleSurfaceDesiredValue property alias consoleSurfaceRequestValue: settingsOwner.consoleSurfaceRequestValue property alias consoleSurfaceInitialized: settingsOwner.consoleSurfaceInitialized property alias consoleSurfaceError: settingsOwner.consoleSurfaceError property bool desktopUiActive: false property alias subscription: accountServicesOwner.subscription readonly property alias remainingPlaytimeHours: accountServicesOwner.remainingPlaytimeHours readonly property alias dlssOverrideAvailability: accountServicesOwner.dlssOverrides readonly property alias dlssFrameGenerationMultipliers: accountServicesOwner.dlssFrameGenerationMultipliers readonly property alias dlssDynamicFrameGeneration: accountServicesOwner.dlssDynamicFrameGeneration function dlssCapability(name) { return accountServicesOwner.dlssCapability(name) } property alias regions: accountServicesOwner.regions property alias regionPingResults: accountServicesOwner.regionPingResults property alias regionPingMessage: accountServicesOwner.regionPingMessage property alias regionPingPending: accountServicesOwner.regionPingPending readonly property bool regionPingBusy: accountServicesOwner.regionPingBusy property var savedAccounts: [] property alias gameAccounts: accountServicesOwner.gameAccounts readonly property alias actionableGameAccounts: accountServicesOwner.actionableGameAccounts property alias gameAccountsState: accountServicesOwner.gameAccountsState property alias gameAccountMessage: accountServicesOwner.gameAccountMessage property alias syncOperation: accountServicesOwner.syncOperation function cancelSyncObservation() { accountServicesOwner.cancelSyncObservation() } function storeSubscriptionLabels(account) { return accountServicesOwner.storeSubscriptionLabels(account) } function gameAccountAction(account) { return accountServicesOwner.gameAccountAction(account) } property alias accountLinkAttempt: accountServicesOwner.accountLinkAttempt property alias storageLocations: accountServicesOwner.storageLocations property alias storageMessage: accountServicesOwner.storageMessage property var mediaItems: [] property string mediaRootPath: "" property string mediaState: "idle" property string mediaMessage: "" property var diagnostics: ({entries: []}) property string diagnosticsMessage: "" property var updaterState: ({status: "idle", currentVersion: Qt.application.version, canCheck: false}) property string updaterError: "" property string updaterFailureMessage: "" property bool updaterInstallConfirmed: false property bool updaterExitScheduled: false property bool updaterReconciling: false property double lastAutoUpdateCheckMs: 0 property string autoDownloadAttempt: "" property int autoDownloadAttemptCount: 0 property double autoDownloadAttemptMs: 0 readonly property bool sessionWorkIdle: !activeSession && !streamBusy && !sessionRecoveryPending && activeSessionRequestId === "" && sessionClaimRequestId === "" && streamCreateRequestId === "" && streamerStartRequestId === "" && streamerPrepareRequestId === "" && streamerStopRequestId === "" && ["idle", "error"].indexOf(streamState) >= 0 && ["stopped", "error"].indexOf(streamerStatus) >= 0 readonly property bool updaterSessionSafe: sessionWorkIdle && !pendingLaunchParams && !pendingDirectLaunch readonly property bool clockSkewSessionSafe: sessionWorkIdle readonly property bool applicationQuitNeedsConfirmation: settings.confirmQuitWhenIdle !== false || !updaterSessionSafe || resumableSession !== null readonly property bool updaterBusy: updaterReconciling || updaterCheckRequestId !== "" || updaterDownloadRequestId !== "" || updaterInstallRequestId !== "" || ["checking", "downloading", "preparing", "awaiting-exit", "applying", "restarting"].indexOf(updaterState.status) >= 0 readonly property bool updaterCanInstall: ready && updaterSessionSafe && !updaterBusy && updaterState.canInstall === true readonly property bool updaterNeedsReconciliation: updaterReconciling || updaterInstallConfirmed || ["preparing", "awaiting-exit", "applying", "restarting", "managed-pending"].indexOf(updaterState.status) >= 0 // One attention state for the desktop status-bar chip, its panel and // Settings › Updates. Empty means there is nothing to act on. readonly property string updaterAttention: updaterState.status === "downloading" ? "downloading" : ["preparing", "awaiting-exit", "applying", "restarting"].indexOf(updaterState.status) >= 0 ? "installing" : updaterError !== "" || ["error", "failed", "rolled-back"].indexOf(updaterState.status) >= 0 ? "error" : updaterState.canDownload === true ? "available" : updaterState.canInstall === true ? "ready" : "" // Received fraction of the signed package while the core downloads it, or -1. readonly property real updaterDownloadFraction: updaterState.status === "downloading" && updaterState.downloadProgress && Number(updaterState.downloadProgress.totalBytes) > 0 ? Math.min(1, Number(updaterState.downloadProgress.receivedBytes) / Number(updaterState.downloadProgress.totalBytes)) : -1 onUpdaterSessionSafeChanged: { if (updaterSessionSafe && releaseHighlightsPending) { accessibilityMessage = qsTr("Release notes are available in Updates.") releaseHighlightsPending = false } } property var releaseHighlights: ({}) property bool releaseHighlightsPending: false property var socialCapabilities: ({ friendsAvailable: false, presenceAvailable: false, invitesAvailable: false, localControllerJoin: true, reason: qsTr("Checking provider social capabilities…") }) property string reportingMessage: "" property string reportingState: "idle" property string pinMode: "unlock" property string pinTargetUserId: "" property string pinTargetName: qsTr("Profile") property string pinMessage: "" property var activeSession: null property var streamIdleWarning: null property string colorFormatSessionId: "" property string pendingRequestedColorQuality: "" property string streamRequestedColorQuality: "" property var streamColorFormat: null property var streamColorNotice: null property bool streamColorNoticeShown: false property bool streamColorProfileObserved: false property var streamHdrNotice: null property bool streamHdrNoticeShown: false property string dropSessionId: "" property string sessionReportDropId: "" property var streamDropCounts: ({}) onActiveSessionChanged: { if (!activeSession) antiAfkEnabled = false if (!activeSession && pendingAccountSwitch) Qt.callLater(continuePendingAccountSwitch) const sessionId = String(activeSession && activeSession.sessionId || "") if (sessionId !== sessionAdSessionId) abandonSessionAdReports(sessionId) if (sessionId !== streamRecordingIntentSessionId) streamRecordingIntentSessionId = "" if (streamIdleWarning && streamIdleWarning.sessionId !== sessionId) streamIdleWarning = null if (sessionId !== mediaRecordingTargetSessionId) cancelRecordingTarget() if (streamRecordingAttempt && sessionId !== streamRecordingAttempt.sessionId) { suspendRecordingStart() if (sessionId !== "") streamRecordingAttempt = null } if (sessionId !== colorFormatSessionId) { colorFormatSessionId = sessionId streamRequestedColorQuality = "" streamColorFormat = null streamColorNotice = null streamColorNoticeShown = false streamColorProfileObserved = false streamHdrNotice = null streamHdrNoticeShown = false } if (sessionId !== "" && sessionId !== dropSessionId) { dropSessionId = sessionId streamDropCounts = {videoDropCount: 0, audioDiscardedMs: 0, audioPacketDropCount: 0, callbackDropCount: 0, otherQueueDropCount: 0} } } onStreamDropCountsChanged: { if (lastSessionReport && sessionReportDropId !== "" && sessionReportDropId === dropSessionId) lastSessionReport = Object.assign({}, lastSessionReport, {drops: streamDropCounts}) } property var remoteSessions: [] property var pendingLaunchParams: null property string launchInspectRequestId: "" property string launchInspectStage: "" property string launchInspectSeatId: "" property string directLookupRequestId: "" property var storeLaunchTarget: null property string storeLaunchRequestId: "" property var storeLaunchDecision: ({status:"metadata_unconfirmed", message:""}) property bool storeLaunchFailed: false property alias ownershipConfirmation: catalogOwner.ownershipConfirmation property alias selectedLaunchDecision: catalogOwner.selectedLaunchDecision property alias cloudMutationBusy: catalogOwner.mutationBusy property alias cloudMutationState: catalogOwner.mutationState property alias cloudMutationMessage: catalogOwner.mutationMessage property alias remoteFavorites: catalogOwner.remoteFavorites property alias remoteFavoritesState: catalogOwner.favoritesState property alias remoteFavoritesError: catalogOwner.favoritesError function isCloudFavorite(game) { return catalogOwner.isCloudFavorite(game) } function toggleCloudFavorite(game) { catalogOwner.toggleCloudFavorite(game) } function requestOwnershipConfirmation(action) { catalogOwner.requestOwnershipConfirmation(action) } function confirmOwnership() { catalogOwner.confirmOwnership() } function selectPreferredVariant() { catalogOwner.selectPreferredVariant() } function refreshCloudFavorites() { catalogOwner.refreshFavorites() } function selectedGameActionLabel() { if (!signedIn) return qsTr("Sign in") if (cloudMutationBusy || launchInspectRequestId !== "") return qsTr("Checking…") if (selectedLaunchDecision.status === "ownership_required") return qsTr("I own this game") if (selectedLaunchDecision.status === "selection_required") return qsTr("Use this store version") if (selectedLaunchDecision.status === "ready") return qsTr("Play") return qsTr("Check availability") } function activateSelectedGame() { if (selectedLaunchDecision.status === "ownership_required") requestOwnershipConfirmation("add") else if (selectedLaunchDecision.status === "selection_required") selectPreferredVariant() else launchSelectedGame() } function invalidateLaunchInspection() { const id = launchInspectRequestId launchInspectRequestId = "" launchInspectStage = "" launchInspectSeatId = "" if (id !== "") CoreClient.cancel(id) } function launchIntentCurrent() { return ready && signedIn && pendingLaunchParams && pendingLaunchParams.selectionIdentity === catalogOwner.selectedIdentity && pendingLaunchParams.authGeneration === authGeneration && pendingLaunchParams.actionGeneration === catalogOwner.actionGeneration && pendingLaunchParams.requestContextKey === catalogOwner.requestContextKey && !catalogOwner.mutationBusy } function inspectLaunch(stage) { if (launchInspectRequestId !== "") return if (!launchIntentCurrent()) { streamState = "error" streamMessage = qsTr("The selected game or account changed. Choose the store version again.") lastError = streamMessage return } launchInspectStage = stage launchInspectSeatId = stage === "stop" && conflictSession ? String(conflictSession.sessionId) : "" const inspectParams = { appId:pendingLaunchParams.catalogAppId, variantId:pendingLaunchParams.variantId } if (pendingLaunchParams.storeLaunch === true) inspectParams.storeLaunch = true launchInspectRequestId = CoreClient.request("catalog.launch.inspect", inspectParams, 30000) } function invalidateStoreLaunch() { const id = storeLaunchRequestId storeLaunchRequestId = "" storeLaunchTarget = null storeLaunchFailed = false storeLaunchDecision = {status:"metadata_unconfirmed", message:""} if (id !== "") CoreClient.cancel(id) } function failStoreLaunch(decision) { storeLaunchTarget = null storeLaunchFailed = true storeLaunchDecision = decision if (AppController.route !== "persistent-storage") AppController.navigate("persistent-storage") } function inspectStoreLaunch() { if (!ready || !signedIn || storeLaunchRequestId !== "") return storeLaunchFailed = false storeLaunchRequestId = CoreClient.request("catalog.launch.store.inspect", {}, 30000) } function launchStoreGame() { const target = storeLaunchTarget if (!target || storeLaunchDecision.status !== "ready" || !target.game) return if (!signedIn) { AppController.navigate("sign-in") return } const variants = target.game.variants || [] const index = variants.findIndex(variant => String(variant.id) === String(target.variantId)) if (index < 0) return selectedGame = Object.assign({}, target.game, {selectedVariantIndex:index}) launchSelectedGame(false) } property Connections launchInspectionResponses: Connections { target: CoreClient function onResponseReceived(id, result) { if (id !== "" && id === root.directLookupRequestId) { root.directLookupRequestId = "" const requested = root.pendingDirectLaunch if (!requested || !root.matchesAuthScope(result.scope) || !result.game) return const index = (result.game.variants || []).findIndex(variant => String(variant.id) === requested.appId) if (index < 0) { root.lastError = qsTr("The exact requested store version was not returned.") root.pendingDirectLaunch = null return } root.selectedGame = Object.assign({}, result.game, {selectedVariantIndex:index}) root.pendingDirectLaunch = null root.launchSelectedGame(true) return } if (id !== "" && id === root.storeLaunchRequestId) { root.storeLaunchRequestId = "" root.storeLaunchFailed = false if (!root.matchesAuthScope(result.scope)) { root.storeLaunchTarget = null root.storeLaunchDecision = {status:"metadata_unconfirmed", message:qsTr("The account changed. Refresh the store launch and try again.")} return } root.storeLaunchDecision = result.decision || {status:"metadata_unconfirmed", message:""} const ready = result.decision && result.decision.status === "ready" && result.game && result.appId && result.variantId root.storeLaunchTarget = ready ? { appId:String(result.appId), variantId:String(result.variantId), title:String(result.game.title || "Steam"), game:result.game } : null return } if (id === "" || id !== root.launchInspectRequestId) return const stage = root.launchInspectStage const seatId = root.launchInspectSeatId root.launchInspectRequestId = "" root.launchInspectStage = "" root.launchInspectSeatId = "" const storeOriginated = root.pendingLaunchParams && root.pendingLaunchParams.storeLaunch === true if (!root.launchIntentCurrent() || !root.matchesAuthScope(result.scope) || result.appId !== root.pendingLaunchParams.catalogAppId || result.variantId !== root.pendingLaunchParams.variantId) { root.streamState = "error" root.streamMessage = qsTr("The selected game or account changed. Choose the store version again.") root.lastError = root.streamMessage if (storeOriginated) { root.pendingLaunchParams = null root.failStoreLaunch({status:"metadata_unconfirmed", message:root.streamMessage}) } return } const variant = result.game && result.game.id === root.pendingLaunchParams.catalogAppId ? (result.game.variants || []).find(item => String(item.id) === root.pendingLaunchParams.variantId) : null if (!variant) { root.streamState = "error" root.streamMessage = qsTr("The exact requested store version was not returned.") root.lastError = root.streamMessage if (storeOriginated) { root.pendingLaunchParams = null root.failStoreLaunch({status:"metadata_unconfirmed", message:root.streamMessage}) } return } catalogOwner.adoptGame(result.game) root.pendingLaunchParams = Object.assign({}, root.pendingLaunchParams, { accountLinked:variant.inLibrary === true, supportsInGameSettingsPersistence:variant.supportsInGameSettingsPersistence === true, title:result.game.title }) root.selectedLaunchDecision = result.decision || ({status:"metadata_unconfirmed", message:""}) if (root.selectedLaunchDecision.status !== "ready") { root.streamState = "error" root.streamMessage = root.selectedLaunchDecision.message || qsTr("Availability could not be confirmed. Refresh and try again.") root.lastError = root.streamMessage root.pendingLaunchParams = null if (storeOriginated) root.failStoreLaunch(root.selectedLaunchDecision) else AppController.navigateFromLastPrimary("game-detail") return } if (stage === "discover") { root.continueInspectedLaunch() } else if (stage === "stop") { if (!root.conflictSession || String(root.conflictSession.sessionId) !== seatId) { root.streamState = "error" root.streamMessage = qsTr("The running session changed. Check your sessions again before replacing a game.") root.lastError = root.streamMessage return } root.forceNewAfterStop = true root.streamState = "stopping" root.streamMessage = qsTr("Closing the previous cloud session…") root.streamStopRequestId = CoreClient.request("session.stop", { sessionId:root.conflictSession.sessionId, streamingBaseUrl:root.conflictSession.streamingBaseUrl, serverIp:root.conflictSession.serverIp || "" }, 35000) } else if (stage === "create") { root.streamState = "requesting" root.launchRequestedAtMs = Date.now() root.pendingRequestedColorQuality = String(root.settings.colorQuality || "8bit_420") root.streamCreateRequestId = CoreClient.request("session.create", Object.assign({}, root.pendingLaunchParams, { runtimeCapabilities: root.nativeRuntimeCapabilities, maxEntitledFps: settingsOwner.maxEntitledFps(String(root.settings.resolution || "")), // Active display physical DPI (auto per screen / OS). screenDpi: AppController.screenDpi(), devicePixelRatio: Screen.devicePixelRatio }), 60000) } } function onRequestFailed(id, code, message) { if (id !== "" && id === root.directLookupRequestId) { root.directLookupRequestId = "" root.pendingDirectLaunch = null root.lastError = message } else if (id !== "" && id === root.launchInspectRequestId) { root.launchInspectRequestId = "" root.launchInspectStage = "" root.launchInspectSeatId = "" root.streamState = "error" root.streamMessage = message root.lastError = message if (root.pendingLaunchParams && root.pendingLaunchParams.storeLaunch === true) { root.pendingLaunchParams = null root.failStoreLaunch({status:"metadata_unconfirmed", message:message}) } } else if (id !== "" && id === root.storeLaunchRequestId) { root.storeLaunchRequestId = "" root.storeLaunchTarget = null root.storeLaunchFailed = true root.storeLaunchDecision = {status:"metadata_unconfirmed", message:message} } } } property var pendingDirectLaunch: null property var conflictSession: null property bool conflictSessionNeedsRefresh: false property bool launchConflictDetected: false property bool forceNewAfterStop: false property var streamer: null property var streamerDetection: ({available: false, availableCodecs: [], capabilities: ({})}) property string streamerDetectionMessage: qsTr("Checking native codec support…") property string streamState: "idle" property string streamMessage: "" property SessionSetupProgress sessionSetupProgress: SessionSetupProgress { session: root.activeSession } property int streamerRestartAttempts: 0 property bool streamerRecoveryExhausted: false property int sessionReconnectAttempts: 0 readonly property int maximumSessionReconnectAttempts: 8 property int streamPollFailureAttempts: 0 readonly property int maximumStreamPollFailureAttempts: 8 property bool sessionRecoveryPending: false property bool sessionRecoveryAwaitingAuth: false property string recoverySessionId: "" property string recoveryDiscoveryRequestId: "" property int resumePollAttempts: 0 property double resumePollDeadlineMs: 0 property int streamerRestartRecoveryCount: 0 property int sessionRecoveryCount: 0 property var guidePagesVisited: [] property alias regionsVpcId: accountServicesOwner.regionsVpcId property string providersRequestId: "" property string authSessionRequestId: "" property string activeSessionRequestId: "" property string coreSessionRestoreId: "" property string sessionStopIntentId: "" property string remoteSessionDiscoveryRequestId: "" property string remoteSessionsRequestId: "" property string sessionClaimRequestId: "" property bool sessionClaimIsRecovery: false property string streamCreateRequestId: "" property string streamPollRequestId: "" property string streamStopRequestId: "" property string streamerStartRequestId: "" property string streamerPrepareRequestId: "" property string streamerStopRequestId: "" property bool streamerStopExpected: false property alias artworkUrls: artworkOwner.artworkUrls property alias artworkPending: artworkOwner.artworkPending property alias artworkRequestSources: artworkOwner.artworkRequestSources property alias artworkRetrySources: artworkOwner.artworkRetrySources property alias artworkInterests: artworkOwner.artworkInterests property alias storeShelfCache: catalogOwner.storeShelfCache property alias storeShelfEpoch: catalogOwner.storeShelfEpoch function cachedStoreShelf(category, limit) { return catalogOwner.cachedStoreShelf(category, limit) } function cacheStoreShelf(category, limit, games) { return catalogOwner.cacheStoreShelf(category, limit, games) } function resetStoreShelves() { return catalogOwner.resetStoreShelves() } property alias catalogRequestId: catalogOwner.catalogRequestId property alias storeRequestId: catalogOwner.storeRequestId property string deviceStartRequestId: "" property string devicePollRequestId: "" property string deviceCompleteRequestId: "" property string logoutRequestId: "" property string logoutAllRequestId: "" property alias subscriptionRequestId: accountServicesOwner.subscriptionRequestId property alias regionsRequestId: accountServicesOwner.regionsRequestId property alias regionPingRequestId: accountServicesOwner.regionPingRequestId property string accountsRequestId: "" property string accountSwitchRequestId: "" property string accountRemoveRequestId: "" property string accountSwitchTargetUserId: "" property bool accountsLoaded: false property bool launchAccountPickerConsidered: false property var accountSwitchConfirmTarget: null property var pendingAccountSwitch: null property string pinRequestId: "" property alias gameAccountsRequestId: accountServicesOwner.gameAccountsRequestId property alias gameAccountActionRequestId: accountServicesOwner.gameAccountActionRequestId property alias accountLinkStartRequestId: accountServicesOwner.accountLinkStartRequestId property alias accountLinkPollRequestId: accountServicesOwner.accountLinkPollRequestId property alias storageLocationsRequestId: accountServicesOwner.storageLocationsRequestId property alias storageResetRequestId: accountServicesOwner.storageResetRequestId property string sessionAdRequestId: "" property string sessionAdSessionId: "" property var sessionAdReports: [] property var sessionAdInFlight: null property int sessionAdRetryAttempts: 0 property Timer sessionAdRetryTimer: Timer { interval: Math.min(30000, 1000 * Math.pow(2, Math.min(5, root.sessionAdRetryAttempts))) onTriggered: { stop() root.flushSessionAdReports() } } property string mediaRequestId: "" property string mediaDeleteRequestId: "" property string mediaRecordingTargetRequestId: "" property string mediaRecordingTargetSessionId: "" property string streamRecordingStartRequestId: "" property string streamRecordingStopRequestId: "" property var streamRecordingAttempt: null property string streamRecordingIntentSessionId: "" property string pendingRecordingPath: "" property string pendingRecordingThumbnailPath: "" property string mediaClipTargetRequestId: "" property string streamClipRequestId: "" readonly property bool streamClipBusy: mediaClipTargetRequestId !== "" || streamClipRequestId !== "" property bool streamReplayEnabled: false readonly property bool replayBufferRequested: settings.replayBufferEnabled === true onReplayBufferRequestedChanged: { if (!replayBufferRequested) disableStreamReplay() } property bool streamRecordingActive: false property double streamRecordingElapsedMs: 0 property double streamRecordingStartedAtMs: 0 property string diagnosticsRequestId: "" property string diagnosticsExportRequestId: "" property string acceptanceExportRequestId: "" property string updaterStateRequestId: "" property string updaterCheckRequestId: "" property string updaterHighlightsRequestId: "" property string updaterDownloadRequestId: "" property string updaterInstallRequestId: "" property string socialCapabilitiesRequestId: "" property string discordRequestId: "" property double streamStartedAtMs: 0 property double launchRequestedAtMs: 0 property string feedbackRequestId: "" property string bugReportRequestId: "" property string streamInputPauseRequestId: "" property string streamControlRequestId: "" property string streamControlAction: "" property string streamControlMessage: "" property rect streamCaptureRect: Qt.rect(0, 0, 0, 0) property bool nativeRuntimeReady: false readonly property int nativeProtocolVersion: 8 property var nativeRuntimeCapabilities: ({}) property var audioOutputDevices: [] property bool audioOutputDevicesBusy: false property string audioOutputDevicesError: "" property string audioOutputDevicesRequestId: "" property Timer audioOutputDevicesTimeout: Timer { interval: 10000 onTriggered: { root.takeNativeRequest(root.audioOutputDevicesRequestId) root.audioOutputDevicesRequestId = "" root.audioOutputDevicesBusy = false root.audioOutputDevices = [] root.audioOutputDevicesError = qsTr("Audio device discovery timed out. Try refreshing again.") } } property int nativeRequestSequence: 0 property var nativeRequests: ({}) property int overlayRequestGeneration: 0 property int screenshotRequestGeneration: 0 property Connections screenshotCaptureEvents: Connections { target: AppController function onStreamScreenshotSaved(path) { root.acceptStreamScreenshot(path) } } property int recordingToggleRequestGeneration: 0 property int shortcutActionGeneration: 0 property var runtimeStreamProfile: ({}) property bool antiAfkEnabled: false // Ctrl+Shift+F12 while frame generation is on: the source frame slot repeats the // latest generated frame instead of the decoded one. property bool generatedFramesOnly: false property var lastSessionReport: null property bool desiredStreamInputPaused: false property bool currentStreamInputPaused: false property bool streamInputStateKnown: false readonly property bool ready: CoreClient.state === "ready" readonly property bool signedIn: authSession !== null readonly property string sessionStatus: activeSession ? String(activeSession.phase || activeSession.status || "requesting") : "idle" readonly property string streamerStatus: streamer ? String(streamer.status || "unknown") : "stopped" readonly property var negotiatedStreamProfile: activeSession && activeSession.negotiatedStreamProfile ? activeSession.negotiatedStreamProfile : ({}) readonly property int streamerRecoveryCount: streamerRestartRecoveryCount + Number(streamer && streamer.deviceRecoveryCount || 0) readonly property string sessionPersistenceMessage: { if (sessionPersistence === "local-file") return qsTr("Your session tokens are saved unencrypted on disk because the OS keychain is unavailable. Anyone who can read this file can access your account.") if (sessionPersistence === "unavailable") return qsTr("Your saved session could not be restored. Unlock your OS keychain and restart OpenNOW, or sign in again.") if (sessionPersistence === "memory-only") return qsTr("This session is memory-only and will not last after you quit.") if (sessionPersistence === "migration-pending") return qsTr("Secure account migration is pending. Unlock your system credential store and restart OpenNOW.") if (authWarnings.length > 0) return qsTr("Account credential cleanup is pending. Your saved data has been retained for recovery.") return "" } readonly property bool streamBusy: streamCreateRequestId !== "" || streamStopRequestId !== "" || pendingSessionEnd !== null || remoteSessionsRequestId !== "" || sessionClaimRequestId !== "" || launchInspectRequestId !== "" || queueSelector.opened || queueLaunchWaitingForSubscription || settingsOwner.settingWrites.webrtcCompatibilityMode !== undefined signal fullscreenToggleRequested() signal pointerLockToggleRequested() signal streamCaptureAnnounced(string message) signal textInputErrorAnnounced(string message) signal consoleScreenshotRequested() readonly property var resumableSession: { if (root.activeSession) { const localStatus = Number(root.activeSession.status || 0) const localPhase = String(root.activeSession.phase || "").toLowerCase() if ((localStatus >= 2 && localStatus <= 5) || localPhase === "ready" || localPhase === "streaming") return root.activeSession } const sessions = root.remoteSessions || [] for (let index = 0; index < sessions.length; ++index) { const status = Number(sessions[index] && sessions[index].status || 0) if (status >= 2 && status <= 5) return sessions[index] } return null } property string sessionMicrophoneMode: "disabled" property string microphoneRequestId: "" property string microphoneRecoverySessionId: "" property bool microphoneRecoveryEnabled: false readonly property bool microphoneCaptureSupported: nativeRuntimeReady && nativeRuntimeCapabilities.supportsMicrophone === true readonly property bool microphoneSessionActive: Boolean(activeSession && streamer && streamer.status === "streaming") readonly property bool microphoneSessionSupported: microphoneSessionActive && Boolean(streamer.capabilities && streamer.capabilities.supportsMicrophone === true) readonly property bool microphoneToggleAvailable: microphoneSessionSupported readonly property bool microphoneCanToggle: microphoneToggleAvailable && microphoneRequestId === "" readonly property string microphoneState: !microphoneSessionActive ? "disabled" : String(streamer.microphoneState || (microphoneSessionSupported ? "muted" : "unavailable")) readonly property bool microphoneEnabled: microphoneSessionActive && microphoneState === "ready" && streamer.microphoneEnabled === true readonly property string microphoneLabel: microphoneState === "ready" && microphoneEnabled ? qsTr("Open microphone") : microphoneState === "muted" ? qsTr("Muted") : microphoneState === "error" ? qsTr("Microphone error") : microphoneState === "unavailable" ? qsTr("Unavailable") : qsTr("Disabled") readonly property string microphoneActionLabel: microphoneEnabled ? qsTr("Mute microphone") : qsTr("Unmute microphone") readonly property string microphoneDescription: microphoneSessionActive && streamer.microphoneMessage ? String(streamer.microphoneMessage) : qsTr("Uses the system default microphone. Open microphone sends audio continuously. You can mute or unmute during supported sessions. The startup preference applies to the next session.") property Timer devicePollTimer: Timer { interval: 5000 repeat: false running: false onTriggered: root.pollDeviceLogin() } property Timer streamPollTimer: Timer { interval: 1500 repeat: true running: false onTriggered: root.pollStreamingSession() } property var pendingSessionEnd: null property string sessionEndRequestId: "" property string nativeEndedSessionId: "" property Timer sessionEndRetryTimer: Timer { interval: 1000 repeat: true running: root.ready && root.pendingSessionEnd !== null && root.sessionEndRequestId === "" onTriggered: root.flushPendingSessionEnd() } property Timer remoteSessionRefreshTimer: Timer { interval: 30000 repeat: true running: root.signedIn && AppController.route !== "stream" onTriggered: root.refreshRemoteSessions() } property Timer antiAfkPulseTimer: Timer { interval: 240000 repeat: true running: root.antiAfkEnabled && root.activeSession && root.streamer && root.streamer.status === "streaming" onTriggered: root.controlStream("anti-afk-pulse") } property alias artworkRetryTimer: artworkOwner.artworkRetryTimer property Timer streamRecordingTimer: Timer { interval: 250 repeat: true running: root.streamRecordingActive onTriggered: root.streamRecordingElapsedMs = Math.max(0, Date.now() - root.streamRecordingStartedAtMs) } property alias accountLinkPollTimer: accountServicesOwner.accountLinkPollTimer property Timer streamerRestartTimer: Timer { interval: Math.min(8000, 1000 * Math.pow(2, Math.min(3, root.sessionReconnectAttempts))) repeat: false onTriggered: root.recoverStreamingSession(root.streamMessage) } property Timer recoveryStopTimer: Timer { interval: 30000 repeat: false running: root.sessionRecoveryPending && root.streamerStopRequestId !== "" onTriggered: { // Keep the outstanding stop ownership: starting another connection // while a decoder/transport worker is still alive is unsafe. root.sessionRecoveryPending = false root.streamState = "error" root.streamMessage = qsTr("The previous native stream is still stopping. Retry after cleanup finishes, or restart OpenNOW.") root.lastError = root.streamMessage } } // VN fork guard (vn-translation): this build must never auto-check // upstream releases. Upstream's updater is hardcoded to // OpenCloudGaming/OpenNOW with an Ed25519 key this fork does not have, // so an upstream offer could only confuse — and a VN build has no // signed update channel of its own yet. Manual update checks still // work (and are fail-closed without a pinned key), but the automatic // 6-hour check is off in VN builds. See docs/vn-translation/UPDATER.md. readonly property bool vnTranslationBuild: true property Timer autoUpdateCheckTimer: Timer { interval: root.lastAutoUpdateCheckMs === 0 ? 15000 : 60000 repeat: true running: !root.vnTranslationBuild && root.ready && (root.settings.autoCheckForUpdates === true || root.settings.autoDownloadUpdates === true) onTriggered: root.runAutomaticUpdates() } property Timer updaterReconcileTimer: Timer { interval: 2000 repeat: true running: root.ready && root.updaterNeedsReconciliation onTriggered: root.refreshUpdaterState() } function refreshSettings() { return settingsOwner.refreshSettings() } function initializeServices() { if (!ready) return if (!signedIn) authRestorePending = true refreshSettings() providersRequestId = CoreClient.request("auth.providers.list", {}, 25000) authSessionRequestId = CoreClient.request("auth.session.get", {}) refreshSavedAccounts() coreSessionRestoreId = activeSession && activeSession.ownerScope ? String(activeSession.sessionId || "") : "" if (coreSessionRestoreId !== "") { streamPollTimer.stop() streamPollFailureAttempts = 0 } else { activeSessionRequestId = CoreClient.request("session.active.get", {}) } ensureNativeRuntimeReady() updaterStateRequestId = CoreClient.request("updater.state.get", {}) socialCapabilitiesRequestId = CoreClient.request("social.capabilities.get", {}) refreshCatalog() } function refreshStreamerDetection() { streamerDetectionMessage = qsTr("Checking native codec support…") ensureNativeRuntimeReady() if (nativeRuntimeReady) acceptNativeCapabilities(nativeRuntimeCapabilities) } function refreshRemoteSessions() { if (!ready || !signedIn || activeSession || pendingLaunchParams || streamBusy || remoteSessionDiscoveryRequestId !== "" || remoteSessionsRequestId !== "") return remoteSessionDiscoveryRequestId = CoreClient.request("session.remote.list", {}, 30000) } function sessionGameTitle(session) { if (!session) return "" const appId = String(session.appId || "") if (appId === "") return "" const games = catalogGames || [] for (let gameIndex = 0; gameIndex < games.length; ++gameIndex) { const game = games[gameIndex] if (String(game.launchAppId || "") === appId) return String(game.title || "") const variants = game.variants || [] for (let variantIndex = 0; variantIndex < variants.length; ++variantIndex) { if (String(variants[variantIndex] && variants[variantIndex].id || "") === appId) return String(game.title || "") } } return "" } function selectGameForSession(session) { if (!session) return const appId = String(session.appId || "") const games = catalogGames || [] for (let index = 0; index < games.length; ++index) { const variantIndex = (games[index].variants || []).findIndex(variant => String(variant.id) === appId) if (appId !== "" && variantIndex >= 0) { selectedGame = Object.assign({}, games[index], {selectedVariantIndex:variantIndex}) return } } selectedGame = {title:sessionGameTitle(session) || qsTr("Your running game"), launchAppId:appId, variants:[], selectedVariantIndex:-1} } function resumeActiveSession() { const session = resumableSession if (!session || sessionClaimRequestId !== "") return selectGameForSession(session) if (activeSession && String(activeSession.sessionId || "") === String(session.sessionId || "")) { if (AppController.route !== "stream") AppController.navigate("stream") if (!streamer || streamer.status === "stopped" || streamer.status === "error") recoverStreamingSession(qsTr("Resuming your active GeForce NOW session…")) return } conflictSession = session conflictSessionNeedsRefresh = false streamState = "resuming" streamMessage = qsTr("Resuming your active GeForce NOW session…") sessionClaimIsRecovery = false sessionClaimRequestId = CoreClient.request("session.claim", { sessionId: session.sessionId, streamingBaseUrl: session.streamingBaseUrl, appId: String(session.appId || "0"), recoveryMode: true }, 35000) AppController.navigate("inserting") } function codecNamesFromCapabilities(capabilities) { return settingsOwner.codecNamesFromCapabilities(capabilities) } function acceptNativeCapabilities(capabilities) { nativeRuntimeCapabilities = capabilities || ({}) const codecs = codecNamesFromCapabilities(nativeRuntimeCapabilities) streamerDetection = { available: Boolean(nativeRuntimeCapabilities.supportsVideoDecode && nativeRuntimeCapabilities.supportsVideoPresent), capabilities: nativeRuntimeCapabilities, availableCodecs: codecs } streamerDetectionMessage = codecs.length ? qsTr("Available: ") + codecs.map(codec => String(codec).toUpperCase()).join(", ") : qsTr("No native video decoder is available") } function sendNativeCommand(type, params, operation) { if (!NativeStreamRuntime.running && !NativeStreamRuntime.start()) { const message = NativeStreamRuntime.lastError || qsTr("The embedded media runtime could not start") lastError = message return "" } nativeRequestSequence += 1 const requestId = "qt-" + nativeRequestSequence const command = Object.assign({id: requestId, type: type}, params || ({})) if (!NativeStreamRuntime.send(command)) { lastError = NativeStreamRuntime.lastError || qsTr("The embedded media runtime rejected a command") return "" } const requests = Object.assign({}, nativeRequests) requests[requestId] = Object.assign({operation: operation || type}, params || ({})) if (operation === "recording-stop" || operation === "stop") requests[requestId].recordingRequestId = streamRecordingAttempt ? streamRecordingAttempt.requestId : "" nativeRequests = requests return requestId } function takeNativeRequest(requestId) { const pending = nativeRequests[requestId] if (pending === undefined) return null const requests = Object.assign({}, nativeRequests) delete requests[requestId] nativeRequests = requests return pending } function refreshAudioOutputDevices() { if (audioOutputDevicesBusy || !nativeRuntimeReady) return audioOutputDevicesError = "" audioOutputDevicesBusy = true audioOutputDevicesRequestId = sendNativeCommand("audioDevices", {}, "audioDevices") if (audioOutputDevicesRequestId === "") { audioOutputDevicesBusy = false audioOutputDevicesError = lastError } else { audioOutputDevicesTimeout.restart() } } function ensureNativeRuntimeReady() { if (nativeRuntimeReady) return const requests = nativeRequests || ({}) for (const requestId in requests) { if (requests[requestId].operation === "hello") return } const requestId = sendNativeCommand("hello", { protocolVersion: nativeProtocolVersion }, "hello") if (requestId === "" && streamer && streamer.status === "starting") updateStreamerFields({status: "error", message: lastError || qsTr("The embedded media runtime could not start"), errorCode: "streamer_start_failed"}) } function codecAvailable(codec) { return settingsOwner.codecAvailable(codec) } function codecDisabledByProfile(codec) { return settingsOwner.codecDisabledByProfile(codec) } function codecsDisabledByProfile() { return settingsOwner.codecsDisabledByProfile() } function hdrDecoderAvailable() { return settingsOwner.hdrDecoderAvailable() } function tenBitAllowedByMembership() { return settingsOwner.tenBitAllowedByMembership() } function gameLockedByMembership(game) { return Boolean(game && game.requiresPaidMembership === true) && settingsOwner.membershipTierName() === "FREE" } // Frame generation facade: levels, target FPS, display refresh and the capability test // are owned by SettingsState. function frameGenerationFactor() { return settingsOwner.frameGenerationFactor() } function frameGenerationRequestedFactor() { return settingsOwner.frameGenerationRequestedFactor() } function frameGenerationMode() { return settingsOwner.frameGenerationMode() } function frameGenerationMatrix() { return settingsOwner.frameGenerationMatrix() } function toggleFrameGeneration() { settingsOwner.toggleFrameGeneration() } function frameGenerationQuickText() { return settingsOwner.frameGenerationQuickText() } function frameGenerationQuickVisible() { return settingsOwner.frameGenerationQuickVisible() } function frameGenerationEngineNotice() { return settingsOwner.frameGenerationEngineNotice() } function frameGenerationVerdictFor(fps) { return settingsOwner.frameGenerationVerdictFor(fps) } function frameGenerationModes() { return settingsOwner.frameGenerationModes } function selectFrameGenerationMode(mode) { settingsOwner.selectFrameGenerationMode(mode) } function frameGenerationMultiplierDescription() { return settingsOwner.frameGenerationMultiplierDescription() } function frameGenerationTargetDescription() { return settingsOwner.frameGenerationTargetDescription() } function frameGenerationUnlocked() { return settingsOwner.frameGenerationUnlocked() } function frameGenerationProfileKey() { return settingsOwner.frameGenerationProfileKey() } function frameGenerationTestDescription() { return settingsOwner.frameGenerationTestDescription() } function frameGenerationSourceFps() { return settingsOwner.frameGenerationSourceFps() } function frameGenerationDisplayHz() { return settingsOwner.frameGenerationDisplayHz() } function frameGenerationDescription() { return settingsOwner.frameGenerationDescription() } function frameGenerationOutputDescription() { return settingsOwner.frameGenerationOutputDescription() } function frameGenerationDisplayDescription() { return settingsOwner.frameGenerationDisplayDescription() } function frameGenerationLockedValues() { return settingsOwner.frameGenerationLockedValues() } function frameGenerationLockedHint() { return settingsOwner.frameGenerationLockedHint() } function frameGenerationTargetOptions() { return settingsOwner.frameGenerationTargetOptions() } function frameGenerationDisplayChoices() { return settingsOwner.frameGenerationDisplayChoices } function selectFrameGenerationLevel(value) { settingsOwner.selectFrameGenerationLevel(value) } function selectFrameGenerationTarget(value) { settingsOwner.selectFrameGenerationTarget(value) } function selectFrameGenerationDisplayHz(value) { settingsOwner.selectFrameGenerationDisplayHz(value) } function runFrameGenerationTest() { settingsOwner.runFrameGenerationTest() } function ensureFrameGenerationGpu() { settingsOwner.ensureFrameGenerationGpu() } function canonicalFpsValues() { return settingsOwner.canonicalFpsValues() } function presetFpsForResolution(width, height) { return settingsOwner.presetFpsForResolution(width, height) } function isFpsCoveredByEntitlement(width, height, fps) { return settingsOwner.isFpsCoveredByEntitlement(width, height, fps) } function entitledFpsForResolution(resolution) { return settingsOwner.entitledFpsForResolution(resolution) } function unentitledFpsValues(resolution) { return settingsOwner.unentitledFpsValues(resolution) } function lockedFpsValues(resolution) { return settingsOwner.lockedFpsValues(resolution) } function selectableFpsValues(resolution) { return settingsOwner.selectableFpsValues(resolution) } function frameRateReason(value) { return settingsOwner.frameRateReason(value) } function maxEntitledFps(resolution) { return settingsOwner.maxEntitledFps(resolution) } function lockedFpsReason() { return settingsOwner.lockedFpsReason() } function resolveEntitledFps(resolution, requested) { return settingsOwner.resolveEntitledFps(resolution, requested) } function clampFpsToEntitlement() { return settingsOwner.clampFpsToEntitlement() } function refreshCatalog(searchQuery) { return catalogOwner.refreshCatalog(searchQuery) } function reloadCatalogForSession() { return catalogOwner.reloadCatalogForSession() } function ensureStore(searchQuery, filters) { return catalogOwner.ensureStore(searchQuery, filters) } function videoBackendItems() { return settingsOwner.videoBackendItems() } function resolutionItems() { return settingsOwner.resolutionItems() } function refreshStore(searchQuery, forceRefresh, filters) { return catalogOwner.refreshStore(searchQuery, forceRefresh, filters) } function cancelStoreRequests() { return catalogOwner.cancelStoreRequests() } function requestStorePage() { return catalogOwner.requestStorePage() } function requestStorePresentation() { return catalogOwner.requestStorePresentation() } function retryStore() { return catalogOwner.retryStore() } function acceptStorePage(result) { return catalogOwner.acceptStorePage(result) } function reloadStoreForSession() { return catalogOwner.reloadStoreForSession() } function refreshSavedAccounts(invalidate) { if (!ready || (accountsRequestId !== "" && !invalidate)) return const previous = accountsRequestId accountsRequestId = "" if (previous !== "") CoreClient.cancel(previous) accountsRequestId = CoreClient.request("auth.accounts.list", {}) } // Nobody signed in with a saved account (PIN-locked or expired restore) // always picks. A restored account only picks once per launch, with two // or more accounts and "start as the last-used account" off. function accountPickerLaunchDecision(accountCount, signedIn, startAsLastUsed) { if (accountCount <= 0) return false if (!signedIn) return true return accountCount >= 2 && !startAsLastUsed } function showSavedAccountSelection() { if (!ready || authRestorePending || authSessionRequestId !== "" || accountsRequestId !== "" || !accountsLoaded || addingAccount || activeSession || streamBusy || pendingDirectLaunch || coreSessionRestoreId !== "" || authState !== (signedIn ? "signed-in" : "idle")) return if (signedIn && Object.keys(settings).length === 0) return const launch = !launchAccountPickerConsidered launchAccountPickerConsidered = true if ((signedIn && !launch) || !accountPickerLaunchDecision(savedAccounts.length, signedIn, settings.startAsLastUsedAccount === true)) return if (AppController.route === "home" || AppController.route === "sign-in") AppController.navigate("accounts") } // Session routes belong to the seat's owner. Every way out of the picker // and every completed switch checks this one rule, so nobody lands on an // empty stream for a seat they do not own. function sessionRouteWithoutOwnedSeat(route) { return ["stream", "inserting", "joining"].indexOf(route) >= 0 && !(Boolean(activeSession) && sessionOwnerSignedIn()) } function leaveAccountPicker() { const back = AppController.backRoute if (back === "" || ["sign-in", "accounts", "profile-pin"].indexOf(back) >= 0 || sessionRouteWithoutOwnedSeat(back)) AppController.navigateFromLastPrimary("home") else AppController.goBack() } // The one place a completed auth.accounts.switch decides where to land, // whichever entry point started it. function settleRouteAfterAccountSwitch() { const route = AppController.route if (!authSession) { if (route === "profile-pin") AppController.navigate("accounts") return } if (route === "accounts" || route === "profile-pin") { if (Boolean(activeSession) && sessionOwnerSignedIn()) AppController.navigate("stream") else leaveAccountPicker() } else if (sessionRouteWithoutOwnedSeat(route)) { AppController.navigateFromLastPrimary("home") } } // auth.accounts.switch never ends a cloud seat, so picking anyone but the // seat's owner must end it through the confirmation first. function accountSwitchEndsSession(account) { if (!activeSession && streamCreateRequestId === "" && sessionClaimRequestId === "" && !pendingLaunchParams) return false const owner = activeSession && activeSession.ownerScope return !(owner && account && String(owner.userId) === String(account.userId)) } function isActiveAccount(account) { return Boolean(account && authSession && authSession.user && String(account.userId) === String(authSession.user.userId)) } // Every entry point (picker, sidebar switcher, Ctrl+1-9, command palette) // picks through here. Returns what happens next so the picker can show its // inline PIN pad: "active", "confirm", "sign-in", "pin" or "switch". function chooseAccount(account, inlinePin) { if (!account || !ready || accountSwitchRequestId !== "") return "" if (isActiveAccount(account)) return "active" if (accountSwitchEndsSession(account)) { accountSwitchConfirmTarget = account AppController.showOverlay("account-switch-confirm") accessibilityMessage = qsTr("Confirm ending the cloud session to switch to %1").arg(account.displayName || "") return "confirm" } return continueAccountChoice(account, "", inlinePin) } function continueAccountChoice(account, pin, inlinePin) { if (account.needsSignIn) { beginAccountSignIn(account) return "sign-in" } if (account.hasPin && !pin) { if (!inlinePin) openPin("unlock", account) return "pin" } switchAccount(account.userId, pin) return "switch" } function chooseAccountAt(index) { return chooseAccount(savedAccounts[index] || null, false) } function confirmAccountSwitch() { const target = accountSwitchConfirmTarget accountSwitchConfirmTarget = null AppController.showOverlay("") if (!target) return pendingAccountSwitch = target accountMessage = "" stopStreamingSession() continuePendingAccountSwitch() } function cancelAccountSwitch() { accountSwitchConfirmTarget = null if (AppController.overlay === "account-switch-confirm") AppController.showOverlay("") } function continuePendingAccountSwitch() { if (!pendingAccountSwitch || accountSwitchEndsSession(pendingAccountSwitch) || streamStopRequestId !== "") return const target = pendingAccountSwitch pendingAccountSwitch = null continueAccountChoice(target, "", false) } function beginAccountSignIn(account) { const idpId = String(account && account.providerIdpId || "") if (idpId !== "" && providers.some(provider => provider.idpId === idpId)) selectedProviderIdpId = idpId beginAddAccount() } function refreshAccountServices() { refreshSavedAccounts() if (!ready || !signedIn) return if (subscriptionRequestId === "") subscriptionRequestId = CoreClient.request("account.subscription.get", {}, 30000) if (regionsRequestId === "") regionsRequestId = CoreClient.request("network.regions.list", {}, 30000) if (gameAccountsRequestId === "") { gameAccountsState = gameAccounts.length ? "refreshing" : "loading" gameAccountsRequestId = CoreClient.request("account.connections.list", {}, 30000) } refreshRemoteSessions() } function acceptPushInvalidation(payload) { if (!ready || !signedIn) return if (Number(payload.generation || 0) !== Number(authGeneration)) return switch (String(payload.kind || "")) { case "library": catalogOwner.refreshCatalog("") break case "favorites": catalogOwner.refreshFavorites() break case "subscription": case "linked-account": refreshAccountServices() break case "platform-sync": accountServicesOwner.pollSync() break default: break } } function refreshRegions() { return accountServicesOwner.refreshRegions() } function pingRegions() { return accountServicesOwner.pingRegions() } function resetRegionPing() { return accountServicesOwner.resetRegionPing() } function refreshGameAccounts() { return accountServicesOwner.refreshGameAccounts() } function captureAccountScope() { return accountServicesOwner.captureAuthScope() } function startAccountLink(provider, scope) { return accountServicesOwner.startAccountLink(provider, scope) } function pollAccountLink() { return accountServicesOwner.pollAccountLink() } function syncGameAccount(provider, scope) { return accountServicesOwner.syncGameAccount(provider, scope) } function unlinkGameAccount(provider, scope) { return accountServicesOwner.unlinkGameAccount(provider, scope) } function refreshStorageLocations() { return accountServicesOwner.refreshStorageLocations() } function resetPersistentStorage(regionCode, scope) { return accountServicesOwner.resetPersistentStorage(regionCode, scope) } function refreshMedia() { if (!ready || mediaRequestId !== "") return mediaState = mediaItems.length ? "refreshing" : "loading" mediaRequestId = CoreClient.request("media.list", {}, 15000) } function deleteMedia(item) { if (!ready || !item || mediaDeleteRequestId !== "") return mediaMessage = qsTr("Deleting ") + item.fileName + "…" mediaDeleteRequestId = CoreClient.request("media.delete", { kind: item.kind, id: item.id, confirmed: true }, 15000) } function refreshDiagnostics() { if (!ready || diagnosticsRequestId !== "") return diagnosticsMessage = qsTr("Loading redacted diagnostics…") diagnosticsRequestId = CoreClient.request("diagnostics.snapshot", {}) } function exportDiagnostics() { if (!ready || diagnosticsExportRequestId !== "") return diagnosticsMessage = qsTr("Creating redacted diagnostic export…") diagnosticsExportRequestId = CoreClient.request("diagnostics.export", { runtimeCapabilities: nativeRuntimeCapabilities, embeddedStream: {drops: streamDropCounts}, lastSessionReport: lastSessionReport ? {drops: lastSessionReport.drops} : null }, 15000) } function recordGuidePage(page) { const allowed = ["guide-session", "guide-controls", "guide-media", "guide-shortcuts"] if (allowed.indexOf(page) < 0 || guidePagesVisited.indexOf(page) >= 0) return guidePagesVisited = guidePagesVisited.concat([page]) } function exportAcceptanceEvidence() { if (!ready || acceptanceExportRequestId !== "") return diagnosticsMessage = qsTr("Creating machine-verifiable live evidence…") acceptanceExportRequestId = CoreClient.request("acceptance.export", { windowSystem: Qt.platform.pluginName, shell: { streamerRecoveryCount: streamerRecoveryCount, sessionRecoveryCount: sessionRecoveryCount, guidePagesVisited: guidePagesVisited } }, 120000) } function checkForUpdates() { if (!ready || updaterBusy || updaterState.canCheck !== true) return updaterError = "" autoDownloadAttempt = "" autoDownloadAttemptCount = 0 updaterCheckRequestId = CoreClient.request("updater.check", { channel: settings.updateChannel || "stable" }, 30000) } function downloadUpdate() { if (!ready || updaterBusy || updaterState.canDownload !== true) return updaterError = "" updaterDownloadRequestId = CoreClient.request("updater.download", {}, 300000) } function installUpdate(confirmed) { if (confirmed !== true || !updaterCanInstall) return updaterError = "" updaterInstallConfirmed = true updaterInstallRequestId = CoreClient.request("updater.install", {confirmed: true}, 30000) } function refreshUpdaterState() { if (ready && updaterStateRequestId === "") updaterStateRequestId = CoreClient.request("updater.state.get", {}) } function acceptUpdaterState(state) { if (["failed", "rolled-back"].indexOf(state.status) >= 0 && state.message && (state.status !== updaterState.status || state.message !== updaterState.message)) updaterFailureMessage = state.message if (state.status !== updaterState.status || ["error", "failed", "rolled-back", "succeeded", "managed-pending", "reboot-required"].indexOf(state.status) >= 0) updaterError = "" updaterState = state updaterReconciling = false if (state.message) accessibilityMessage = state.message if (updaterInstallConfirmed && state.status === "awaiting-exit" && state.exitRequired === true && updaterSessionSafe && !updaterExitScheduled) { updaterExitScheduled = true Qt.callLater(function() { if (updaterInstallConfirmed && updaterState.status === "awaiting-exit" && updaterState.exitRequired === true && updaterSessionSafe) AppController.quitApplication() else updaterExitScheduled = false }) } else if (["failed", "rolled-back", "succeeded", "managed-pending", "reboot-required"].indexOf(state.status) >= 0 || (state.canInstall === true && updaterInstallRequestId === "")) { updaterInstallConfirmed = false } } function reconcileUpdaterFailure(message) { updaterError = message accessibilityMessage = message updaterReconciling = true refreshUpdaterState() } function runAutomaticUpdates() { if (root.vnTranslationBuild) return // VN fork: no automatic upstream update checks (see above). if (!ready || !updaterSessionSafe || updaterBusy) return if (settings.autoDownloadUpdates === true && updaterState.canDownload === true) { const release = String(updaterState.availableVersion || updaterState.releaseUrl || "") + ":" + String(settings.updateChannel || "stable") if (release !== autoDownloadAttempt) { autoDownloadAttempt = release autoDownloadAttemptCount = 0 } if (autoDownloadAttemptCount < 3 && (autoDownloadAttemptCount === 0 || Date.now() - autoDownloadAttemptMs >= 60000 * Math.pow(2, autoDownloadAttemptCount - 1))) { autoDownloadAttemptCount += 1 autoDownloadAttemptMs = Date.now() downloadUpdate() return } } if (settings.autoCheckForUpdates === true && updaterState.canCheck === true && (lastAutoUpdateCheckMs === 0 || Date.now() - lastAutoUpdateCheckMs >= (updaterState.status === "error" ? 300000 : 21600000))) { lastAutoUpdateCheckMs = Date.now() checkForUpdates() } } function acknowledgeUpdateHighlights() { if (ready && releaseHighlights.version) CoreClient.request("updater.highlights.ack", {version: releaseHighlights.version}) } function submitFeedback(category, message) { if (!ready || feedbackRequestId !== "") return reportingState = "submitting" reportingMessage = qsTr("Sending feedback…") feedbackRequestId = CoreClient.request("feedback.submit", { category: category, message: message, includeSystemInfo: true }, 30000) } function submitBugReport(title, description, includeDiagnostics) { if (!ready || bugReportRequestId !== "") return reportingState = "submitting" reportingMessage = qsTr("Uploading bug report…") bugReportRequestId = CoreClient.request("bug_report.submit", { title: title, description: description, includeDiagnostics: includeDiagnostics }, 60000) } function switchAccount(userId, pin) { cancelDeviceLogin() if (ready && accountSwitchRequestId === "") { accountMessage = "" accountSwitchTargetUserId = String(userId || "") accountSwitchRequestId = CoreClient.request("auth.accounts.switch", { userId: userId, pin: pin || "" }, 30000) } } function removeAccount(userId) { if (ready && accountRemoveRequestId === "") { accountMessage = "" accountRemoveRequestId = CoreClient.request("auth.accounts.remove", { userId: userId }) } } function openPin(mode, account) { pinMode = mode pinTargetUserId = account && account.userId ? account.userId : (authSession ? authSession.user.userId : "") pinTargetName = account && account.displayName ? account.displayName : (authSession ? authSession.user.displayName : "Profile") pinMessage = qsTr("") AppController.navigate("profile-pin") } function submitPin(pin) { if (!ready || pinRequestId !== "" || !pinTargetUserId) return pinMessage = qsTr("Checking PIN…") if (pinMode === "unlock") { switchAccount(pinTargetUserId, pin) return } const method = pinMode === "clear" ? "auth.pin.clear" : "auth.pin.set" const params = pinMode === "clear" ? { userId: pinTargetUserId, currentPin: pin } : { userId: pinTargetUserId, pin: pin } pinRequestId = CoreClient.request(method, params, 30000) } function openGame(game) { return catalogOwner.openGame(game) } function selectGameVariant(index) { return catalogOwner.selectGameVariant(index) } function gameIdentity(game) { return catalogOwner.gameIdentity(game) } function isFavorite(game) { return catalogOwner.isFavorite(game) } function toggleFavorite(game) { return catalogOwner.toggleFavorite(game) } function isHidden(game) { return catalogOwner.isHidden(game) } function hiddenGameCount() { return catalogOwner.hiddenGameCount() } function toggleHidden(game) { return catalogOwner.toggleHidden(game) } function addToHome(game) { return catalogOwner.addToHome(game) } function removeFromHome(game) { return catalogOwner.removeFromHome(game) } function setHomeOrder(ids) { return catalogOwner.setHomeOrder(ids) } function homeTileSize(game) { return catalogOwner.homeTileSize(game) } function setHomeTileSize(game, size) { return catalogOwner.setHomeTileSize(game, size) } function acceptDirectLaunch(appId, title) { const previous = directLookupRequestId directLookupRequestId = "" if (previous !== "") CoreClient.cancel(previous) pendingDirectLaunch = { appId: String(appId || ""), title: String(title || "").trim() } resolveDirectLaunch() } function gameMatchesDirectLaunch(game, request) { const requestedId = String(request.appId || "") if (requestedId !== "") { const variants = game.variants || [] for (let index = 0; index < variants.length; ++index) { if (String(variants[index].id || "") === requestedId) return true } return false } return request.title !== "" && String(game.title || "").toLocaleLowerCase() === request.title.toLocaleLowerCase() } function resolveDirectLaunch() { if (!pendingDirectLaunch) return if (Object.keys(settings).length === 0 || onboardingRequired || onboardingSaving || onboardingReplaying || onboardingError !== "") return if (/^[0-9]+$/.test(pendingDirectLaunch.appId)) { if (!signedIn) { if (!authRestorePending) AppController.navigate("sign-in") return } if (ready && directLookupRequestId === "") directLookupRequestId = CoreClient.request("catalog.game.get", {variantId:pendingDirectLaunch.appId}, 30000) return } if (catalogState !== "ready") { catalogOwner.ensureCatalog(pendingDirectLaunch.title) return } let match = null for (let index = 0; index < catalogGames.length; ++index) { if (gameMatchesDirectLaunch(catalogGames[index], pendingDirectLaunch)) { if (match) { lastError = qsTr("More than one game matches this title. Choose a game and store version from your library.") pendingDirectLaunch = null AppController.navigate("library") return } match = catalogGames[index] } } if (!match) { lastError = qsTr("The requested GeForce NOW game was not found in the current catalog.") pendingDirectLaunch = null AppController.navigate("library") return } selectedGame = match if (!signedIn) { if (!authRestorePending) AppController.navigate("sign-in") return } pendingDirectLaunch = null launchSelectedGame(true) } function selectedLaunchAppId() { if (!selectedGame) return "" const variants = selectedGame.variants || [] const index = Number(selectedGame.selectedVariantIndex || 0) const variantId = index >= 0 && variants.length > index ? String(variants[index].id || "") : "" if (/^\d+$/.test(variantId) && Number(variantId) > 0 && Number(variantId) <= 2147483647) return variantId return "" } readonly property bool queueSelectorFreeTier: signedIn && queueSelector.freeTier property bool queueLaunchWaitingForSubscription: false readonly property bool queueLaunchIntentCurrent: launchIntentCurrent() onQueueLaunchIntentCurrentChanged: { if (!queueLaunchIntentCurrent) queueLaunchWaitingForSubscription = false } property QueueSelectorState queueSelector: QueueSelectorState { coreClient: CoreClient authSession: root.authSession subscription: root.subscription eligible: root.ready && root.desktopUiActive && root.queueSelectorFreeTier && root.settings.hideQueueSelector !== true && !root.activeSession launchValid: root.queueLaunchIntentCurrent onSelected: location => { if (!root.launchIntentCurrent()) return if (location) root.pendingLaunchParams = Object.assign({}, root.pendingLaunchParams, { zone: location.zoneId, streamingBaseUrl: location.streamingBaseUrl }) root.discoverPendingLaunch() } onDismissed: { root.queueLaunchWaitingForSubscription = false root.pendingLaunchParams = null root.streamState = "idle" root.streamMessage = "" } } onSubscriptionRequestIdChanged: { if (subscriptionRequestId === "" && queueLaunchWaitingForSubscription) { queueLaunchWaitingForSubscription = false Qt.callLater(root.continueInspectedLaunch) } } function continueInspectedLaunch() { if (!launchIntentCurrent()) return if (desktopUiActive && subscriptionRequestId !== "") { queueLaunchWaitingForSubscription = true return } if (pendingLaunchParams.queueSelectorHandled === true || !queueSelector.begin(pendingLaunchParams.title)) discoverPendingLaunch() } function discoverPendingLaunch() { if (!launchIntentCurrent() || remoteSessionsRequestId !== "") return pendingLaunchParams = Object.assign({}, pendingLaunchParams, {queueSelectorHandled: true}) streamState = "checking" remoteSessionsRequestId = CoreClient.request("session.remote.list", pendingLaunchParams, 30000) AppController.navigate("inserting") } function dismissStreamEndNotice() { streamEndNotice = null } function launchSelectedGame(directConsoleMode) { streamEndNotice = null if (!signedIn) { AppController.navigate("sign-in") return } const appId = selectedLaunchAppId() if (!appId) { streamState = "error" streamMessage = qsTr("This game does not expose a numeric GeForce NOW launch ID.") lastError = streamMessage return } if (!ready || streamBusy || onboardingReplaying) return streamerRestartAttempts = 0 streamerRecoveryExhausted = false sessionReconnectAttempts = 0 streamerRestartRecoveryCount = 0 sessionRecoveryCount = 0 guidePagesVisited = [] antiAfkEnabled = false const variants = selectedGame.variants || [] const selectedVariantIndex = Math.max(0, Number(selectedGame.selectedVariantIndex || 0)) const selectedVariant = variants.length > selectedVariantIndex ? variants[selectedVariantIndex] : null const params = { appId: appId, catalogAppId: String(selectedGame.id), scope: catalogOwner.authScope, variantId: appId, selectionIdentity: catalogOwner.selectedIdentity, authGeneration: authGeneration, actionGeneration: catalogOwner.actionGeneration, requestContextKey: catalogOwner.requestContextKey, title: selectedGame.title || "GeForce NOW game", store: String(selectedVariant && selectedVariant.store || ""), supportsInGameSettingsPersistence: Boolean(selectedVariant && selectedVariant.supportsInGameSettingsPersistence), accountLinked: Boolean(selectedVariant && selectedVariant.inLibrary), appLaunchMode: settings.steamBigPictureMode === true ? "gamepadFriendly" : "default" } if (storeLaunchTarget && String(storeLaunchTarget.appId) === String(selectedGame.id) && String(storeLaunchTarget.variantId) === appId) params.storeLaunch = true const configuredRegion = selectedRegion for (let index = 0; index < regions.length; ++index) { const region = regions[index] if (configuredRegion === region.name || configuredRegion === region.url) { params.zone = region.name params.streamingBaseUrl = region.url break } } pendingLaunchParams = params launchConflictDetected = false conflictSession = null conflictSessionNeedsRefresh = false streamState = "checking" streamMessage = qsTr("Looking for your game on GeForce NOW…") lastError = qsTr("") inspectLaunch("discover") } function checkLaunchSessions() { if (!ready || !pendingLaunchParams || streamBusy) return streamState = "checking" streamMessage = qsTr("Looking for your game on GeForce NOW…") lastError = qsTr("") inspectLaunch("discover") } function retrySessionLaunch() { if (streamBusy) return if (activeSession) { retryNativeStreamer() return } if (conflictSession) { resolveSessionConflict("resume") return } checkLaunchSessions() } function handleSessionCreateFailure(code, message) { streamPollTimer.stop() if (code === "session_conflict") { launchConflictDetected = true checkLaunchSessions() return } streamState = "error" streamMessage = message } function createPendingSession() { if (!pendingLaunchParams || !ready || streamCreateRequestId !== "" || onboardingReplaying) return streamState = "requesting" streamMessage = qsTr("Requesting a cloud gaming seat…") if (!nativeRuntimeReady) { ensureNativeRuntimeReady() streamState = "error" streamMessage = qsTr("The native decoder is still being detected. Please try again in a moment.") lastError = streamMessage return } inspectLaunch("create") } function resolveSessionConflict(choice) { if (streamBusy) return AppController.showOverlay("") if (choice === "cancel") { invalidateLaunchInspection() pendingLaunchParams = null conflictSession = null conflictSessionNeedsRefresh = false launchConflictDetected = false streamState = "idle" streamMessage = qsTr("") AppController.navigateFromLastPrimary("game-detail") return } if (choice === "resume") { if (!conflictSession) return if (conflictSessionNeedsRefresh) { streamState = "checking" streamMessage = qsTr("Looking for your game on GeForce NOW…") remoteSessionsRequestId = CoreClient.request("session.remote.list", { sessionId: conflictSession.sessionId, streamingBaseUrl: conflictSession.streamingBaseUrl }, 30000) return } streamState = "resuming" streamMessage = qsTr("Reconnecting to your running game. You don't need to start again.") sessionClaimIsRecovery = false sessionClaimRequestId = CoreClient.request("session.claim", { sessionId: conflictSession.sessionId, streamingBaseUrl: conflictSession.streamingBaseUrl, appId: String(conflictSession.appId || "0"), recoveryMode: true }, 35000) return } if (choice === "new") { if (!conflictSession) { createPendingSession() return } inspectLaunch("stop") } } function inspectRemoteSessions(result) { remoteSessions = result.sessions || [] if (conflictSessionNeedsRefresh && conflictSession) { const refreshed = remoteSessions.find(session => String(session.sessionId) === String(conflictSession.sessionId)) if (!refreshed) { streamState = "error" streamMessage = qsTr("Your previous game isn't available to reconnect yet. Wait a moment, then try again.") return } conflictSession = refreshed conflictSessionNeedsRefresh = false resolveSessionConflict("resume") return } if (!pendingLaunchParams) return if (remoteSessions.length === 0) { if (launchConflictDetected) { streamState = "error" streamMessage = qsTr("GeForce NOW says a game is still running, but it isn't available to reconnect yet. Wait a moment, then try again. If you were playing on another device, disconnect there first.") return } createPendingSession() return } const wantedAppId = pendingLaunchParams ? Number(pendingLaunchParams.appId || 0) : 0 conflictSession = remoteSessions[0] for (let index = 0; index < remoteSessions.length; ++index) { if (wantedAppId > 0 && Number(remoteSessions[index].appId || 0) === wantedAppId) { conflictSession = remoteSessions[index] resolveSessionConflict("resume") return } } streamState = "conflict" streamMessage = qsTr("Another game is still running on GeForce NOW. You can return to it, or end it to play this game.") AppController.showOverlay("session-conflict") } function normalizedStreamingSession(session) { if (!session) return null const normalized = Object.assign({}, session) if (session.negotiatedStreamProfile) { const profile = Object.assign({}, session.negotiatedStreamProfile) const resolution = String(profile.resolution || "").split("x") if (resolution.length === 2) { const width = Number(resolution[0]) const height = Number(resolution[1]) if (Number.isFinite(width) && width > 0) profile.width = width if (Number.isFinite(height) && height > 0) profile.height = height } normalized.negotiatedStreamProfile = profile } return normalized } function acceptStreamingSession(session) { if (session && String(session.sessionId) === nativeEndedSessionId) return if (session && Number(session.status) === 7) { finishRemoteSession(session.termination || {source: "cloudmatch-session-status", status: 7, sessionId: session.sessionId, resumable: false}) return } const previousSession = activeSession const nextSession = normalizedStreamingSession(session) if (nextSession && previousSession && nextSession.sessionId === previousSession.sessionId && (nextSession.keyboardLayout === undefined || nextSession.keyboardLayout === null) && previousSession.keyboardLayout !== undefined && previousSession.keyboardLayout !== null) nextSession.keyboardLayout = previousSession.keyboardLayout activeSession = nextSession if (!activeSession || !previousSession || previousSession.sessionId !== activeSession.sessionId) { if (activeSession) streamStartedAtMs = 0 const pollId = streamPollRequestId streamPollRequestId = "" coreSessionRestoreId = "" sessionStopIntentId = "" if (pollId !== "") CoreClient.cancel(pollId) streamerRestartTimer.stop() streamerRestartAttempts = 0 sessionReconnectAttempts = 0 sessionRecoveryAwaitingAuth = false streamPollFailureAttempts = 0 streamerRecoveryExhausted = false } if (!activeSession) { reportSessionEnd(previousSession, "remote_ended") launchRequestedAtMs = 0 cancelSessionRecovery() runtimeStreamProfile = ({}) if (previousSession && streamer && streamer.status !== "stopped") stopNativeStreamer("The remote session ended") streamRecordingActive = false streamRecordingElapsedMs = 0 pendingRecordingPath = "" pendingRecordingThumbnailPath = "" resetStreamReplay() streamState = "idle" streamMessage = qsTr("") streamPollTimer.stop() streamStartedAtMs = 0 syncDiscordPresence() return } // A seat still being ready does not mean its media path recovered. // Polls and claim replies must not restart an exhausted media episode. if (streamerRecoveryExhausted) return streamState = activeSession.phase || (Number(activeSession.status) >= 2 ? "ready" : "preparing") const adState = activeSession.adState || ({}) const ads = adState.sessionAds || adState.ads || [] if ((adState.sessionAdsRequired || adState.isAdsRequired) && ads.length > 0 && ["queue-ad", "desktop-stream-exit-confirm", "application-quit-confirm", "account-switch-confirm"] .indexOf(AppController.overlay) < 0) AppController.showOverlay("queue-ad") if (streamState === "ready" || streamState === "streaming") { if (streamStartedAtMs === 0) streamStartedAtMs = Date.now() streamMessage = qsTr("Your GeForce NOW seat is ready.") streamPollTimer.stop() if (AppController.route !== "stream") AppController.navigate("stream") startNativeStreamer() } else if (streamState === "failed") { streamMessage = qsTr("GeForce NOW could not prepare this session.") streamPollTimer.stop() } else { streamMessage = activeSession.resumePending ? qsTr("Reconnecting to your running game. You don't need to start again.") : sessionSetupProgress.title + "\n" + sessionSetupProgress.detail streamPollTimer.restart() } syncDiscordPresence() } function syncDiscordPresence() { if (!ready || discordRequestId !== "") return if (!Boolean(settings.discordRichPresence) || !activeSession) { discordRequestId = CoreClient.request("discord.activity.clear", {}, 5000) return } const status = Number(activeSession.status || 0) const kind = status >= 3 ? "streaming" : Number(activeSession.queuePosition || 0) > 0 ? "queued" : "starting" discordRequestId = CoreClient.request("discord.activity.sync", { enabled: true, gameName: selectedGame ? selectedGame.title : String(activeSession.appId || "GeForce NOW"), gameImageUrl: selectedGame ? (selectedGame.boxArtUrl || selectedGame.imageUrl || "") : "", kind: kind, queuePosition: Number(activeSession.queuePosition || 0), startTimestampMs: streamStartedAtMs }, 5000) } function abandonSessionAdReports(sessionId) { const requestId = sessionAdRequestId sessionAdRequestId = "" sessionAdInFlight = null sessionAdReports = [] sessionAdSessionId = sessionId sessionAdRetryAttempts = 0 sessionAdRetryTimer.stop() if (requestId !== "") CoreClient.cancel(requestId) } function prepareSessionAd(ad, sessionId) { const owner = String(activeSession && activeSession.sessionId || "") if (!owner || !ad || !ad.adId || (sessionId !== undefined && String(sessionId) !== owner)) return false if (sessionAdSessionId !== owner) abandonSessionAdReports(owner) const reports = sessionAdReports.filter(value => value.adId === ad.adId || value.events.length > 0) if (reports.some(value => value.adId === ad.adId)) return true if (reports.length >= 8) return false reports.push({adId: ad.adId, events: [], lastAction: "", terminal: false}) sessionAdReports = reports return true } function reportSessionAd(action, ad, watchedTimeMs, cancelReason, sessionId) { if (["start", "pause", "resume", "finish", "cancel"].indexOf(action) < 0 || !prepareSessionAd(ad, sessionId)) return false const report = sessionAdReports.find(value => value.adId === ad.adId) if (report.terminal || report.lastAction === action || (action === "start" && report.lastAction !== "")) return true const event = { sessionId: sessionAdSessionId, adId: ad.adId, action: action, watchedTimeInMs: Math.max(0, Math.round(watchedTimeMs || 0)), pausedTimeInMs: 0, clientTimestamp: Math.floor(Date.now() / 1000), cancelReason: cancelReason || undefined } const tail = report.events[report.events.length - 1] if ((action === "pause" || action === "resume") && tail && (tail.action === "pause" || tail.action === "resume") && (!sessionAdInFlight || sessionAdInFlight.event !== tail)) report.events[report.events.length - 1] = event else report.events.push(event) report.lastAction = action report.terminal = action === "finish" || action === "cancel" sessionAdReports = sessionAdReports.slice() if (!sessionAdRetryTimer.running) flushSessionAdReports() return true } function flushSessionAdReports() { if (!ready || sessionAdRequestId !== "" || !activeSession || String(activeSession.sessionId) !== sessionAdSessionId) return const report = sessionAdReports.find(value => value.events.length > 0) if (!report) return sessionAdInFlight = {report: report, event: report.events[0]} sessionAdRequestId = CoreClient.request("session.ad.report", sessionAdInFlight.event, 30000) if (sessionAdRequestId === "") { sessionAdInFlight = null sessionAdRetryAttempts = Math.min(5, sessionAdRetryAttempts + 1) sessionAdRetryTimer.restart() } } function finishSessionAdReport(requestId, result, message) { if (requestId === "" || requestId !== sessionAdRequestId || !sessionAdInFlight) return false const pending = sessionAdInFlight sessionAdRequestId = "" sessionAdInFlight = null if (!result || (result.scope && !matchesAuthScope(result.scope) && !acceptsSessionScope(result.scope))) { if (message) streamMessage = message sessionAdRetryAttempts = Math.min(5, sessionAdRetryAttempts + 1) sessionAdRetryTimer.restart() return true } sessionAdRetryAttempts = 0 sessionAdRetryTimer.stop() pending.report.events.shift() if (pending.event.action === "finish" || pending.event.action === "cancel") sessionAdReports = sessionAdReports.filter(value => value !== pending.report) else sessionAdReports = sessionAdReports.slice() const identity = result.adReportIdentity if (identity && identity.sessionId === pending.event.sessionId && identity.adId === pending.event.adId) acceptSessionAdSnapshot(result) flushSessionAdReports() return true } function acceptSessionAdSnapshot(payload) { const identity = payload && payload.adReportIdentity if (!identity || typeof identity.sessionId !== "string" || typeof identity.adId !== "string" || identity.sessionId.length === 0 || identity.sessionId.length > 256 || identity.adId.length === 0 || identity.adId.length > 256 || /[\u0000-\u001f\u007f]/.test(identity.sessionId + identity.adId) || !activeSession || String(activeSession.sessionId) !== identity.sessionId || !acceptsSessionScope(payload.scope)) return false const state = activeSession.adState || ({}) const ads = state.sessionAds || state.ads || [] if (!ads.length || ads[0].adId !== identity.adId || !payload.session || String(payload.session.sessionId) !== identity.sessionId) return false const termination = ownedSessionTermination(payload) if (termination) finishRemoteSession(termination) else if (isRemoteSessionTermination(payload.termination)) finishRemoteSession(payload.termination) else acceptStreamingSession(payload.session) const next = activeSession ? (activeSession.adState || ({})) : ({}) if (!(next.sessionAdsRequired || next.isAdsRequired) || !(next.sessionAds || next.ads || []).length) { if (AppController.overlay === "queue-ad") AppController.showOverlay("") } return true } function startNativeStreamer() { if (!ready || !activeSession || sessionRecoveryPending || sessionRecoveryAwaitingAuth || activeSession.resumePending || coreSessionRestoreId !== "" || sessionStopIntentId === String(activeSession.sessionId) || streamStopRequestId !== "" || streamerStopRequestId !== "" || streamerStartRequestId !== "" || streamerPrepareRequestId !== "" || sessionClaimRequestId !== "" || streamerRestartTimer.running || streamerRecoveryExhausted) return if (streamer && streamer.sessionId === activeSession.sessionId && streamer.status !== "stopped" && streamer.status !== "error" && streamer.status !== "starting") return if (streamer && streamer.sessionId && streamer.sessionId !== activeSession.sessionId && streamer.status !== "stopped" && streamer.status !== "error") { stopNativeStreamer("Replacing the native media session") return } streamIdleWarning = null streamer = { status: "starting", message: qsTr("Preparing the embedded native media runtime…"), sessionId: activeSession.sessionId, sessionStartedAtMs: String(Date.now()), inputReady: false, inputPauseCount: 0, inputResumeCount: 0, recordingStartCount: 0, recordingStopCount: 0, queueDropCount: 0, overlayRequestGeneration: overlayRequestGeneration, screenshotRequestGeneration: screenshotRequestGeneration, recordingToggleRequestGeneration: recordingToggleRequestGeneration, shortcutActionGeneration: shortcutActionGeneration } streamColorFormat = null microphoneRequestId = "" sessionMicrophoneMode = "disabled" streamInputStateKnown = false streamerStopExpected = false if (!nativeRuntimeReady) { ensureNativeRuntimeReady() return } streamerPrepareRequestId = CoreClient.request("streamer.prepare", { session: activeSession, runtimeCapabilities: nativeRuntimeCapabilities }, 15000) if (streamerPrepareRequestId === "") acceptStreamerSnapshot(Object.assign({}, streamer, { status: "error", message: qsTr("The core could not prepare the native stream context"), errorCode: "core_not_ready" })) } function retryNativeStreamer() { streamerRestartTimer.stop() streamerRestartAttempts = 0 sessionReconnectAttempts = 0 streamPollFailureAttempts = 0 sessionStopIntentId = "" streamerRecoveryExhausted = false recoverStreamingSession(streamMessage) } function acceptStreamerSnapshot(snapshot) { if (!snapshot || snapshot.status === "error" || snapshot.status === "stopped") streamIdleWarning = null if (snapshot && isRemoteSessionTermination(snapshot.termination)) { finishRemoteSession(snapshot.termination, snapshot.message, snapshot) return } // One failure produces both error and stopped, plus late input replies. // Count it once and preserve the original, actionable error message. const wasTerminal = streamer && (streamer.status === "error" || streamer.status === "stopped") const wasStreaming = streamer && streamer.status === "streaming" const isTerminal = snapshot && (snapshot.status === "error" || snapshot.status === "stopped") if (wasTerminal && isTerminal) return streamer = snapshot ? Object.assign({}, snapshot, { codec: snapshot.codec || runtimeStreamProfile.codec || "", outputWidth: snapshot.outputWidth || runtimeStreamProfile.width || 0, outputHeight: snapshot.outputHeight || runtimeStreamProfile.height || 0, outputFps: snapshot.outputFps || runtimeStreamProfile.fps || 0 }) : null if (!streamer) { return } inspectStreamerOverlayRequest(streamer) inspectStreamerScreenshotRequest(streamer) inspectStreamerRecordingRequest(streamer) inspectStreamerShortcutAction(streamer) const status = String(streamer.status || "unknown") if (activeSession && !sessionRecoveryPending && status !== "stopped" && status !== "error") { streamState = status streamMessage = streamer.message || streamMessage setStreamInputPaused(desiredStreamInputPaused) } if (status === "streaming") { if (!wasStreaming && streamRecordingAttempt) streamRecordingAttempt = Object.assign({}, streamRecordingAttempt, {awaitingMedia: false}) resumeStreamRecording() return } if (status !== "error" && status !== "stopped") return streamInputStateKnown = false streamReplayEnabled = false mediaClipTargetRequestId = "" streamClipRequestId = "" if (streamRecordingActive) { streamRecordingActive = false streamRecordingElapsedMs = 0 pendingRecordingPath = "" pendingRecordingThumbnailPath = "" refreshMedia() } cancelRecordingTarget() suspendRecordingStart() if (status === "stopped" && (streamerStopExpected || !activeSession)) { streamInputStateKnown = false return } streamMessage = streamer.message || (status === "error" ? qsTr("Native media startup failed") : qsTr("The native media runtime stopped unexpectedly")) if (!activeSession) return if (streamer.errorCode === "missing-video-peer" || streamer.errorCode === "nvst-legacy-transport-unsupported" || streamer.errorCode === "streamer_presentation_unsupported") { cancelSessionRecovery() streamerRecoveryExhausted = true streamState = "error" lastError = streamMessage return } if (sessionRecoveryPending || streamerRestartTimer.running) return scheduleSessionRecovery(streamMessage) } function recoverStreamingSession(reason) { if (!activeSession || sessionClaimRequestId !== "" || recoveryDiscoveryRequestId !== "" || streamerStopRequestId !== "" || sessionStopIntentId === String(activeSession.sessionId)) return if (!sessionOwnerSignedIn()) { sessionRecoveryAwaitingAuth = true streamerRestartTimer.stop() return } sessionRecoveryAwaitingAuth = false if (!ready) { streamerRestartTimer.restart() return } if (coreSessionRestoreId !== "") { pollStreamingSession() return } if (sessionReconnectAttempts >= maximumSessionReconnectAttempts) { streamerRecoveryExhausted = true streamerRestartTimer.stop() streamState = "error" streamMessage = reason || qsTr("The streaming session could not be recovered") lastError = streamMessage return } sessionReconnectAttempts += 1 streamerRestartTimer.stop() sessionRecoveryPending = true recoverySessionId = String(activeSession.sessionId || "") streamState = "reconnecting" streamMessage = qsTr("Reconnecting to the GeForce NOW session…") streamPollTimer.stop() const pendingRequests = [streamerPrepareRequestId, streamPollRequestId] streamerPrepareRequestId = "" streamPollRequestId = "" for (const id of pendingRequests) if (id !== "") CoreClient.cancel(id) // Stop/reap the previous native connection before claiming fresh keys. // This is NOT session.stop: the cloud game must remain alive. if (NativeStreamRuntime.running) { stopNativeStreamer("Reconnecting the native media transport", true) if (streamerStopRequestId === "") scheduleSessionRecovery(lastError || qsTr("Could not stop the previous native connection")) return } discoverRecoverySession() } function scheduleSessionRecovery(reason) { sessionRecoveryPending = false streamMessage = reason || qsTr("Connection lost. Waiting to reconnect…") if (!activeSession || streamStopRequestId !== "" || sessionStopIntentId === String(activeSession.sessionId)) return if (sessionReconnectAttempts >= maximumSessionReconnectAttempts) { streamerRecoveryExhausted = true streamerRestartTimer.stop() streamState = "error" lastError = streamMessage return } streamState = "reconnecting" streamerRestartTimer.restart() } function discoverRecoverySession() { if (!sessionRecoveryPending || !activeSession || String(activeSession.sessionId) !== recoverySessionId) return if (!sessionOwnerSignedIn()) { sessionRecoveryPending = false sessionRecoveryAwaitingAuth = true return } recoveryDiscoveryRequestId = CoreClient.request("session.poll", { sessionId: recoverySessionId, streamingBaseUrl: activeSession.streamingBaseUrl, recoveryMode: true }, 30000) if (recoveryDiscoveryRequestId === "") scheduleSessionRecovery(qsTr("Waiting for the connection…")) } function acceptRecoverySessions(result) { if (!sessionRecoveryPending || !activeSession || String(activeSession.sessionId) !== recoverySessionId) return if (isRemoteSessionTermination(result.termination)) { finishRemoteSession(result.termination) return } const existing = result.session if (existing && String(existing.sessionId) === recoverySessionId && Number(existing.status) === 7) { acceptStreamingSession(existing) return } if (!existing || String(existing.sessionId) !== recoverySessionId) { scheduleSessionRecovery(qsTr("The previous session is not available yet. Retrying…")) return } sessionClaimIsRecovery = true sessionClaimRequestId = CoreClient.request("session.claim", { sessionId: recoverySessionId, streamingBaseUrl: existing.streamingBaseUrl || activeSession.streamingBaseUrl, appId: String(activeSession.appId || "0"), recoveryMode: true }, 35000) if (sessionClaimRequestId === "") scheduleSessionRecovery(qsTr("Waiting to resume the session…")) } function cancelSessionRecovery() { streamerRestartTimer.stop() const requestIds = [recoveryDiscoveryRequestId, sessionClaimRequestId] recoveryDiscoveryRequestId = "" sessionClaimRequestId = "" sessionRecoveryPending = false sessionRecoveryAwaitingAuth = false sessionClaimIsRecovery = false recoverySessionId = "" resumePollAttempts = 0 resumePollDeadlineMs = 0 for (const id of requestIds) if (id !== "") CoreClient.cancel(id) } function isRemoteSessionTermination(termination) { return termination && termination.resumable === false && ((termination.source === "cloudmatch-session-status" && Number(termination.status) === 7) || (termination.source === "cloudmatch-http" && Number(termination.httpStatus) === 404) || (termination.source === "nvst-server" && termination.code === "server-terminated")) } function flushPendingSessionEnd() { if (!ready || !pendingSessionEnd || sessionEndRequestId !== "") return sessionEndRequestId = CoreClient.request("session.ended", pendingSessionEnd, 5000) } function finishRemoteSession(termination, message, snapshot) { if (!activeSession || !isRemoteSessionTermination(termination)) return if (termination.sessionId && String(termination.sessionId) !== String(activeSession.sessionId)) return if (snapshot) streamer = snapshot reportSessionEnd(activeSession, "remote_ended", true) const pendingRequests = [streamerPrepareRequestId, streamPollRequestId] streamerPrepareRequestId = "" streamPollRequestId = "" for (const id of pendingRequests) if (id !== "") CoreClient.cancel(id) if (termination.source === "nvst-server") { nativeEndedSessionId = String(activeSession.sessionId) if (activeSession.ownerScope) { pendingSessionEnd = {sessionId: nativeEndedSessionId, ownerScope: activeSession.ownerScope} flushPendingSessionEnd() } } acceptStreamingSession(null) streamIdleWarning = null if (termination.source === "nvst-server") { lastError = message || qsTr("The server ended the session.") accessibilityMessage = lastError const disposition = termination.disposition || "error" if (disposition !== "normal") { const code = typeof termination.extendedCode === "number" ? termination.extendedCode >>> 0 : null streamEndNotice = {kind: disposition, code: code, codeText: code === null ? "" : "0x" + code.toString(16).toUpperCase().padStart(8, "0")} } } if (AppController.route === "stream" || AppController.route === "inserting") { AppController.showOverlay("") AppController.navigateFromLastPrimary("game-detail") } } function artworkUrl(sourceUrl) { return artworkOwner.artworkUrl(sourceUrl) } function reportArtworkLoad(sourceUrl, resolvedUrl, failed) { return artworkOwner.reportArtworkLoad(sourceUrl, resolvedUrl, failed) } function retainArtwork(source) { return artworkOwner.retainArtwork(source) } function releaseArtwork(source) { return artworkOwner.releaseArtwork(source) } function scheduleArtworkRetry(source) { return artworkOwner.scheduleArtworkRetry(source) } function retryVisibleArtwork(now) { return artworkOwner.retryVisibleArtwork(now) } function requestArtwork(sourceUrl, retryDue) { return artworkOwner.requestArtwork(sourceUrl, retryDue) } function finishArtworkRequest(requestId, result, failed) { return artworkOwner.finishArtworkRequest(requestId, result, failed) } function acceptArtworkResult(payload) { return artworkOwner.acceptArtworkResult(payload) } function stopNativeStreamer(reason, recovery) { streamIdleWarning = null if (recovery !== true) streamRecordingIntentSessionId = "" cancelRecordingTarget() suspendRecordingStart() streamerRestartTimer.stop() const prepareId = streamerPrepareRequestId streamerPrepareRequestId = "" if (prepareId !== "") CoreClient.cancel(prepareId) if (streamerStartRequestId !== "") takeNativeRequest(streamerStartRequestId) streamerStartRequestId = "" if (streamerStopRequestId !== "") return const status = streamer ? String(streamer.status || "") : "" if ((status === "" || status === "stopped") && !(recovery === true && NativeStreamRuntime.running)) return streamerStopExpected = true streamerStopRequestId = sendNativeCommand("stop", { reason: reason || "User stopped the session", recovery: recovery === true }, "stop") if (streamerStopRequestId === "") streamerStopExpected = false } function setStreamInputPaused(paused) { desiredStreamInputPaused = Boolean(paused) if (streamInputPauseRequestId !== "" || !streamer || streamer.status === "stopped" || streamer.status === "error") return if (streamInputStateKnown && currentStreamInputPaused === desiredStreamInputPaused) return streamInputPauseRequestId = sendNativeCommand("input-paused", { paused: desiredStreamInputPaused }, "input") } function controlStream(action) { if (streamControlRequestId !== "") return if (!activeSession || !streamer || streamer.status !== "streaming") { streamControlMessage = qsTr("Stream controls are available once the session is live.") return } streamControlMessage = qsTr("") streamControlAction = action const commandTypes = { "toggle-fullscreen": "fullscreen-toggle", "anti-afk-pulse": "anti-afk-pulse" } const commandType = commandTypes[action] if (!commandType) { streamControlAction = "" streamControlMessage = qsTr("This stream control is unavailable") return } streamControlRequestId = sendNativeCommand(commandType, {}, "control") if (streamControlRequestId === "") { streamControlAction = "" streamControlMessage = lastError } } function setMicrophoneEnabled(enabled) { if (!microphoneCanToggle) return if (!enabled) microphoneRecoveryEnabled = false microphoneRequestId = sendNativeCommand("microphone-set", { enabled: Boolean(enabled) }, "microphone") if (microphoneRequestId === "") { streamControlMessage = lastError accessibilityMessage = lastError } } function toggleMicrophone() { setMicrophoneEnabled(!microphoneEnabled) } function prepareMicrophoneStart(sessionId, mode) { sessionMicrophoneMode = String(mode || "disabled") if (microphoneRecoverySessionId !== String(sessionId)) { microphoneRecoverySessionId = String(sessionId) microphoneRecoveryEnabled = sessionMicrophoneMode === "voice-activity" } return microphoneRecoveryEnabled } function canOpenSessionGuide() { return Boolean(activeSession) && String(activeSession.sessionId || "") !== "" && AppController.route === "stream" && streamState !== "idle" && streamState !== "stopping" } function openSessionGuide() { if (!canOpenSessionGuide()) return false return AppController.showOverlay(desktopUiActive ? "desktop-stream-menu" : "guide-session") } function inspectStreamerOverlayRequest(value) { const generation = Number(value && value.overlayRequestGeneration || 0) if (generation <= overlayRequestGeneration) return overlayRequestGeneration = generation openSessionGuide() } function inspectStreamerScreenshotRequest(value) { const generation = Number(value && value.screenshotRequestGeneration || 0) if (generation <= screenshotRequestGeneration) return screenshotRequestGeneration = generation captureStreamScreenshot() } function captureStreamScreenshot() { if (!desktopUiActive && AppController.route === "stream" && AppController.overlay.startsWith("guide-")) { consoleScreenshotRequested() return } const title = selectedGame && selectedGame.title ? selectedGame.title : "OpenNOW" if (!AppController.captureStreamScreenshot(title)) acceptStreamScreenshot("") } function acceptStreamScreenshot(path) { if (path) { mediaMessage = qsTr("Screenshot saved") accessibilityMessage = qsTr("Screenshot saved to %1").arg(path) if (!desktopUiActive) streamCaptureAnnounced(mediaMessage) refreshMedia() } else { mediaMessage = qsTr("Screenshot capture failed") lastError = qsTr("No video frame is available, or the screenshot could not be saved.") accessibilityMessage = lastError if (!desktopUiActive) streamCaptureAnnounced(mediaMessage) } } function inspectStreamerRecordingRequest(value) { const generation = Number(value && value.recordingToggleRequestGeneration || 0) if (generation <= recordingToggleRequestGeneration) return recordingToggleRequestGeneration = generation toggleStreamRecording() } function streamShortcutBindings() { return { "guide": ["Ctrl+G"], "toggle-pointer-lock": [String(settings.shortcutTogglePointerLock ?? "F8")], "toggle-fullscreen": [String(settings.shortcutToggleFullscreen ?? "F11")], "stop-stream": [String(settings.shortcutStopStream ?? "Ctrl+Shift+Q")], "toggle-anti-afk": [String(settings.shortcutToggleAntiAfk ?? "Ctrl+Shift+K")], "toggle-frame-generation": [String(settings.shortcutToggleFrameGeneration ?? "Ctrl+Shift+G")], "toggle-generated-only": ["Ctrl+Shift+F12"], "toggle-microphone": microphoneToggleAvailable ? [String(settings.shortcutToggleMicrophone ?? "Ctrl+Shift+M")] : [], "screenshot": [String(settings.shortcutScreenshot ?? "Ctrl+F11")], "toggle-recording": [String(settings.shortcutToggleRecording ?? "F12")], "save-clip": [String(settings.shortcutSaveClip ?? "Ctrl+F12")] } } function isStreamStatsOverlay(overlay) { return ["desktop-stream-stats", "desktop-stream-stats-expanded", "stream-stats", "stream-stats-expanded"] .indexOf(String(overlay || "")) >= 0 } // Statistics are a heads-up display, not a shell modal. Gameplay input must // stay owned by StreamVideoItem while the panel is visible. function streamOverlayBlocksGameplayInput(overlay) { const name = String(overlay || "") return name !== "" && !isStreamStatsOverlay(name) } function requestStreamExitConfirmation() { if (AppController.route !== "stream" && AppController.route !== "inserting") return if (AppController.route === "inserting" && (streamState === "error" || streamState === "checking") && !activeSession && streamCreateRequestId === "" && sessionClaimRequestId === "" && streamStopRequestId === "") { stopStreamingSession() return } AppController.showOverlay("desktop-stream-exit-confirm") accessibilityMessage = qsTr("Confirm ending the cloud session") } function confirmStreamExit() { stopStreamingSession() AppController.showOverlay("") } function antiAfkIndicatorShown(elapsedSeconds) { if (!antiAfkEnabled) return false if (Boolean(settings.showAntiAfkIndicator)) return true const interval = Math.max(0, Number(settings.antiAfkReminderEveryMinutes || 0) * 60) const duration = Math.max(1, Number(settings.antiAfkReminderDurationSeconds || 5)) return interval > 0 && elapsedSeconds % interval < duration } function applyStreamShortcutAction(action) { action = String(action || "") if (action === "guide") { openSessionGuide() } else if (action === "request-exit" || action === "stop-stream") { requestStreamExitConfirmation() } else if (action === "toggle-anti-afk") { antiAfkEnabled = !antiAfkEnabled streamControlMessage = antiAfkEnabled ? qsTr("Anti-AFK on") : qsTr("Anti-AFK off") accessibilityMessage = streamControlMessage } else if (action === "toggle-generated-only") { if (settingsOwner.frameGenerationFactor() < 2) { streamControlMessage = qsTr("Frame generation is off") } else { generatedFramesOnly = !generatedFramesOnly streamControlMessage = generatedFramesOnly ? qsTr("Generated frames only") : qsTr("Source frames shown") } accessibilityMessage = streamControlMessage } else if (action === "toggle-frame-generation") { if (!settingsOwner.frameGenerationUnlocked()) { streamControlMessage = qsTr("Frame generation needs the capability test in Settings first") } else { settingsOwner.toggleFrameGeneration() streamControlMessage = settingsOwner.frameGenerationMode() !== "off" ? qsTr("Frame generation %1").arg(settingsOwner.frameGenerationQuickText()) : qsTr("Frame generation off") } accessibilityMessage = streamControlMessage } else if (action === "toggle-stats") { const compact = desktopUiActive ? "desktop-stream-stats" : "stream-stats" const expanded = desktopUiActive ? "desktop-stream-stats-expanded" : "stream-stats-expanded" if (AppController.overlay === compact) AppController.showOverlay(expanded) else if (AppController.overlay === expanded) AppController.showOverlay("") else AppController.showOverlay(compact) } else if (action === "toggle-fullscreen") { fullscreenToggleRequested() } else if (action === "toggle-pointer-lock") { pointerLockToggleRequested() } else if (action === "screenshot") { captureStreamScreenshot() } else if (action === "toggle-recording") { toggleStreamRecording() } else if (action === "save-clip") { saveStreamClip() } else if (action === "toggle-microphone") { toggleMicrophone() } } function inspectStreamerShortcutAction(value) { const generation = Number(value && value.shortcutActionGeneration || 0) if (generation <= shortcutActionGeneration) return shortcutActionGeneration = generation applyStreamShortcutAction(value.shortcutAction) } function resetStreamReplay() { streamReplayEnabled = false mediaClipTargetRequestId = "" streamClipRequestId = "" } function disableStreamReplay() { if (!streamReplayEnabled) return if (NativeStreamRuntime.running) { const requestId = sendNativeCommand("replay-stop", {}, "replay-stop") if (requestId === "") { mediaMessage = lastError accessibilityMessage = mediaMessage streamCaptureAnnounced(mediaMessage) return } } streamReplayEnabled = false mediaClipTargetRequestId = "" streamClipRequestId = "" } function saveStreamClip() { if (streamClipBusy) return if (!activeSession || !streamer || streamer.status !== "streaming") { mediaMessage = qsTr("Start a native stream before saving a clip") } else if (!streamReplayEnabled || !replayBufferRequested) { mediaMessage = qsTr("Enable replay buffering in Recording settings before starting a session") } else { const title = selectedGame && selectedGame.title ? selectedGame.title : "OpenNOW" mediaClipTargetRequestId = CoreClient.request("media.recording.target", { gameTitle: title + "-clip" }, 5000) mediaMessage = qsTr("Preparing clip…") } accessibilityMessage = mediaMessage streamCaptureAnnounced(mediaMessage) } function cancelRecordingTarget() { const requestId = mediaRecordingTargetRequestId mediaRecordingTargetRequestId = "" mediaRecordingTargetSessionId = "" if (requestId !== "") CoreClient.cancel(requestId) } function suspendRecordingStart() { if (streamRecordingAttempt) streamRecordingAttempt = Object.assign({}, streamRecordingAttempt, {acceptStart: false, awaitingMedia: false}) streamRecordingStartRequestId = "" streamRecordingStopRequestId = "" streamRecordingActive = false streamRecordingElapsedMs = 0 } function resumeStreamRecording() { if (streamRecordingIntentSessionId === "" || !activeSession || String(activeSession.sessionId) !== streamRecordingIntentSessionId || !streamer || streamer.status !== "streaming" || streamerStopExpected || sessionRecoveryPending || sessionRecoveryAwaitingAuth || sessionStopIntentId === streamRecordingIntentSessionId || streamStopRequestId !== "" || !NativeStreamRuntime.running || streamRecordingActive || mediaRecordingTargetRequestId !== "" || streamRecordingStartRequestId !== "" || streamRecordingStopRequestId !== "" || (streamRecordingAttempt && (!streamRecordingAttempt.completed || streamRecordingAttempt.awaitingMedia))) return const title = selectedGame && selectedGame.title ? selectedGame.title : "OpenNOW" mediaRecordingTargetSessionId = streamRecordingIntentSessionId mediaRecordingTargetRequestId = CoreClient.request("media.recording.target", { gameTitle: title }, 5000) if (mediaRecordingTargetRequestId === "") streamRecordingIntentSessionId = "" } function acceptRecordingTarget(requestId, result) { if (requestId === "" || requestId !== mediaRecordingTargetRequestId) return const sessionId = mediaRecordingTargetSessionId mediaRecordingTargetRequestId = "" mediaRecordingTargetSessionId = "" if (!activeSession || String(activeSession.sessionId) !== sessionId || sessionId !== streamRecordingIntentSessionId || !streamer || streamer.status !== "streaming" || streamerStopExpected || sessionRecoveryPending || sessionRecoveryAwaitingAuth || sessionStopIntentId === sessionId || streamStopRequestId !== "") return pendingRecordingPath = String(result.path || "") pendingRecordingThumbnailPath = String(result.thumbnailPath || "") streamRecordingStartRequestId = sendNativeCommand("recording-start", { outputPath: pendingRecordingPath }, "recording-start") streamRecordingAttempt = streamRecordingStartRequestId === "" ? null : { requestId: streamRecordingStartRequestId, sessionId: sessionId, completed: false, acceptStart: true } if (streamRecordingStartRequestId === "") { streamRecordingIntentSessionId = "" pendingRecordingPath = "" pendingRecordingThumbnailPath = "" mediaMessage = lastError } } function acceptRecordingCompletion(result, authoritativeRequestId) { const requestId = String(result.requestId || authoritativeRequestId || "") if (!streamRecordingAttempt || streamRecordingAttempt.completed || requestId === "" || requestId !== streamRecordingAttempt.requestId || (authoritativeRequestId && requestId !== authoritativeRequestId)) return let message = "" if (result.state === "saved") { if (!result.path) return const completion = result.completion if (!completion && authoritativeRequestId) { message = qsTr("Recording saved") } else if (completion && completion.kind === "complete") { message = qsTr("Recording saved") } else if (completion && completion.kind === "cut") { if (completion.reason === "discontinuity") message = qsTr("Recording saved early because the stream was interrupted") else if (completion.reason === "queue-overflow") message = qsTr("Recording saved early because the recording buffer filled") else if (completion.reason === "interrupted") message = qsTr("Recording saved early because the stream stopped") else return } else { return } } else if (result.state === "failed") { message = String(result.message || qsTr("Recording failed")) lastError = message } else { return } const continuation = result.completion && result.completion.kind === "cut" && ["discontinuity", "interrupted"].indexOf(result.completion.reason) >= 0 const awaitingMedia = continuation && result.completion.reason === "interrupted" && streamRecordingAttempt.acceptStart if (!continuation) streamRecordingIntentSessionId = "" streamRecordingAttempt = Object.assign({}, streamRecordingAttempt, {completed: true, acceptStart: false, awaitingMedia: awaitingMedia}) streamRecordingStartRequestId = "" streamRecordingStopRequestId = "" streamRecordingActive = false streamRecordingElapsedMs = 0 pendingRecordingPath = "" pendingRecordingThumbnailPath = "" mediaMessage = message accessibilityMessage = message streamCaptureAnnounced(message) if (result.state === "saved") updateStreamerFields({recordingStopCount: Number(streamer && streamer.recordingStopCount || 0) + 1}) refreshMedia() resumeStreamRecording() } function acceptRecordingResponse(response, pending) { const requestId = String(response.id || "") if (pending.operation === "recording-stop") { if (requestId === streamRecordingStopRequestId) streamRecordingStopRequestId = "" if (!pending.recordingRequestId || response.type === "recording-not-active") return if (response.type === "recording-stopped" || response.type === "error") acceptRecordingCompletion(Object.assign({}, response, { state: response.type === "error" ? "failed" : "saved" }), pending.recordingRequestId) return } if (requestId === streamRecordingStartRequestId) streamRecordingStartRequestId = "" if (!streamRecordingAttempt || requestId !== streamRecordingAttempt.requestId || streamRecordingAttempt.completed) return if (response.type === "error") { acceptRecordingCompletion(Object.assign({}, response, {state: "failed"}), requestId) return } if (response.type !== "recording-started" || !streamRecordingAttempt.acceptStart || streamRecordingActive || streamRecordingIntentSessionId !== streamRecordingAttempt.sessionId || !activeSession || String(activeSession.sessionId) !== streamRecordingAttempt.sessionId || !streamer || streamer.status !== "streaming" || streamerStopExpected) return streamRecordingActive = true streamRecordingStartedAtMs = Date.now() streamRecordingElapsedMs = 0 updateStreamerFields({recordingStartCount: Number(streamer && streamer.recordingStartCount || 0) + 1}) const rect = streamCaptureRect if (pendingRecordingThumbnailPath) { AppController.captureScreenRegionTo( Number(rect.x || 0), Number(rect.y || 0), Number(rect.width || 0), Number(rect.height || 0), pendingRecordingThumbnailPath) } mediaMessage = qsTr("Recording source video + stream audio") accessibilityMessage = qsTr("Recording started") } function toggleStreamRecording() { if (streamRecordingIntentSessionId !== "") { streamRecordingIntentSessionId = "" cancelRecordingTarget() const stop = streamRecordingAttempt && !streamRecordingAttempt.completed && streamRecordingAttempt.acceptStart && NativeStreamRuntime.running suspendRecordingStart() if (stop) { streamRecordingStopRequestId = sendNativeCommand("recording-stop", {}, "recording-stop") mediaMessage = streamRecordingStopRequestId === "" ? lastError : qsTr("Finalizing recording…") accessibilityMessage = mediaMessage } return } if (streamRecordingStartRequestId !== "" || streamRecordingStopRequestId !== "" || mediaRecordingTargetRequestId !== "") return if (streamRecordingActive) { streamRecordingStopRequestId = sendNativeCommand("recording-stop", {}, "recording-stop") mediaMessage = streamRecordingStopRequestId === "" ? lastError : qsTr("Finalizing recording…") accessibilityMessage = mediaMessage return } if (!activeSession || !streamer || streamer.status !== "streaming" || streamerStopExpected || sessionRecoveryPending || sessionRecoveryAwaitingAuth || streamStopRequestId !== "" || sessionStopIntentId === String(activeSession.sessionId)) { mediaMessage = qsTr("Start a native stream before recording") accessibilityMessage = mediaMessage return } AppController.showOverlay("") if (streamRecordingAttempt && streamRecordingAttempt.completed) streamRecordingAttempt = null streamRecordingIntentSessionId = String(activeSession.sessionId) resumeStreamRecording() mediaMessage = qsTr("Preparing source-quality recording…") accessibilityMessage = mediaMessage } function pollStreamingSession() { if (!ready || !activeSession || streamPollRequestId !== "" || streamStopRequestId !== "") return if (sessionStopIntentId === String(activeSession.sessionId) && coreSessionRestoreId === "") return if (!(activeSession.resumePending && coreSessionRestoreId === "") && streamPollFailureAttempts > maximumStreamPollFailureAttempts) { streamPollTimer.stop() return } if (coreSessionRestoreId !== "") { if (authSessionRequestId !== "") return streamPollRequestId = CoreClient.request("session.active.get", { sessionId: coreSessionRestoreId, ownerScope: activeSession.ownerScope }, 35000) return } if (activeSession.resumePending && (++resumePollAttempts > 60 || (resumePollDeadlineMs > 0 && Date.now() >= resumePollDeadlineMs))) { streamPollTimer.stop() scheduleSessionRecovery(qsTr("The resumed session did not become ready. Retrying…")) return } streamPollRequestId = CoreClient.request("session.poll", { sessionId: activeSession.sessionId, streamingBaseUrl: activeSession.streamingBaseUrl }, 35000) } function handleStreamPollFailure(code, message) { if (code === "session_owner_authentication_required") { streamPollTimer.stop() streamMessage = message lastError = message return } if (activeSession && activeSession.resumePending && coreSessionRestoreId === "") { streamMessage = qsTr("Waiting for the resumed session…") streamPollTimer.restart() return } streamPollFailureAttempts += 1 const retry = activeSession && streamPollFailureAttempts <= maximumStreamPollFailureAttempts if (coreSessionRestoreId === "" || !streamer || streamer.status !== "streaming") streamState = retry ? "reconnecting" : "error" streamMessage = retry ? qsTr("Connection interrupted. Retrying…") : message if (retry) { streamPollTimer.restart() } else { streamPollTimer.stop() lastError = message } } function stopStreamingSession() { streamRecordingIntentSessionId = "" sessionStopIntentId = activeSession ? String(activeSession.sessionId) : "" if (coreSessionRestoreId !== "") streamPollFailureAttempts = 0 invalidateLaunchInspection() const discoveryRequestId = remoteSessionsRequestId const createRequestId = streamCreateRequestId const prepareRequestId = streamerPrepareRequestId remoteSessionsRequestId = "" streamCreateRequestId = "" streamerPrepareRequestId = "" pendingLaunchParams = null conflictSession = null conflictSessionNeedsRefresh = false launchConflictDetected = false forceNewAfterStop = false if (discoveryRequestId !== "") CoreClient.cancel(discoveryRequestId) if (createRequestId !== "") CoreClient.cancel(createRequestId) if (prepareRequestId !== "") CoreClient.cancel(prepareRequestId) cancelSessionRecovery() reportSessionEnd(activeSession, "") if (activeSession && streamStartedAtMs > 0) { const snapshot = streamer || ({}) sessionReportDropId = dropSessionId lastSessionReport = { gameTitle: selectedGame && selectedGame.title ? selectedGame.title : "GeForce NOW", durationMs: Math.max(0, Date.now() - streamStartedAtMs), transport: snapshot.transport ? String(snapshot.transport).toUpperCase() : "", mediaBackend: snapshot.mediaBackend ? String(snapshot.mediaBackend) : "", firstFrameLatencyMs: snapshot.firstFrameLatencyMs !== undefined && snapshot.firstFrameLatencyMs !== null ? Number(snapshot.firstFrameLatencyMs) : null, recoveries: Number(streamerRecoveryCount || 0) + Number(sessionRecoveryCount || 0), decoderErrors: snapshot.decoderErrorCount !== undefined && snapshot.decoderErrorCount !== null ? Number(snapshot.decoderErrorCount) : null, outputErrors: snapshot.outputErrorCount !== undefined && snapshot.outputErrorCount !== null ? Number(snapshot.outputErrorCount) : null, queueDrops: snapshot.queueDropCount !== undefined && snapshot.queueDropCount !== null ? Number(snapshot.queueDropCount) : null, drops: streamDropCounts, recordingCount: snapshot.recordingStopCount !== undefined && snapshot.recordingStopCount !== null ? Number(snapshot.recordingStopCount) : null } } streamPollTimer.stop() stopNativeStreamer("User stopped the session") if (streamPollRequestId !== "") { const pollId = streamPollRequestId streamPollRequestId = "" CoreClient.cancel(pollId) } if (!activeSession) { streamState = "idle" AppController.navigateFromLastPrimary("game-detail") return } if (!ready || streamStopRequestId !== "") return if (coreSessionRestoreId !== "") { pollStreamingSession() return } streamState = "stopping" streamMessage = qsTr("Closing the remote session…") streamStopRequestId = CoreClient.request("session.stop", { sessionId: activeSession.sessionId, streamingBaseUrl: activeSession.streamingBaseUrl }, 35000) } function reportSessionStart(fields) { const profile = negotiatedStreamProfile const firstFrameMs = fields.firstFrameLatencyMs !== undefined ? fields.firstFrameLatencyMs : Number(streamer.firstFrameLatencyMs) bugReports.observeFirstFrame({ game_id: String(activeSession.appId || ""), game_title: selectedGame && selectedGame.title ? String(selectedGame.title) : "", codec: String(profile.codec || streamer.codec || "").toLowerCase(), resolution: profile.width && profile.height ? profile.width + "x" + profile.height : "", fps_target: Number(profile.fps || 0) || undefined, hdr: typeof profile.enableHdr === "boolean" ? profile.enableHdr : undefined, decoder_backend: String(fields.mediaBackend || "").toLowerCase(), first_frame_ms: Number.isFinite(firstFrameMs) ? firstFrameMs : undefined, queue_wait_s: launchRequestedAtMs > 0 && streamStartedAtMs >= launchRequestedAtMs ? (streamStartedAtMs - launchRequestedAtMs) / 1000 : undefined }) } function reportSessionEnd(session, cause, confirmedTermination) { if (!session || streamStartedAtMs <= 0) return const snapshot = streamer || ({}) const sessionId = String(session.sessionId || "") const failed = snapshot.status === "error" || streamerRecoveryExhausted bugReports.observeSessionEnd(sessionId, { game_id: String(session.appId || ""), game_title: selectedGame && selectedGame.title ? String(selectedGame.title) : "", duration_s: Math.max(0, Date.now() - streamStartedAtMs) / 1000, outcome: confirmedTermination ? "remote_ended" : failed ? "error" : cause !== "" ? cause : bugReports.startedSessionId === sessionId ? "clean" : "user_stopped", error_code: failed ? bugReports.normalizedCode(snapshot.errorCode, "native_stream_error") : undefined, recoveries: Number(streamerRecoveryCount || 0) + Number(sessionRecoveryCount || 0), video_drop_count: Number(streamDropCounts.videoDropCount || 0), decoder_errors: Number(snapshot.decoderErrorCount || 0) }) } function beginAddAccount() { cancelDeviceLogin() addingAccount = true authState = "idle" authMessage = "" AppController.navigate("sign-in") } function startDeviceLogin(providerIdpId, staySignedIn) { if (!ready || deviceStartRequestId !== "") return if (!providerIdpId || !providers.some(provider => provider.idpId === providerIdpId)) { authState = "error" authMessage = qsTr("Select an available provider before signing in.") return } selectedProviderIdpId = providerIdpId pendingStaySignedIn = staySignedIn !== false cancelDeviceLogin() lastError = qsTr("") authMessage = qsTr("Contacting provider…") authState = "starting" const params = providerIdpId ? { providerIdpId: providerIdpId } : {} deviceStartRequestId = CoreClient.request("auth.device.start", params, 30000) } function pollDeviceLogin() { if (!ready || !authChallenge || devicePollRequestId !== "") return devicePollRequestId = CoreClient.request("auth.device.poll", { attemptId: authChallenge.attemptId }, 30000) } function cancelDeviceLogin() { devicePollTimer.stop() if (deviceStartRequestId !== "") { CoreClient.cancel(deviceStartRequestId) deviceStartRequestId = "" } if (deviceCompleteRequestId !== "") { CoreClient.cancel(deviceCompleteRequestId) deviceCompleteRequestId = "" if (ready) authSessionRequestId = CoreClient.request("auth.session.get", {}) } if (devicePollRequestId !== "") { CoreClient.cancel(devicePollRequestId) devicePollRequestId = "" } if (authChallenge && ready) CoreClient.request("auth.device.cancel", { attemptId: authChallenge.attemptId }) authChallenge = null if (!signedIn || addingAccount) { authState = "idle" authMessage = "" } } function logout() { cancelDeviceLogin() if (ready && logoutRequestId === "") logoutRequestId = CoreClient.request("auth.logout", {}) } function logoutAll() { cancelDeviceLogin() if (ready && logoutAllRequestId === "") { accountMessage = "" logoutAllRequestId = CoreClient.request("auth.accounts.logoutAll", {}) } } function acceptAuthEnvelope(payload) { const generation = payload.generation === undefined ? authGeneration : Number(payload.generation) if (generation < authGeneration) return false const next = payload.session || null const changed = generation !== authGeneration || String(authSession && authSession.user ? authSession.user.userId : "") !== String(next && next.user ? next.user.userId : "") || String(authSession && authSession.provider ? authSession.provider.idpId : "") !== String(next && next.provider ? next.provider.idpId : "") const keepPreparedOwner = activeSession && activeSession.ownerScope && next && Number(activeSession.ownerScope.generation) === generation && String(activeSession.ownerScope.userId) === String(next.user.userId) && String(activeSession.ownerScope.providerIdpId) === String(next.provider.idpId) const interruptedRecovery = changed && activeSession && (recoveryDiscoveryRequestId !== "" || (sessionClaimIsRecovery && sessionClaimRequestId !== "") || (streamerPrepareRequestId !== "" && !keepPreparedOwner)) if (changed) { if (interruptedRecovery) cancelSessionRecovery() accountServicesOwner.invalidateAccount() for (const key of ["remoteSessionsRequestId", "remoteSessionDiscoveryRequestId", "sessionClaimRequestId", "streamCreateRequestId", "streamerPrepareRequestId"]) { if (key === "streamerPrepareRequestId" && keepPreparedOwner) continue const requestId = root[key] root[key] = "" if (requestId !== "") CoreClient.cancel(requestId) } remoteSessions = [] pendingLaunchParams = null conflictSession = null invalidateStoreLaunch() } authGeneration = generation authSession = payload.session || null sessionPersistence = payload.persistence || "none" authWarnings = payload.warnings || [] if (interruptedRecovery) sessionRecoveryAwaitingAuth = true if (changed && coreSessionRestoreId === "" && sessionRecoveryAwaitingAuth && sessionOwnerSignedIn()) { sessionRecoveryAwaitingAuth = false scheduleSessionRecovery(streamMessage) } if (changed && coreSessionRestoreId !== "" && activeSession && activeSession.ownerScope && next && String(activeSession.ownerScope.userId) === String(next.user.userId) && String(activeSession.ownerScope.providerIdpId) === String(next.provider.idpId)) { streamPollFailureAttempts = 0 Qt.callLater(root.pollStreamingSession) } if (changed) { Qt.callLater(root.reloadCatalogForSession) if (next) Qt.callLater(root.refreshAccountServices) } return true } function matchesAuthScope(scope) { return !scope || (Number(scope.generation) === authGeneration && authSession && String(scope.userId) === String(authSession.user.userId) && String(scope.providerIdpId) === String(authSession.provider.idpId)) } function sessionOwnerSignedIn() { const owner = activeSession && activeSession.ownerScope return !owner || Boolean(authSession && String(owner.userId) === String(authSession.user.userId) && String(owner.providerIdpId) === String(authSession.provider.idpId)) } function acceptsSessionScope(scope) { if (matchesAuthScope(scope)) return true if (authSession && Number(scope.generation) < authGeneration && String(scope.userId) === String(authSession.user.userId) && String(scope.providerIdpId) === String(authSession.provider.idpId)) return false const owner = activeSession && activeSession.ownerScope return Boolean(owner && Number(owner.generation) === Number(scope.generation) && String(owner.userId) === String(scope.userId) && String(owner.providerIdpId) === String(scope.providerIdpId)) } function ownedSessionTermination(result) { const owner = activeSession && activeSession.ownerScope const scope = result && result.scope if (!owner || !scope || String(owner.userId) !== String(scope.userId) || String(owner.providerIdpId) !== String(scope.providerIdpId)) return null const session = result.session const termination = result.termination || (session && Number(session.status) === 7 ? (session.termination || {source:"cloudmatch-session-status",status:7,sessionId:session.sessionId,resumable:false}) : null) return isRemoteSessionTermination(termination) && termination.sessionId && String(termination.sessionId) === String(activeSession.sessionId) ? termination : null } function requestConsoleSurface(enabled) { return settingsOwner.requestConsoleSurface(enabled) } function beginConsoleSurfacePersistence() { return settingsOwner.beginConsoleSurfacePersistence() } function setSetting(key, value, source) { return settingsOwner.setSetting(key, value, source) } function resetSettings() { return settingsOwner.resetSettings() } function updateShortcuts(bindings) { return settingsOwner.updateShortcuts(bindings) } function applyCoupledSettings(changes) { return settingsOwner.applyCoupledSettings(changes) } function applySetting(key, value) { return settingsOwner.applySetting(key, value) } function focusIndex(route) { return focusPositions[route] === undefined ? 0 : focusPositions[route] } function rememberFocus(route, index) { const updated = Object.assign({}, focusPositions) updated[route] = index focusPositions = updated } function updateStreamerFields(fields) { acceptStreamerSnapshot(Object.assign({}, streamer || ({}), fields || ({}))) } function acceptNativeResponse(response) { const requestId = String(response && response.id || "") const pending = takeNativeRequest(requestId) if (!pending) return if (pending.operation === "start" && requestId !== streamerStartRequestId) return if (pending.operation === "recording-start" || pending.operation === "recording-stop") { acceptRecordingResponse(response, pending) return } if (pending.operation === "clip-save" && streamClipRequestId !== requestId) return const responseType = String(response.type || "") if (pending.operation === "audioDevices") { audioOutputDevicesTimeout.stop() audioOutputDevicesRequestId = "" audioOutputDevicesBusy = false if (responseType === "audioDevices" && Array.isArray(response.devices)) { audioOutputDevices = response.devices audioOutputDevicesError = "" } else { audioOutputDevices = [] audioOutputDevicesError = String(response.message || qsTr("Could not list audio output devices")) } return } if (responseType === "error") { const message = String(response.message || qsTr("The embedded media runtime rejected a command")) if (pending.operation === "hello") { nativeRuntimeReady = false streamerDetection = {available: false, availableCodecs: [], capabilities: ({})} streamerDetectionMessage = message } else if (pending.operation === "start") { streamerStartRequestId = "" updateStreamerFields({status: "error", message: message, errorCode: String(response.code || "native_stream_error")}) } else if (pending.operation === "stop") { streamerStopRequestId = "" lastError = message if (sessionRecoveryPending) scheduleSessionRecovery(message) } else if (pending.operation === "input") { streamInputPauseRequestId = "" } else if (pending.operation === "control") { streamControlRequestId = "" streamControlAction = "" streamControlMessage = message } else if (pending.operation === "microphone") { if (requestId === microphoneRequestId) { microphoneRequestId = "" microphoneRecoveryEnabled = false } streamControlMessage = message accessibilityMessage = message } else if (pending.operation === "clip-save") { streamClipRequestId = "" mediaMessage = message accessibilityMessage = message streamCaptureAnnounced(message) } else if (pending.operation === "replay-stop") { mediaMessage = message accessibilityMessage = message streamCaptureAnnounced(message) } lastError = message return } if (pending.operation === "hello") { const protocolVersion = Number(response.capabilities && response.capabilities.protocolVersion || 0) nativeRuntimeReady = responseType === "ready" && protocolVersion === nativeProtocolVersion if (!nativeRuntimeReady) { lastError = qsTr("The embedded media runtime returned an invalid handshake") streamerDetection = {available: false, availableCodecs: [], capabilities: ({})} streamerDetectionMessage = lastError bugReports.openApp({}) return } acceptNativeCapabilities(response.capabilities || ({})) bugReports.openApp(nativeRuntimeCapabilities) if (activeSession && (!streamer || streamer.status === "starting")) Qt.callLater(() => root.startNativeStreamer()) } else if (pending.operation === "start") { streamerStartRequestId = "" if (sessionRecoveryPending) return if (streamer && (streamer.status === "error" || streamer.status === "stopped")) return streamReplayEnabled = response.replayEnabled === true if (!replayBufferRequested) disableStreamReplay() const connectingWebrtc = response.transport === "webrtc" && (!streamer || streamer.status !== "streaming") updateStreamerFields({ status: connectingWebrtc ? "connecting" : "streaming", message: connectingWebrtc ? qsTr("Connecting the native WebRTC media transport…") : response.transport === "webrtc" ? streamer.message : qsTr("Native-owned NVST media transport is active"), transport: String(response.transport || "nvst"), capabilities: Object.assign({}, nativeRuntimeCapabilities, response.capabilities || ({}), {supportsMicrophone: Boolean(response.capabilities && response.capabilities.supportsMicrophone === true)}), errorCode: null }) } else if (pending.operation === "stop") { streamerStopRequestId = "" microphoneRequestId = "" sessionMicrophoneMode = "disabled" updateStreamerFields({status: "stopped", message: pending.reason || qsTr("Stream stopped"), sessionId: null, transport: null, inputReady: false, microphoneState: "disabled", microphoneEnabled: false, microphoneMessage: ""}) if (pending.recordingRequestId) { if (response.recording && response.recording.requestId === pending.recordingRequestId) { acceptRecordingCompletion(response.recording, pending.recordingRequestId) } else if (response.recording !== undefined && streamRecordingAttempt && !streamRecordingAttempt.completed && streamRecordingAttempt.requestId === pending.recordingRequestId) { streamRecordingAttempt = null pendingRecordingPath = "" pendingRecordingThumbnailPath = "" } } if (sessionRecoveryPending) { streamerStartRequestId = "" discoverRecoverySession() } else if (activeSession && ["ready", "streaming"].indexOf(activeSession.phase || (Number(activeSession.status) >= 2 ? "ready" : "preparing")) >= 0) { startNativeStreamer() } } else if (pending.operation === "input") { streamInputPauseRequestId = "" currentStreamInputPaused = Boolean(pending.paused) streamInputStateKnown = true const counter = currentStreamInputPaused ? "inputPauseCount" : "inputResumeCount" const values = {} values[counter] = Number(streamer && streamer[counter] || 0) + 1 updateStreamerFields(values) if (currentStreamInputPaused !== desiredStreamInputPaused) Qt.callLater(() => root.setStreamInputPaused(root.desiredStreamInputPaused)) } else if (pending.operation === "control") { streamControlRequestId = "" streamControlAction = "" streamControlMessage = qsTr("Stream control applied") } else if (pending.operation === "microphone") { if (requestId === microphoneRequestId) { microphoneRequestId = "" microphoneRecoveryEnabled = pending.enabled === true && pending.microphoneFailed !== true } } else if (pending.operation === "clip-save") { mediaMessage = qsTr("Saving clip…") accessibilityMessage = mediaMessage streamCaptureAnnounced(mediaMessage) } } function recordQueueDrop(event) { const count = Number(event.count) if (dropSessionId === "" || !Number.isSafeInteger(count) || count <= 0) return let field = "otherQueueDropCount" let amount = count if (event.unit === "frames") { field = "videoDropCount" } else if (event.unit === "packets") { field = "audioPacketDropCount" } else if (event.unit === "callbacks") { field = "callbackDropCount" } else if (event.unit === "samples") { const rate = Number(event.sampleRate) const channels = Number(event.channels) if (Number.isSafeInteger(rate) && rate > 0 && rate <= 384000 && Number.isSafeInteger(channels) && channels > 0 && channels <= 32) { field = "audioDiscardedMs" amount = count / rate / channels * 1000 } } const next = Object.assign({}, streamDropCounts) next[field] = Math.min(Number.MAX_SAFE_INTEGER, Number(next[field] || 0) + amount) streamDropCounts = next } function acceptStreamColorFormat(requested, actual, source, eventSessionId) { const sessionId = String(activeSession && activeSession.sessionId || "") if (!sessionId || !streamer || streamer.sessionId !== sessionId || ["starting", "streaming"].indexOf(streamer.status) < 0 || streamerStopExpected || streamStopRequestId !== "" || (eventSessionId && eventSessionId !== sessionId)) return const supported = ["8bit_420", "8bit_444", "10bit_420", "10bit_444"] if (supported.indexOf(requested) < 0 || supported.indexOf(actual) < 0 || ["decoder", "server"].indexOf(source) < 0) return const requestedColor = source === "decoder" && supported.indexOf(streamRequestedColorQuality) >= 0 ? streamRequestedColorQuality : requested streamColorFormat = {sessionId: sessionId, requestedColorQuality: requestedColor, actualColorQuality: actual, source: source} if (requestedColor !== actual && !streamColorNotice && !streamColorNoticeShown) streamColorNotice = streamColorFormat } function observeHdrDowngrade() { const gameId = String(activeSession && activeSession.catalogAppId || "") if (streamHdrNotice || streamHdrNoticeShown || !gameId || activeSession.hdrDowngrade !== "game-unsupported" || settingsOwner.hdrNoticeShown(gameId)) return streamHdrNotice = {sessionId: String(activeSession.sessionId || ""), gameId: gameId, title: selectedGame && selectedGame.title ? String(selectedGame.title) : ""} } function claimHdrNotice(notice) { if (streamHdrNoticeShown || notice !== streamHdrNotice) return false streamHdrNoticeShown = true settingsOwner.rememberHdrNotice(notice.gameId) return true } function observeNegotiatedColorFormat() { if (streamColorProfileObserved) return streamColorProfileObserved = true const profile = activeSession && activeSession.negotiatedStreamProfile if (!profile || !streamRequestedColorQuality) return const requestedDepth = streamRequestedColorQuality.startsWith("10bit_") ? 10 : 8 const requestedChroma = streamRequestedColorQuality.endsWith("_444") ? 1 : 0 const depthChanged = profile.bitDepth !== requestedDepth const chromaChanged = profile.chromaFormat !== requestedChroma if ((!depthChanged && !chromaChanged) || (depthChanged && profile.bitDepthSource !== "finalized") || (chromaChanged && profile.chromaFormatSource !== "finalized")) return acceptStreamColorFormat(streamRequestedColorQuality, profile.colorQuality, "server", "") } function acceptSessionTimer(timerType, secondsLeft, active) { if (!activeSession || !streamer || streamer.sessionId !== activeSession.sessionId || ["starting", "streaming"].indexOf(streamer.status) < 0 || streamerStopExpected || streamStopRequestId !== "") return streamIdleWarning = timerType === 4 && active ? {sessionId: String(activeSession.sessionId), secondsLeft: secondsLeft, receivedAtMs: Date.now()} : null } function acceptNativeEvent(event) { const type = String(event && event.type || "") if (type === "text-input-error") { streamControlMessage = qsTr("Text input could not be delivered. Try pasting again.") accessibilityMessage = streamControlMessage textInputErrorAnnounced(streamControlMessage) return } if (event && event.event === "color-format-changed") { if (type === "log" && event.source === "decoder" && typeof event.sessionId === "string" && event.sessionId !== "") acceptStreamColorFormat(event.requestedColorQuality, event.actualColorQuality, event.source, event.sessionId) return } const fields = {} if (event.framesPerSecond !== undefined) fields.framesPerSecond = Number(event.framesPerSecond) if (event.bitrateMbps !== undefined) fields.bitrateMbps = Number(event.bitrateMbps) if (event.peakBitrateMbps !== undefined) fields.peakBitrateMbps = Number(event.peakBitrateMbps) // Keep missing measurements unavailable instead of converting null to 0. for (const key of ["receiveBitrateMbps", "pingMs", "jitterMs", "packetLossPercent", "decodeTimeMs", "decoderResidenceMs", "latencyMs"]) { if (event[key] !== undefined) fields[key] = event[key] === null || !Number.isFinite(Number(event[key])) ? null : Number(event[key]) } if (event.event === "first-frame") { if (!activeSession || !streamer || streamer.status === "error" || streamer.status === "stopped") return // Only real video progress closes the recovery episode. A ready // seat, successful PLAY, or audio/control traffic is insufficient. streamerRestartRecoveryCount += streamerRestartAttempts if (sessionReconnectAttempts > 0) sessionRecoveryCount += 1 streamerRestartAttempts = 0 sessionReconnectAttempts = 0 streamerRecoveryExhausted = false streamerRestartTimer.stop() if (streamer && (streamer.firstFrameLatencyMs === undefined || streamer.firstFrameLatencyMs === null)) { fields.firstFrameLatencyMs = Math.max(0, Date.now() - Number(streamer.sessionStartedAtMs || Date.now())) } fields.mediaBackend = String(event.backend || "") if (!event.sessionId || event.sessionId === String(activeSession.sessionId)) { observeNegotiatedColorFormat() observeHdrDowngrade() reportSessionStart(fields) } } else if (event.event === "backend-fallback") { fields.backendFallbackCount = Number(streamer && streamer.backendFallbackCount || 0) + 1 } else if (event.event === "decoder-error") { fields.decoderErrorCount = Number(streamer && streamer.decoderErrorCount || 0) + 1 } else if (event.event === "output-error") { fields.outputErrorCount = Number(streamer && streamer.outputErrorCount || 0) + 1 } else if (event.event === "device-state") { const key = event.recovered ? "deviceRecoveryCount" : "deviceLossCount" fields[key] = Number(streamer && streamer[key] || 0) + 1 } else if (event.event === "queue-dropped") { if (!Number.isSafeInteger(Number(event.count)) || Number(event.count) <= 0) return recordQueueDrop(event) if (event.unit === "frames") bugReports.observeFrameDrops(Number(event.count), event.sessionId) if ((event.media === "d3d11-video" || event.media === "video-decode") && (!event.sessionId || String(event.sessionId) === connectionHealth.sessionId)) connectionHealth.acceptDecoderDrops(Number(event.count)) fields.queueDropCount = Number(streamer && streamer.queueDropCount || 0) + Number(event.count || 0) } if (type === "status") { fields.status = event.status === "ready" ? "streaming" : String(event.status || "streaming") fields.message = String(event.message || streamMessage) fields.termination = event.termination || null } else if (type === "error") { fields.status = "error" fields.message = String(event.message || qsTr("Native media runtime failed")) fields.errorCode = String(event.code || "native_stream_error") fields.termination = event.termination || null if (activeSession && !streamerStopExpected && !isRemoteSessionTermination(event.termination)) bugReports.reportStreamError(fields.errorCode, fields.message, "stream") } else if (type === "input-ready") { fields.inputReady = true fields.inputUnavailableReason = null } else if (type === "input-unavailable") { fields.inputReady = false fields.inputUnavailableReason = String(event.reason || "") } else if (type === "microphone-state") { fields.microphoneState = ["disabled", "muted", "ready", "unavailable", "error"] .indexOf(String(event.state)) >= 0 ? String(event.state) : "error" fields.microphoneEnabled = fields.microphoneState === "ready" && event.enabled === true fields.microphoneMessage = String(event.message || "") if (["muted", "unavailable", "error"].indexOf(fields.microphoneState) >= 0) microphoneRecoveryEnabled = false if (["unavailable", "error"].indexOf(fields.microphoneState) >= 0 && nativeRequests[microphoneRequestId]) { const requests = Object.assign({}, nativeRequests) requests[microphoneRequestId] = Object.assign({}, requests[microphoneRequestId], {microphoneFailed: true}) nativeRequests = requests } accessibilityMessage = fields.microphoneMessage || qsTr("Microphone state changed") if (fields.microphoneState === "error" || fields.microphoneState === "unavailable") streamControlMessage = fields.microphoneMessage || qsTr("Microphone error") } else if (type === "clip-state") { if (streamClipRequestId === "" || String(event.requestId || "") !== streamClipRequestId) return if (event.state === "saved" || event.state === "failed") { streamClipRequestId = "" mediaMessage = event.state === "saved" ? qsTr("Clip saved") : String(event.message || qsTr("Clip failed")) accessibilityMessage = event.state === "saved" ? qsTr("Clip saved to %1").arg(String(event.path || "")) : mediaMessage streamCaptureAnnounced(mediaMessage) if (event.state === "failed") lastError = mediaMessage refreshMedia() } } else if (type === "recording-state") { acceptRecordingCompletion(event, "") return } else if (type === "overlay-request") { fields.overlayRequestGeneration = Number(streamer && streamer.overlayRequestGeneration || 0) + 1 } else if (type === "screenshot-request") { fields.screenshotRequestGeneration = Number(streamer && streamer.screenshotRequestGeneration || 0) + 1 } else if (type === "recording-toggle-request") { fields.recordingToggleRequestGeneration = Number(streamer && streamer.recordingToggleRequestGeneration || 0) + 1 } else if (type === "shortcut-action") { fields.shortcutActionGeneration = Number(streamer && streamer.shortcutActionGeneration || 0) + 1 fields.shortcutAction = String(event.action || "") if (fields.shortcutAction === "toggle-stats") fields.statsToggleCount = Number(streamer && streamer.statsToggleCount || 0) + 1 else if (fields.shortcutAction === "toggle-fullscreen") fields.fullscreenToggleCount = Number(streamer && streamer.fullscreenToggleCount || 0) + 1 } updateStreamerFields(fields) if (type === "telemetry") bugReports.observeTelemetry(event) if (type === "telemetry" && Object.prototype.hasOwnProperty.call(event, "packetLossPercent") && (!event.sessionId || String(event.sessionId) === connectionHealth.sessionId)) connectionHealth.acceptSample(event.packetLossPercent) } property Connections nativeRuntimeConnections: Connections { target: NativeStreamRuntime function onPresentationError(message, errorCode) { const code = String(errorCode || "streamer_presentation_failed") root.lastError = message if (root.activeSession) { root.updateStreamerFields({status: "error", message: message, errorCode: code}) root.bugReports.reportStreamError(code, message, "presentation") if (code === "streamer_presentation_unsupported") root.stopNativeStreamer("Decoded video cannot be presented on this graphics device") } } function onResponseReceived(response) { root.acceptNativeResponse(response) } function onEventReceived(event) { root.acceptNativeEvent(event) } function onSessionTimerReceived(timerType, secondsLeft, active) { root.acceptSessionTimer(timerType, secondsLeft, active) } function onCallbacksDropped(count) { root.recordQueueDrop({unit: "callbacks", count: count}) root.updateStreamerFields({queueDropCount: Number(root.streamer && root.streamer.queueDropCount || 0) + Number(count || 0)}) } function onRunningChanged() { if (NativeStreamRuntime.running) return root.streamIdleWarning = null root.nativeRuntimeReady = false root.audioOutputDevices = [] root.audioOutputDevicesBusy = false root.audioOutputDevicesError = "" root.audioOutputDevicesRequestId = "" root.audioOutputDevicesTimeout.stop() root.nativeRequests = ({}) root.streamerStartRequestId = "" root.streamerStopRequestId = "" root.streamInputPauseRequestId = "" root.streamControlRequestId = "" root.microphoneRequestId = "" root.sessionMicrophoneMode = "disabled" root.streamRecordingStartRequestId = "" root.streamRecordingStopRequestId = "" root.cancelRecordingTarget() root.suspendRecordingStart() root.streamRecordingAttempt = null root.resetStreamReplay() if (root.streamer && root.streamer.status !== "stopped" && root.streamer.status !== "error") root.updateStreamerFields({status: "error", message: NativeStreamRuntime.lastError || qsTr("The embedded media runtime stopped"), errorCode: "streamer_closed"}) } } property Connections coreConnections: Connections { target: CoreClient function onStateChanged() { if (CoreClient.state === "ready") { root.authGeneration = 0 root.initializeServices() root.flushSessionAdReports() } else { root.invalidateStoreLaunch() if (CoreClient.state === "failed") { root.lastError = CoreClient.lastError root.authRestorePending = false root.resolveDirectLaunch() } } } function onResponseReceived(requestId, result) { if (requestId === root.sessionAdRequestId && root.finishSessionAdReport(requestId, result, "")) return if (result.adReportIdentity !== undefined) return if (settingsOwner.acceptResponse(requestId, result)) return const ownedTermination = root.ownedSessionTermination(result) if (ownedTermination) { root.finishRemoteSession(ownedTermination) return } const newerSameOwner = result.scope && Number(result.scope.generation) > root.authGeneration && root.authSession && String(result.scope.userId) === String(root.authSession.user.userId) && String(result.scope.providerIdpId) === String(root.authSession.provider.idpId) if (newerSameOwner && root.authSessionRequestId === "") root.authSessionRequestId = CoreClient.request("auth.session.get", {}) if (result.scope && !newerSameOwner && !root.matchesAuthScope(result.scope) && !(result.session !== undefined && root.acceptsSessionScope(result.scope))) { if (Number(result.scope.generation) > root.authGeneration && root.authSessionRequestId === "") root.authSessionRequestId = CoreClient.request("auth.session.get", {}) if (requestId === root.streamPollRequestId) root.streamPollRequestId = "" if (requestId === root.recoveryDiscoveryRequestId) { root.recoveryDiscoveryRequestId = "" root.scheduleSessionRecovery(root.streamMessage) } return } const authRequests = ["authSessionRequestId", "deviceCompleteRequestId", "logoutRequestId", "logoutAllRequestId", "accountSwitchRequestId", "accountRemoveRequestId"] for (let index = 0; index < authRequests.length; ++index) { const propertyName = authRequests[index] if (requestId === root[propertyName] && result.session !== undefined && !root.acceptAuthEnvelope(result)) { root[propertyName] = "" return } } if (onboardingOwner.acceptResponse(requestId, result)) { return } else if (root.finishArtworkRequest(requestId, result, false)) { return } else if (requestId === root.settingsRequestId && result.settings) { settingsOwner.acceptSettings(result, true) root.resolveDirectLaunch() root.showSavedAccountSelection() root.syncDiscordPresence() root.refreshStreamerDetection() } else if (requestId === root.consoleSurfaceRequestId) { settingsOwner.acceptConsoleSurface(result) } else if (requestId === root.providersRequestId) { root.providers = result.providers || [] root.providersRequestId = "" if (root.selectedProviderIdpId === "" && result.defaultProviderIdpId) root.selectedProviderIdpId = result.defaultProviderIdpId if (Number(result.generation || 0) > root.authGeneration && root.authSessionRequestId === "") root.authSessionRequestId = CoreClient.request("auth.session.get", {}) root.providerDiscoveryDegraded = Boolean(result.discovery && result.discovery.state === "degraded") const clockSkew = result.clockSkewMs ?? null if (clockSkew !== null && root.clockSkewMs === null) root.clockSkewDismissed = false root.clockSkewMs = clockSkew if (root.providerDiscoveryDegraded) root.scheduleProviderRetry(result.discovery.retryAfterMs) else if (!root.providerDiscoveryDegraded) { root.providerRetryAttempts = 0 root.providerRetryTimer.stop() } } else if (requestId === root.authSessionRequestId) { root.authSession = result.session || null root.sessionPersistence = result.persistence || "none" root.authState = root.settledAuthState(root.authSession) root.authSessionRequestId = "" root.authRestorePending = false if (root.sessionPersistenceMessage !== "") root.accessibilityMessage = root.sessionPersistenceMessage if (root.authSession && root.catalogSource !== "account-library") root.reloadCatalogForSession() if (root.authSession) root.refreshAccountServices() if (root.authSession) root.refreshRemoteSessions() else root.remoteSessions = [] if (root.coreSessionRestoreId !== "") root.pollStreamingSession() root.resolveDirectLaunch() root.showSavedAccountSelection() } else if (requestId === root.catalogRequestId) { catalogOwner.acceptCatalog(result) root.resolveDirectLaunch() } else if (requestId === root.storeRequestId) { root.acceptStorePage(result) } else if (requestId === root.storePresentationRequestId) { catalogOwner.acceptStorePresentation(result) } else if (requestId === root.deviceStartRequestId) { root.authChallenge = result root.authState = "waiting" root.authMessage = qsTr("Scan the QR code or enter %1").arg(result.userCode) root.deviceStartRequestId = "" root.devicePollTimer.interval = Math.max(1000, Number(result.intervalSeconds || 5) * 1000) root.devicePollTimer.restart() } else if (requestId === root.devicePollRequestId) { root.devicePollRequestId = "" const status = result.status || "error" if (status === "authorized") { root.devicePollTimer.stop() root.authState = "completing" root.authMessage = qsTr("Signed in. Loading your profile…") root.deviceCompleteRequestId = CoreClient.request("auth.device.complete", { attemptId: root.authChallenge.attemptId, staySignedIn: root.pendingStaySignedIn }, 30000) } else if (status === "pending") { root.authState = "waiting" root.devicePollTimer.interval = Math.max(1000, Number(result.retryAfterMs || Number(result.intervalSeconds || 5) * 1000)) root.devicePollTimer.restart() } else if (status === "slow_down") { root.devicePollTimer.interval = Math.max(1000, Number(result.retryAfterMs || Number(result.intervalSeconds || 5) * 1000)) root.devicePollTimer.restart() } else { root.cancelDeviceLogin() root.authState = "error" root.authMessage = result.error || qsTr("Device sign-in failed") } } else if (requestId === root.deviceCompleteRequestId) { root.authSession = result.session || null root.sessionPersistence = result.persistence || "memory-only" root.authChallenge = null root.authState = root.authSession ? "signed-in" : "error" root.authMessage = root.authSession ? (root.sessionPersistenceMessage !== "" ? qsTr("Welcome, %1. %2").arg(root.authSession.user.displayName).arg(root.sessionPersistenceMessage) : qsTr("Welcome, %1").arg(root.authSession.user.displayName)) : qsTr("Sign-in did not return a session") root.deviceCompleteRequestId = "" if (root.sessionPersistenceMessage !== "") root.accessibilityMessage = root.sessionPersistenceMessage if (root.authSession) root.reloadCatalogForSession() if (root.authSession) root.refreshAccountServices() if (root.authSession) { root.addingAccount = false if (AppController.route === "sign-in") AppController.navigate(root.activeSession && root.sessionOwnerSignedIn() ? "stream" : "home") } root.resolveDirectLaunch() } else if (requestId === root.logoutRequestId) { root.authSession = result.session || null if (!root.authSession) root.sessionPersistence = "none" root.authState = root.authSession ? "signed-in" : "idle" root.authMessage = qsTr("") root.logoutRequestId = "" root.subscription = null root.regions = [] root.resetRegionPing() root.reloadCatalogForSession() root.refreshSavedAccounts(true) if (root.authSession) root.refreshAccountServices() } else if (requestId === root.logoutAllRequestId) { root.logoutAllRequestId = "" root.authSession = null root.sessionPersistence = "none" root.authState = "idle" root.authMessage = qsTr("") root.savedAccounts = [] root.subscription = null root.regions = [] root.resetRegionPing() root.reloadCatalogForSession() root.refreshSavedAccounts(true) root.accessibilityMessage = qsTr("All saved accounts signed out") } else if (requestId === root.subscriptionRequestId) { accountServicesOwner.acceptSubscription(result) } else if (requestId === root.regionsRequestId) { accountServicesOwner.acceptRegions(result) } else if (requestId === root.regionPingRequestId) { accountServicesOwner.acceptRegionPing(result) } else if (requestId === root.accountsRequestId) { root.savedAccounts = result.accounts || [] root.accountsRequestId = "" root.accountsLoaded = true root.showSavedAccountSelection() } else if (requestId === root.accountSwitchRequestId) { root.resetRegionPing() root.regions = [] root.authSession = result.session || null root.sessionPersistence = result.persistence || "os-credential-store" root.authState = root.authSession ? "signed-in" : "error" root.accountSwitchRequestId = "" root.accountSwitchTargetUserId = "" if (root.sessionPersistenceMessage !== "") root.accessibilityMessage = root.sessionPersistenceMessage root.reloadCatalogForSession() root.refreshAccountServices() root.refreshSavedAccounts(true) root.pinMessage = qsTr("") root.settleRouteAfterAccountSwitch() } else if (requestId === root.accountRemoveRequestId) { root.accountRemoveRequestId = "" root.refreshSavedAccounts(true) root.authSessionRequestId = CoreClient.request("auth.session.get", {}) } else if (requestId === root.pinRequestId) { root.pinRequestId = "" if (result.ok) { root.pinMessage = qsTr("") root.refreshSavedAccounts(true) AppController.navigate("accounts") } else { root.pinMessage = result.reason === "locked_out" ? qsTr("Too many attempts. This profile is temporarily locked.") : result.reason === "invalid_pin" ? qsTr("That PIN is incorrect.") : qsTr("Enter exactly four digits.") } } else if (requestId === root.gameAccountsRequestId) { accountServicesOwner.acceptGameAccounts(result) } else if (requestId === root.gameAccountActionRequestId) { accountServicesOwner.acceptGameAccountAction(result) } else if (requestId === root.accountLinkStartRequestId) { accountServicesOwner.acceptAccountLinkStart(result) } else if (requestId === root.accountLinkPollRequestId) { accountServicesOwner.acceptAccountLinkPoll(result) } else if (requestId === root.storageLocationsRequestId) { accountServicesOwner.acceptStorageLocations(result) } else if (requestId === root.storageResetRequestId) { accountServicesOwner.acceptStorageReset(result) } else if (requestId === root.mediaRequestId) { root.mediaRequestId = "" root.mediaItems = result.items || [] root.mediaRootPath = result.rootPath || "" root.mediaState = "ready" root.mediaMessage = root.mediaItems.length ? qsTr("%1 screenshots · %2 recordings").arg(result.screenshots).arg(result.recordings) : qsTr("No captures yet") } else if (requestId === root.mediaDeleteRequestId) { root.mediaDeleteRequestId = "" root.mediaMessage = qsTr("Capture deleted") root.refreshMedia() } else if (requestId === root.mediaClipTargetRequestId && requestId !== "") { root.mediaClipTargetRequestId = "" if (!root.streamReplayEnabled || !root.replayBufferRequested || !root.activeSession || !root.streamer || root.streamer.status !== "streaming") return root.streamClipRequestId = root.sendNativeCommand("clip-save", { outputPath: String(result.path || "") }, "clip-save") if (root.streamClipRequestId === "") { root.mediaMessage = root.lastError root.accessibilityMessage = root.mediaMessage root.streamCaptureAnnounced(root.mediaMessage) } } else if (requestId === root.mediaRecordingTargetRequestId) { root.acceptRecordingTarget(requestId, result) } else if (requestId === root.diagnosticsRequestId) { root.diagnosticsRequestId = "" root.diagnostics = result root.diagnosticsMessage = result.entries && result.entries.length ? qsTr("%1 recent redacted events").arg(result.entries.length) : qsTr("No diagnostic events recorded") } else if (requestId === root.diagnosticsExportRequestId) { root.diagnosticsExportRequestId = "" root.diagnosticsMessage = qsTr("Saved redacted report to %1").arg(result.path) AppController.openLocalPath(result.path, true) } else if (requestId === root.acceptanceExportRequestId) { root.acceptanceExportRequestId = "" root.diagnosticsMessage = qsTr("Saved live acceptance evidence to %1").arg(result.path) AppController.openLocalPath(result.path, true) } else if (requestId === root.updaterStateRequestId) { root.updaterStateRequestId = "" root.acceptUpdaterState(result) } else if (requestId === root.updaterCheckRequestId) { root.updaterCheckRequestId = "" root.acceptUpdaterState(result) root.updaterHighlightsRequestId = CoreClient.request("updater.highlights.get", {}) } else if (requestId === root.updaterHighlightsRequestId) { root.updaterHighlightsRequestId = "" root.releaseHighlights = result } else if (requestId === root.updaterDownloadRequestId) { root.updaterDownloadRequestId = "" root.acceptUpdaterState(result) } else if (requestId === root.updaterInstallRequestId) { root.updaterInstallRequestId = "" root.acceptUpdaterState(result) } else if (requestId === root.socialCapabilitiesRequestId) { root.socialCapabilitiesRequestId = "" root.socialCapabilities = result } else if (requestId === root.discordRequestId) { root.discordRequestId = "" } else if (requestId === root.feedbackRequestId) { root.feedbackRequestId = "" root.reportingState = "sent" root.reportingMessage = result.message || qsTr("Thanks — your feedback was sent.") } else if (requestId === root.bugReportRequestId) { root.bugReportRequestId = "" root.reportingState = "sent" root.reportingMessage = result.queued ? qsTr("The report service is unreachable. Your report will be sent the next time OpenNOW starts.") : result.reportId ? qsTr("Thanks — this bug has been sent to the developer. Reference %1").arg(result.reportId) : qsTr("Thanks — this bug has been sent to the developer.") } else if (requestId === root.sessionEndRequestId) { root.sessionEndRequestId = "" root.pendingSessionEnd = null } else if (requestId === root.activeSessionRequestId) { root.activeSessionRequestId = "" if (!root.activeSession && !root.pendingSessionEnd) root.acceptStreamingSession(result.session || null) } else if (requestId === root.remoteSessionDiscoveryRequestId) { root.remoteSessionDiscoveryRequestId = "" root.remoteSessions = result.sessions || [] } else if (requestId === root.remoteSessionsRequestId) { root.remoteSessionsRequestId = "" root.inspectRemoteSessions(result) } else if (requestId === root.recoveryDiscoveryRequestId) { root.recoveryDiscoveryRequestId = "" root.acceptRecoverySessions(result) } else if (requestId === root.sessionClaimRequestId) { const recovering = root.sessionClaimIsRecovery root.sessionClaimRequestId = "" root.sessionClaimIsRecovery = false if (recovering && root.sessionRecoveryPending && (!root.activeSession || String(root.activeSession.sessionId) !== root.recoverySessionId)) return root.sessionRecoveryPending = false root.resumePollAttempts = 0 root.resumePollDeadlineMs = Date.now() + 90000 root.streamer = null root.selectGameForSession(result.session) root.pendingLaunchParams = null root.conflictSession = null root.conflictSessionNeedsRefresh = false root.launchConflictDetected = false root.remoteSessions = [] root.acceptStreamingSession(result.session || null) } else if (requestId === root.streamCreateRequestId) { root.streamCreateRequestId = "" root.launchConflictDetected = false root.pendingLaunchParams = null root.acceptStreamingSession(result.session || null) if (root.activeSession) root.streamRequestedColorQuality = root.pendingRequestedColorQuality root.pendingRequestedColorQuality = "" } else if (requestId === root.streamPollRequestId) { root.streamPollRequestId = "" if (!root.acceptsSessionScope(result.scope)) return const restoring = root.coreSessionRestoreId !== "" if (restoring && (!result.session || String(result.session.sessionId) !== root.coreSessionRestoreId)) { root.handleStreamPollFailure("session_restore_failed", qsTr("We couldn't check whether your game is still running. Check your connection, then try again.")) return } root.coreSessionRestoreId = "" root.sessionRecoveryAwaitingAuth = false root.streamPollFailureAttempts = 0 if (root.isRemoteSessionTermination(result.termination)) root.finishRemoteSession(result.termination) else if (restoring && root.sessionStopIntentId === String(result.session.sessionId)) { root.acceptStreamingSession(result.session) root.stopStreamingSession() } else if (restoring && root.streamer && !root.streamerStopExpected && (root.streamer.status === "error" || root.streamer.status === "stopped")) { root.sessionRecoveryPending = true root.acceptStreamingSession(result.session) root.sessionRecoveryPending = false root.scheduleSessionRecovery(root.streamer.message) } else { root.acceptStreamingSession(result.session || null) } } else if (requestId === root.streamStopRequestId) { root.streamStopRequestId = "" Qt.callLater(root.continuePendingAccountSwitch) const wasForceNewAfterStop = root.forceNewAfterStop root.remoteSessions = [] root.acceptStreamingSession(result.session || null) if (root.activeSession && String(root.activeSession.sessionId) !== String(result.sessionId)) return if (root.forceNewAfterStop) { root.forceNewAfterStop = false root.conflictSession = null root.conflictSessionNeedsRefresh = false if (root.pendingLaunchParams) root.createPendingSession() else if (AppController.route === "inserting") AppController.navigate("home") } else if (!root.pendingAccountSwitch && AppController.route !== "game-detail") AppController.navigateFromLastPrimary("game-detail") if (!wasForceNewAfterStop && !root.pendingAccountSwitch && Boolean(root.settings.showSessionReport) && root.lastSessionReport) AppController.showOverlay("session-report") } else if (requestId === root.streamerPrepareRequestId) { root.streamerPrepareRequestId = "" if (!root.ready || !root.activeSession || (result.session && String(result.session.sessionId) !== String(root.activeSession.sessionId)) || root.streamStopRequestId !== "" || root.streamerStopRequestId !== "" || root.sessionRecoveryPending) return if (!result.context || !result.session) { root.acceptStreamerSnapshot(Object.assign({}, root.streamer || ({}), { status: "error", message: qsTr("The core returned an invalid embedded stream context"), errorCode: "invalid_stream_context" })) return } root.activeSession = result.session const preparedSettings = result.context.settings || ({}) const initialMicrophoneEnabled = root.prepareMicrophoneStart( root.activeSession.sessionId, preparedSettings.microphoneMode) root.runtimeStreamProfile = { codec: String(preparedSettings.codec || "").toUpperCase(), width: Number(preparedSettings.width || root.negotiatedStreamProfile.width || 0), height: Number(preparedSettings.height || root.negotiatedStreamProfile.height || 0), maxBitrateMbps: Number(preparedSettings.maxBitrateMbps || 0), fps: Number(preparedSettings.fps || root.negotiatedStreamProfile.fps || 0) } root.acceptStreamerSnapshot(Object.assign({}, root.streamer || ({}), { codec: root.runtimeStreamProfile.codec, outputWidth: root.runtimeStreamProfile.width, outputHeight: root.runtimeStreamProfile.height, outputFps: root.runtimeStreamProfile.fps })) root.streamerStartRequestId = root.sendNativeCommand("start", { context: result.context, microphoneEnabled: initialMicrophoneEnabled }, "start") if (root.streamerStartRequestId === "") root.acceptStreamerSnapshot(Object.assign({}, root.streamer || ({}), { status: "error", message: NativeStreamRuntime.lastError || qsTr("The embedded media runtime could not start the stream"), errorCode: "streamer_start_failed" })) } } function onRequestFailed(requestId, code, message) { if (requestId === root.sessionAdRequestId && root.finishSessionAdReport(requestId, null, message)) return if (requestId === root.sessionEndRequestId && requestId !== "") { root.sessionEndRequestId = "" return } if (settingsOwner.acceptFailure(requestId, message)) return if (onboardingOwner.acceptFailure(requestId, message)) { return } else if (requestId === root.storePresentationRequestId && requestId !== "") { catalogOwner.failStorePresentation(message) return } if (root.finishArtworkRequest(requestId, null, true)) return if (requestId === root.remoteSessionDiscoveryRequestId) { root.remoteSessionDiscoveryRequestId = "" root.remoteSessions = [] return } if (code !== "cancelled") root.lastError = message if (requestId === root.consoleSurfaceRequestId) { settingsOwner.failConsoleSurface(message) } else if (requestId === root.catalogRequestId) { catalogOwner.failCatalog(message, code) } else if (requestId === root.storeRequestId) { catalogOwner.failStore(message) } else if (requestId === root.providersRequestId) { root.providersRequestId = "" if (code !== "cancelled") root.scheduleProviderRetry(0) } else if (requestId === root.authSessionRequestId) { root.authSessionRequestId = "" root.authRestorePending = false root.authState = root.settledAuthState(root.authSession) if (code !== "cancelled") root.authMessage = message root.resolveDirectLaunch() if (root.coreSessionRestoreId !== "" && code !== "cancelled") root.handleStreamPollFailure(code, message) } else if (requestId === root.deviceStartRequestId || requestId === root.devicePollRequestId || requestId === root.deviceCompleteRequestId) { root.deviceStartRequestId = "" root.devicePollRequestId = "" root.deviceCompleteRequestId = "" root.cancelDeviceLogin() root.authState = code === "cancelled" ? "idle" : "error" root.authMessage = code === "cancelled" ? "" : message if (code === "system_clock_wrong") { root.authMessage = qsTr("Your computer's clock is wrong, so you can't sign in yet. Turn on automatic date and time in your system settings, then try again.") root.clockSkewDismissed = false root.refreshProviders() } } else if (requestId === root.logoutRequestId) { root.logoutRequestId = "" root.authMessage = message } else if (requestId === root.logoutAllRequestId) { root.logoutAllRequestId = "" root.authMessage = message root.accountMessage = message } else if (requestId === root.subscriptionRequestId) { accountServicesOwner.failSubscription(message) } else if (requestId === root.regionsRequestId) { accountServicesOwner.failRegions(message) } else if (requestId === root.regionPingRequestId) { accountServicesOwner.failRegionPing(message) } else if (requestId === root.accountsRequestId) { root.accountsRequestId = "" root.accountsLoaded = true } else if (requestId === root.accountSwitchRequestId) { root.accountSwitchRequestId = "" root.accountSwitchTargetUserId = "" root.pinMessage = message root.accountMessage = message } else if (requestId === root.accountRemoveRequestId) { root.accountRemoveRequestId = "" root.accountMessage = message } else if (requestId === root.pinRequestId) { root.pinRequestId = "" root.pinMessage = message } else if (requestId === root.gameAccountsRequestId) { accountServicesOwner.failGameAccounts(message) } else if (requestId === root.gameAccountActionRequestId) { accountServicesOwner.failGameAccountAction(message) } else if (requestId === root.accountLinkStartRequestId) { accountServicesOwner.failAccountLinkStart(message) } else if (requestId === root.accountLinkPollRequestId) { accountServicesOwner.failAccountLinkPoll(message) } else if (requestId === root.storageLocationsRequestId) { accountServicesOwner.failStorageLocations(message) } else if (requestId === root.storageResetRequestId) { accountServicesOwner.failStorageReset(message) } else if (requestId === root.mediaRequestId) { root.mediaRequestId = "" root.mediaState = "error" root.mediaMessage = message } else if (requestId === root.mediaDeleteRequestId) { root.mediaDeleteRequestId = "" root.mediaMessage = message } else if (requestId === root.mediaClipTargetRequestId && requestId !== "") { root.mediaClipTargetRequestId = "" root.mediaMessage = message root.accessibilityMessage = message root.streamCaptureAnnounced(message) } else if (requestId === root.mediaRecordingTargetRequestId) { root.mediaRecordingTargetRequestId = "" root.mediaRecordingTargetSessionId = "" root.streamRecordingIntentSessionId = "" root.pendingRecordingPath = "" root.pendingRecordingThumbnailPath = "" root.mediaMessage = message } else if (requestId === root.diagnosticsRequestId) { root.diagnosticsRequestId = "" root.diagnosticsMessage = message } else if (requestId === root.diagnosticsExportRequestId) { root.diagnosticsExportRequestId = "" root.diagnosticsMessage = message } else if (requestId === root.acceptanceExportRequestId) { root.acceptanceExportRequestId = "" root.diagnosticsMessage = message } else if (requestId === root.updaterStateRequestId) { root.updaterStateRequestId = "" root.updaterError = message root.updaterReconciling = true } else if (requestId === root.updaterCheckRequestId) { root.updaterCheckRequestId = "" root.reconcileUpdaterFailure(message) } else if (requestId === root.updaterHighlightsRequestId) { root.updaterHighlightsRequestId = "" } else if (requestId === root.updaterDownloadRequestId) { root.updaterDownloadRequestId = "" root.reconcileUpdaterFailure(message) } else if (requestId === root.updaterInstallRequestId) { root.updaterInstallRequestId = "" root.updaterFailureMessage = message root.reconcileUpdaterFailure(message) } else if (requestId === root.socialCapabilitiesRequestId) { root.socialCapabilitiesRequestId = "" root.socialCapabilities = Object.assign({}, root.socialCapabilities, { reason: qsTr("Provider social capabilities could not be checked.") }) } else if (requestId === root.discordRequestId) { root.discordRequestId = "" } else if (requestId === root.feedbackRequestId) { root.feedbackRequestId = "" root.reportingState = "error" root.reportingMessage = message } else if (requestId === root.bugReportRequestId) { root.bugReportRequestId = "" root.reportingState = "error" root.reportingMessage = message } else if (requestId === root.activeSessionRequestId) { root.activeSessionRequestId = "" } else if (requestId === root.remoteSessionsRequestId) { root.remoteSessionsRequestId = "" if (code === "session_discovery_failed" && root.launchIntentCurrent() && !root.activeSession && !root.conflictSession && !root.conflictSessionNeedsRefresh && !root.launchConflictDetected && !root.onboardingReplaying) { root.lastError = "" root.createPendingSession() return } root.streamState = "error" root.streamMessage = qsTr("We couldn't check whether your game is still running. Check your connection, then try again.") root.lastError = root.streamMessage } else if (requestId === root.recoveryDiscoveryRequestId) { root.recoveryDiscoveryRequestId = "" root.scheduleSessionRecovery(message) } else if (requestId === root.sessionClaimRequestId) { const recovering = root.sessionClaimIsRecovery root.sessionClaimRequestId = "" root.sessionClaimIsRecovery = false if (recovering) { if (code === "session_not_found") root.finishRemoteSession({source: "cloudmatch-http", httpStatus: 404, resumable: false}) else root.scheduleSessionRecovery(message) } else { root.conflictSessionNeedsRefresh = true root.streamState = "conflict" root.streamMessage = qsTr("We couldn't reconnect to your game. Try returning to it again, or end it and start over. Ending it may lose unsaved progress.") root.lastError = root.streamMessage AppController.showOverlay("session-conflict") } } else if (requestId === root.streamCreateRequestId) { root.streamCreateRequestId = "" root.handleSessionCreateFailure(code, message) } else if (requestId === root.streamPollRequestId) { root.streamPollRequestId = "" root.handleStreamPollFailure(code, message) } else if (requestId === root.streamStopRequestId) { root.streamStopRequestId = "" if (root.pendingAccountSwitch) { root.pendingAccountSwitch = null root.accountMessage = message } root.forceNewAfterStop = false root.streamState = root.conflictSession ? "conflict" : "error" root.streamMessage = qsTr("The previous game hasn't closed. Try again in a moment. We won't start another game until it has ended.") root.lastError = root.streamMessage if (root.conflictSession) AppController.showOverlay("session-conflict") } else if (requestId === root.streamerPrepareRequestId) { root.streamerPrepareRequestId = "" root.acceptStreamerSnapshot({ status: "error", message: message, errorCode: code }) } } function onEventReceived(name, payload) { if (name === "settings.changed") { settingsOwner.acceptSettingsChange(payload) } else if (name === "settings.reset") { if (!settingsOwner.resetting) root.refreshSettings() } else if (name === "auth.session.changed") { if (!root.acceptAuthEnvelope(payload)) return root.authState = root.settledAuthState(root.authSession) if (root.authSession) root.refreshRemoteSessions() else root.remoteSessions = [] } else if (name === "session.cleanup.pending") { root.lastError = String(payload.message || "") root.streamMessage = root.lastError root.refreshRemoteSessions() } else if (name === "session.changed") { if (payload.adReportIdentity !== undefined) { root.acceptSessionAdSnapshot(payload) return } const ownedTermination = root.ownedSessionTermination(payload) if (ownedTermination) { root.finishRemoteSession(ownedTermination) return } if (!root.acceptsSessionScope(payload.scope)) return if (root.isRemoteSessionTermination(payload.termination)) root.finishRemoteSession(payload.termination) else root.acceptStreamingSession(payload.session || null) } else if (name === "account.push.changed") root.acceptPushInvalidation(payload) else if (name === "streamer.changed") root.acceptStreamerSnapshot(payload.streamer || payload || null) else if (name === "artwork.ready") root.acceptArtworkResult(payload) else if (name === "updater.changed") root.acceptUpdaterState(payload) else if (name === "bug_report.changed") root.bugReports.acceptEvent(payload) else if (name === "updater.highlights.show") { root.releaseHighlights = payload root.releaseHighlightsPending = !root.updaterSessionSafe if (root.updaterSessionSafe) root.accessibilityMessage = qsTr("Release notes are available in Updates.") } } } }