mirror of
https://github.com/moonlight-stream/moonlight-ios.git
synced 2026-06-17 06:01:13 +00:00
Fix "server busy" pairing error dialog
This commit is contained in:
@@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
@protocol PairCallback <NSObject>
|
@protocol PairCallback <NSObject>
|
||||||
|
|
||||||
- (void) showPIN:(NSString*)PIN;
|
- (void) startPairing:(NSString*)PIN;
|
||||||
- (void) pairSuccessful:(NSData*)serverCert;
|
- (void) pairSuccessful:(NSData*)serverCert;
|
||||||
- (void) pairFailed:(NSString*)message;
|
- (void) pairFailed:(NSString*)message;
|
||||||
- (void) alreadyPaired;
|
- (void) alreadyPaired;
|
||||||
@@ -19,8 +19,4 @@
|
|||||||
|
|
||||||
@interface PairManager : NSOperation
|
@interface PairManager : NSOperation
|
||||||
- (id) initWithManager:(HttpManager*)httpManager clientCert:(NSData*)clientCert callback:(id<PairCallback>)callback;
|
- (id) initWithManager:(HttpManager*)httpManager clientCert:(NSData*)clientCert callback:(id<PairCallback>)callback;
|
||||||
- (NSString*) generatePIN;
|
|
||||||
- (NSData*) saltPIN:(NSString*)PIN;
|
|
||||||
- (void) initiatePair:(int)serverMajorVersion;
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -30,6 +30,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void) main {
|
- (void) main {
|
||||||
|
// We have to call startPairing before calling any other _callback functions
|
||||||
|
NSString* PIN = [self generatePIN];
|
||||||
|
[_callback startPairing:PIN];
|
||||||
|
|
||||||
ServerInfoResponse* serverInfoResp = [[ServerInfoResponse alloc] init];
|
ServerInfoResponse* serverInfoResp = [[ServerInfoResponse alloc] init];
|
||||||
[_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]]];
|
||||||
@@ -42,7 +46,7 @@
|
|||||||
[_callback pairFailed:@"Missing XML element"];
|
[_callback pairFailed:@"Missing XML element"];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
[self initiatePair: [[appversion substringToIndex:1] intValue]];
|
[self initiatePairWithPin:PIN forServerMajorVersion:[[appversion substringToIndex:1] intValue]];
|
||||||
} else {
|
} else {
|
||||||
[_callback alreadyPaired];
|
[_callback alreadyPaired];
|
||||||
}
|
}
|
||||||
@@ -78,7 +82,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// All codepaths must call finishPairing exactly once before returning!
|
// All codepaths must call finishPairing exactly once before returning!
|
||||||
- (void) initiatePair:(int)serverMajorVersion {
|
- (void) initiatePairWithPin:(NSString*)PIN forServerMajorVersion:(int)serverMajorVersion {
|
||||||
Log(LOG_I, @"Pairing with generation %d server", serverMajorVersion);
|
Log(LOG_I, @"Pairing with generation %d server", serverMajorVersion);
|
||||||
|
|
||||||
// Start a background task to help prevent the app from being killed
|
// Start a background task to help prevent the app from being killed
|
||||||
@@ -87,10 +91,8 @@
|
|||||||
Log(LOG_W, @"Background pairing time has expired!");
|
Log(LOG_W, @"Background pairing time has expired!");
|
||||||
}];
|
}];
|
||||||
|
|
||||||
NSString* PIN = [self generatePIN];
|
|
||||||
NSData* salt = [self saltPIN:PIN];
|
NSData* salt = [self saltPIN:PIN];
|
||||||
Log(LOG_I, @"PIN: %@, saltedPIN: %@", PIN, salt);
|
Log(LOG_I, @"PIN: %@, saltedPIN: %@", PIN, salt);
|
||||||
[_callback showPIN:PIN];
|
|
||||||
|
|
||||||
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]]];
|
||||||
|
|||||||
@@ -56,8 +56,10 @@
|
|||||||
}
|
}
|
||||||
static NSMutableSet* hostList;
|
static NSMutableSet* hostList;
|
||||||
|
|
||||||
- (void)showPIN:(NSString *)PIN {
|
- (void)startPairing:(NSString *)PIN {
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
// Needs to be synchronous to ensure the alert is shown before any potential
|
||||||
|
// failure callback could be invoked.
|
||||||
|
dispatch_sync(dispatch_get_main_queue(), ^{
|
||||||
self->_pairAlert = [UIAlertController alertControllerWithTitle:@"Pairing"
|
self->_pairAlert = [UIAlertController alertControllerWithTitle:@"Pairing"
|
||||||
message:[NSString stringWithFormat:@"Enter the following PIN on the host machine: %@", PIN]
|
message:[NSString stringWithFormat:@"Enter the following PIN on the host machine: %@", PIN]
|
||||||
preferredStyle:UIAlertControllerStyleAlert];
|
preferredStyle:UIAlertControllerStyleAlert];
|
||||||
|
|||||||
Reference in New Issue
Block a user