Allow pairing with Sunshine hosts while streaming

This commit is contained in:
Cameron Gutman 2022-12-04 16:54:37 -06:00
parent 365f61b393
commit c7badef9d7

View File

@ -38,15 +38,13 @@
[_httpManager executeRequestSynchronously:[HttpRequest requestForResponse:serverInfoResp withUrlRequest:[_httpManager newServerInfoRequest:false] [_httpManager executeRequestSynchronously:[HttpRequest requestForResponse:serverInfoResp withUrlRequest:[_httpManager newServerInfoRequest:false]
fallbackError:401 fallbackRequest:[_httpManager newHttpServerInfoRequest]]]; fallbackError:401 fallbackRequest:[_httpManager newHttpServerInfoRequest]]];
if ([serverInfoResp isStatusOk]) { if ([serverInfoResp isStatusOk]) {
if ([[serverInfoResp getStringTag:@"state"] hasSuffix:@"_SERVER_BUSY"]) { if (![[serverInfoResp getStringTag:@"PairStatus"] isEqual:@"1"]) {
[_callback pairFailed:@"You cannot pair while a previous session is still running on the host PC. Quit any running games or reboot the host PC, then try pairing again."];
} else if (![[serverInfoResp getStringTag:@"PairStatus"] isEqual:@"1"]) {
NSString* appversion = [serverInfoResp getStringTag:@"appversion"]; NSString* appversion = [serverInfoResp getStringTag:@"appversion"];
if (appversion == nil) { if (appversion == nil) {
[_callback pairFailed:@"Missing XML element"]; [_callback pairFailed:@"Missing XML element"];
return; return;
} }
[self initiatePairWithPin:PIN forServerMajorVersion:[[appversion substringToIndex:1] intValue]]; [self initiatePairWithPin:PIN forServerMajorVersion:[[appversion substringToIndex:1] intValue] withState:[serverInfoResp getStringTag:@"state"]];
} else { } else {
[_callback alreadyPaired]; [_callback alreadyPaired];
} }
@ -82,8 +80,8 @@
} }
// All codepaths must call finishPairing exactly once before returning! // All codepaths must call finishPairing exactly once before returning!
- (void) initiatePairWithPin:(NSString*)PIN forServerMajorVersion:(int)serverMajorVersion { - (void) initiatePairWithPin:(NSString*)PIN forServerMajorVersion:(int)serverMajorVersion withState:(NSString*)state {
Log(LOG_I, @"Pairing with generation %d server", serverMajorVersion); Log(LOG_I, @"Pairing with generation %d server in state %@", serverMajorVersion, state);
// Start a background task to help prevent the app from being killed // Start a background task to help prevent the app from being killed
// while pairing is in progress. // while pairing is in progress.
@ -99,7 +97,13 @@
HttpResponse* pairResp = [[HttpResponse alloc] init]; HttpResponse* pairResp = [[HttpResponse alloc] init];
[_httpManager executeRequestSynchronously:[HttpRequest requestForResponse:pairResp withUrlRequest:[_httpManager newPairRequest:salt clientCert:_clientCert]]]; [_httpManager executeRequestSynchronously:[HttpRequest requestForResponse:pairResp withUrlRequest:[_httpManager newPairRequest:salt clientCert:_clientCert]]];
if (![self verifyResponseStatus:pairResp]) { if (![self verifyResponseStatus:pairResp]) {
[self finishPairing:bgId forResponse:pairResp withFallbackError:@"Pairing was declined by the target."]; // GFE does not allow pairing while a server is busy, but Sunshine does. We give it a try and display the busy error if it fails.
if ([state hasSuffix:@"_SERVER_BUSY"]) {
[self finishPairing:bgId forResponse:pairResp withFallbackError:@"You cannot pair while a previous session is still running on the host PC. Quit any running games or reboot the host PC, then try pairing again."];
}
else {
[self finishPairing:bgId forResponse:pairResp withFallbackError:@"Pairing was declined by the target."];
}
return; return;
} }