Add automatic network testing on connection failure

This commit is contained in:
Cameron Gutman
2020-08-10 22:56:47 -07:00
parent 3ab0829db5
commit 286b19d360
4 changed files with 42 additions and 19 deletions
+3 -1
View File
@@ -9,13 +9,15 @@
#import "VideoDecoderRenderer.h" #import "VideoDecoderRenderer.h"
#import "StreamConfiguration.h" #import "StreamConfiguration.h"
#define CONN_TEST_SERVER "ios.conntest.moonlight-stream.org"
@protocol ConnectionCallbacks <NSObject> @protocol ConnectionCallbacks <NSObject>
- (void) connectionStarted; - (void) connectionStarted;
- (void) connectionTerminated:(int)errorCode; - (void) connectionTerminated:(int)errorCode;
- (void) stageStarting:(const char*)stageName; - (void) stageStarting:(const char*)stageName;
- (void) stageComplete:(const char*)stageName; - (void) stageComplete:(const char*)stageName;
- (void) stageFailed:(const char*)stageName withError:(int)errorCode; - (void) stageFailed:(const char*)stageName withError:(int)errorCode portTestFlags:(int)portTestFlags;
- (void) launchFailed:(NSString*)message; - (void) launchFailed:(NSString*)message;
- (void) rumble:(unsigned short)controllerNumber lowFreqMotor:(unsigned short)lowFreqMotor highFreqMotor:(unsigned short)highFreqMotor; - (void) rumble:(unsigned short)controllerNumber lowFreqMotor:(unsigned short)lowFreqMotor highFreqMotor:(unsigned short)highFreqMotor;
- (void) connectionStatusUpdate:(int)status; - (void) connectionStatusUpdate:(int)status;
+1 -1
View File
@@ -268,7 +268,7 @@ void ClStageComplete(int stage)
void ClStageFailed(int stage, int errorCode) void ClStageFailed(int stage, int errorCode)
{ {
[_callbacks stageFailed:LiGetStageName(stage) withError:errorCode]; [_callbacks stageFailed:LiGetStageName(stage) withError:errorCode portTestFlags:LiGetPortFlagsFromStage(stage)];
} }
void ClConnectionStarted(void) void ClConnectionStarted(void)
@@ -509,6 +509,12 @@ static NSMutableSet* hostList;
[self updateHosts]; [self updateHosts];
}); });
} else { } else {
unsigned int portTestResults = LiTestClientConnectivity(CONN_TEST_SERVER, 443,
ML_PORT_FLAG_TCP_47984 | ML_PORT_FLAG_TCP_47989);
if (portTestResults != ML_TEST_RESULT_INCONCLUSIVE && portTestResults != 0) {
error = [error stringByAppendingString:@"\n\nYour device's Internet connection is blocking Moonlight. Streaming over the Internet may not work while connected to this network."];
}
UIAlertController* hostNotFoundAlert = [UIAlertController alertControllerWithTitle:@"Add Host Manually" message:error preferredStyle:UIAlertControllerStyleAlert]; UIAlertController* hostNotFoundAlert = [UIAlertController alertControllerWithTitle:@"Add Host Manually" message:error preferredStyle:UIAlertControllerStyleAlert];
[Utils addHelpOptionToDialog:hostNotFoundAlert]; [Utils addHelpOptionToDialog:hostNotFoundAlert];
[hostNotFoundAlert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]]; [hostNotFoundAlert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]];
@@ -233,6 +233,9 @@
- (void)connectionTerminated:(int)errorCode { - (void)connectionTerminated:(int)errorCode {
Log(LOG_I, @"Connection terminated: %d", errorCode); Log(LOG_I, @"Connection terminated: %d", errorCode);
unsigned int portTestResults = LiTestClientConnectivity(CONN_TEST_SERVER, 443,
LiGetPortFlagsFromTerminationErrorCode(errorCode));
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
// Allow the display to go to sleep now // Allow the display to go to sleep now
[UIApplication sharedApplication].idleTimerDisabled = NO; [UIApplication sharedApplication].idleTimerDisabled = NO;
@@ -240,20 +243,26 @@
NSString* title; NSString* title;
NSString* message; NSString* message;
switch (errorCode) { if (portTestResults != ML_TEST_RESULT_INCONCLUSIVE && portTestResults != 0) {
case ML_ERROR_GRACEFUL_TERMINATION: title = @"Connection Error";
[self returnToMainFrame]; message = @"Your device's Internet connection is blocking Moonlight. Streaming over the Internet may not work while connected to this network.";
return; }
else {
case ML_ERROR_NO_VIDEO_TRAFFIC: switch (errorCode) {
title = @"Connection Error"; case ML_ERROR_GRACEFUL_TERMINATION:
message = @"No video received from host. Check the host PC's firewall and port forwarding rules."; [self returnToMainFrame];
break; return;
default: case ML_ERROR_NO_VIDEO_TRAFFIC:
title = @"Connection Terminated"; title = @"Connection Error";
message = @"The connection was terminated"; message = @"No video received from host. Check the host PC's firewall and port forwarding rules.";
break; break;
default:
title = @"Connection Terminated";
message = @"The connection was terminated";
break;
}
} }
UIAlertController* conTermAlert = [UIAlertController alertControllerWithTitle:title UIAlertController* conTermAlert = [UIAlertController alertControllerWithTitle:title
@@ -283,16 +292,22 @@
- (void) stageComplete:(const char*)stageName { - (void) stageComplete:(const char*)stageName {
} }
- (void) stageFailed:(const char*)stageName withError:(int)errorCode { - (void) stageFailed:(const char*)stageName withError:(int)errorCode portTestFlags:(int)portTestFlags {
Log(LOG_I, @"Stage %s failed: %d", stageName, errorCode); Log(LOG_I, @"Stage %s failed: %d", stageName, errorCode);
unsigned int portTestResults = LiTestClientConnectivity(CONN_TEST_SERVER, 443, portTestFlags);
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
// Allow the display to go to sleep now // Allow the display to go to sleep now
[UIApplication sharedApplication].idleTimerDisabled = NO; [UIApplication sharedApplication].idleTimerDisabled = NO;
NSString* message = [NSString stringWithFormat:@"%s failed with error %d", stageName, errorCode];
if (portTestResults != ML_TEST_RESULT_INCONCLUSIVE && portTestResults != 0) {
message = [message stringByAppendingString:@"\n\nYour device's Internet connection is blocking Moonlight. Streaming over the Internet may not work while connected to this network."];
}
UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Connection Failed" UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Connection Failed"
message:[NSString stringWithFormat:@"%s failed with error %d", message:message
stageName, errorCode]
preferredStyle:UIAlertControllerStyleAlert]; preferredStyle:UIAlertControllerStyleAlert];
[Utils addHelpOptionToDialog:alert]; [Utils addHelpOptionToDialog:alert];
[alert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction* action){ [alert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction* action){