diff --git a/Limelight/Network/DiscoveryManager.m b/Limelight/Network/DiscoveryManager.m index 05f5b1d..de17574 100644 --- a/Limelight/Network/DiscoveryManager.m +++ b/Limelight/Network/DiscoveryManager.m @@ -41,7 +41,7 @@ - (void) discoverHost:(NSString *)hostAddress withCallback:(void (^)(Host *, NSString*))callback { HttpManager* hMan = [[HttpManager alloc] initWithHost:hostAddress uniqueId:_uniqueId deviceName:deviceName cert:_cert]; ServerInfoResponse* serverInfoResponse = [[ServerInfoResponse alloc] init]; - [hMan executeRequestSynchronously:[HttpRequest requestForResponse:serverInfoResponse withUrlRequest:[hMan newServerInfoRequest]]]; + [hMan executeRequestSynchronously:[HttpRequest requestForResponse:serverInfoResponse withUrlRequest:[hMan newServerInfoRequest] fallbackError:401 fallbackRequest:[hMan newHttpServerInfoRequest]]]; Host* host = nil; if ([serverInfoResponse isStatusOk]) { diff --git a/Limelight/Network/DiscoveryWorker.m b/Limelight/Network/DiscoveryWorker.m index e871aca..9d9314e 100644 --- a/Limelight/Network/DiscoveryWorker.m +++ b/Limelight/Network/DiscoveryWorker.m @@ -68,7 +68,8 @@ static const float POLL_RATE = 2.0f; // Poll every 2 seconds cert:_cert]; ServerInfoResponse* response = [[ServerInfoResponse alloc] init]; [hMan executeRequestSynchronously:[HttpRequest requestForResponse:response - withUrlRequest:[hMan newServerInfoRequest]]]; + withUrlRequest:[hMan newServerInfoRequest] + fallbackError:401 fallbackRequest:[hMan newHttpServerInfoRequest]]]; return response; } diff --git a/Limelight/Network/HttpManager.h b/Limelight/Network/HttpManager.h index b96ee47..d72a618 100644 --- a/Limelight/Network/HttpManager.h +++ b/Limelight/Network/HttpManager.h @@ -22,6 +22,7 @@ - (NSURLRequest*) newPairChallenge; - (NSURLRequest*) newAppListRequest; - (NSURLRequest*) newServerInfoRequest; +- (NSURLRequest*) newHttpServerInfoRequest; - (NSURLRequest*) newLaunchRequest:(NSString*)appId width:(int)width height:(int)height refreshRate:(int)refreshRate rikey:(NSString*)rikey rikeyid:(int)rikeyid; - (NSURLRequest*) newResumeRequestWithRiKey:(NSString*)riKey riKeyId:(int)riKeyId; - (NSURLRequest*) newQuitAppRequest; diff --git a/Limelight/Network/HttpManager.m b/Limelight/Network/HttpManager.m index 70bf8c7..da6f20a 100644 --- a/Limelight/Network/HttpManager.m +++ b/Limelight/Network/HttpManager.m @@ -83,6 +83,15 @@ static const NSString* HTTPS_PORT = @"47984"; if (!_errorOccurred && request.response) { [request.response populateWithData:_requestResp]; + + // If the fallback error code was detected, issue the fallback request + if (request.response.statusCode == request.fallbackError && request.fallbackRequest != NULL) { + Log(LOG_D, @"Request failed with fallback error code: %d", request.fallbackError); + request.request = request.fallbackRequest; + request.fallbackError = 0; + request.fallbackRequest = NULL; + [self executeRequestSynchronously:request]; + } } _errorOccurred = false; } @@ -145,6 +154,11 @@ static const NSString* HTTPS_PORT = @"47984"; return [self createRequestFromString:urlString enableTimeout:TRUE]; } +- (NSURLRequest *)newHttpServerInfoRequest { + NSString* urlString = [NSString stringWithFormat:@"%@/serverinfo", _baseHTTPURL]; + return [self createRequestFromString:urlString enableTimeout:TRUE]; +} + - (NSURLRequest*) newLaunchRequest:(NSString*)appId width:(int)width height:(int)height refreshRate:(int)refreshRate rikey:(NSString*)rikey rikeyid:(int)rikeyid { NSString* urlString = [NSString stringWithFormat:@"%@/launch?uniqueid=%@&appid=%@&mode=%dx%dx%d&additionalStates=1&sops=1&rikey=%@&rikeyid=%d", _baseHTTPSURL, _uniqueId, appId, width, height, refreshRate, rikey, rikeyid]; // This blocks while the app is launching diff --git a/Limelight/Network/HttpRequest.h b/Limelight/Network/HttpRequest.h index bead208..743b58b 100644 --- a/Limelight/Network/HttpRequest.h +++ b/Limelight/Network/HttpRequest.h @@ -13,7 +13,10 @@ @property (nonatomic) id response; @property (nonatomic) NSURLRequest* request; +@property (nonatomic) int fallbackError; +@property (nonatomic) NSURLRequest* fallbackRequest; ++ (instancetype) requestForResponse:(id)response withUrlRequest:(NSURLRequest*)req fallbackError:(int)error fallbackRequest:(NSURLRequest*) fallbackReq; + (instancetype) requestForResponse:(id)response withUrlRequest:(NSURLRequest*)req; + (instancetype) requestWithUrlRequest:(NSURLRequest*)req; diff --git a/Limelight/Network/HttpRequest.m b/Limelight/Network/HttpRequest.m index 69298ed..afb1c89 100644 --- a/Limelight/Network/HttpRequest.m +++ b/Limelight/Network/HttpRequest.m @@ -25,4 +25,13 @@ return request; } ++ (HttpRequest*) requestForResponse:(id)response withUrlRequest:(NSURLRequest*)req fallbackError:(int)error fallbackRequest:(NSURLRequest*) fallbackReq { + HttpRequest* request = [[HttpRequest alloc] init]; + request.request = req; + request.response = response; + request.fallbackError = error; + request.fallbackRequest = fallbackReq; + return request; +} + @end diff --git a/Limelight/Network/PairManager.m b/Limelight/Network/PairManager.m index 616bb32..82ff2b2 100644 --- a/Limelight/Network/PairManager.m +++ b/Limelight/Network/PairManager.m @@ -31,7 +31,8 @@ - (void) main { ServerInfoResponse* serverInfoResp = [[ServerInfoResponse alloc] init]; - [_httpManager executeRequestSynchronously:[HttpRequest requestForResponse:serverInfoResp withUrlRequest:[_httpManager newServerInfoRequest]]]; + [_httpManager executeRequestSynchronously:[HttpRequest requestForResponse:serverInfoResp withUrlRequest:[_httpManager newServerInfoRequest] + fallbackError:401 fallbackRequest:[_httpManager newHttpServerInfoRequest]]]; if (serverInfoResp == nil) { [_callback pairFailed:@"Unable to connect to PC"]; return; diff --git a/Limelight/Stream/StreamManager.m b/Limelight/Stream/StreamManager.m index 3308ad1..d9087c3 100644 --- a/Limelight/Stream/StreamManager.m +++ b/Limelight/Stream/StreamManager.m @@ -45,7 +45,8 @@ cert:cert]; ServerInfoResponse* serverInfoResp = [[ServerInfoResponse alloc] init]; - [hMan executeRequestSynchronously:[HttpRequest requestForResponse:serverInfoResp withUrlRequest:[hMan newServerInfoRequest]]]; + [hMan executeRequestSynchronously:[HttpRequest requestForResponse:serverInfoResp withUrlRequest:[hMan newServerInfoRequest] + fallbackError:401 fallbackRequest:[hMan newHttpServerInfoRequest]]]; NSString* currentGame = [serverInfoResp getStringTag:@"currentgame"]; NSString* pairStatus = [serverInfoResp getStringTag:@"PairStatus"]; NSString* currentClient = [serverInfoResp getStringTag:@"CurrentClient"]; diff --git a/Limelight/ViewControllers/MainFrameViewController.m b/Limelight/ViewControllers/MainFrameViewController.m index d797d1e..e188607 100644 --- a/Limelight/ViewControllers/MainFrameViewController.m +++ b/Limelight/ViewControllers/MainFrameViewController.m @@ -133,7 +133,8 @@ static NSArray* appList; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ HttpManager* hMan = [[HttpManager alloc] initWithHost:host.address uniqueId:_uniqueId deviceName:deviceName cert:_cert]; ServerInfoResponse* serverInfoResp = [[ServerInfoResponse alloc] init]; - [hMan executeRequestSynchronously:[HttpRequest requestForResponse:serverInfoResp withUrlRequest:[hMan newServerInfoRequest]]]; + [hMan executeRequestSynchronously:[HttpRequest requestForResponse:serverInfoResp withUrlRequest:[hMan newServerInfoRequest] + fallbackError:401 fallbackRequest:[hMan newHttpServerInfoRequest]]]; if (serverInfoResp == nil || ![serverInfoResp isStatusOk]) { Log(LOG_W, @"Failed to get server info: %@", serverInfoResp.statusMessage); [self hideLoadingFrame];