Distinguish between offline and unknown hosts

This commit is contained in:
Cameron Gutman
2019-08-30 19:19:23 -07:00
parent a065c78b5f
commit 6d94897c21
7 changed files with 50 additions and 17 deletions

View File

@@ -11,7 +11,7 @@
@interface TemporaryHost : NSObject
@property (nonatomic) BOOL online;
@property (nonatomic) State state;
@property (nonatomic) PairState pairState;
@property (nonatomic, nullable) NSString * activeAddress;
@property (nonatomic, nullable) NSString * currentGame;

View File

@@ -16,6 +16,7 @@
self = [super init];
self.appList = [[NSMutableSet alloc] init];
self.currentGame = @"0";
self.state = StateUnknown;
return self;
}

View File

@@ -56,7 +56,7 @@
if ([serverInfoResponse isStatusOk]) {
host = [[TemporaryHost alloc] init];
host.activeAddress = host.address = hostAddress;
host.online = YES;
host.state = StateOnline;
[serverInfoResponse populateHost:host];
if (![self addHostToDiscovery:host]) {
callback(nil, @"Host information updated");
@@ -137,7 +137,7 @@
existingHost.externalAddress = host.externalAddress;
}
existingHost.activeAddress = host.activeAddress;
existingHost.online = host.online;
existingHost.state = host.state;
return NO;
}
else {

View File

@@ -118,9 +118,9 @@ static const float POLL_RATE = 2.0f; // Poll every 2 seconds
}
}
_host.online = receivedResponse;
_host.state = receivedResponse ? StateOnline : StateOffline;
if (receivedResponse) {
Log(LOG_D, @"Received response from: %@\n{\n\t address:%@ \n\t localAddress:%@ \n\t externalAddress:%@ \n\t ipv6Address:%@ \n\t uuid:%@ \n\t mac:%@ \n\t pairState:%d \n\t online:%d \n\t activeAddress:%@ \n}", _host.name, _host.address, _host.localAddress, _host.externalAddress, _host.ipv6Address, _host.uuid, _host.mac, _host.pairState, _host.online, _host.activeAddress);
Log(LOG_D, @"Received response from: %@\n{\n\t address:%@ \n\t localAddress:%@ \n\t externalAddress:%@ \n\t ipv6Address:%@ \n\t uuid:%@ \n\t mac:%@ \n\t pairState:%d \n\t online:%d \n\t activeAddress:%@ \n}", _host.name, _host.address, _host.localAddress, _host.externalAddress, _host.ipv6Address, _host.uuid, _host.mac, _host.pairState, _host.state, _host.activeAddress);
}
}

View File

@@ -33,14 +33,14 @@ static const int LABEL_DY = 20;
_hostButton.layer.shadowColor = [[UIColor blackColor] CGColor];
_hostButton.layer.shadowOffset = CGSizeMake(5,8);
_hostButton.layer.shadowOpacity = 0.7;
_hostButton.layer.shadowOpacity = 0.3;
_hostLabel = [[UILabel alloc] init];
#if !TARGET_OS_TV
_hostLabel.textColor = [UIColor whiteColor];
#endif
_hostOverlay = [[UIImageView alloc] initWithFrame:CGRectMake(_hostButton.frame.size.width / 4, _hostButton.frame.size.height / 6, _hostButton.frame.size.width / 2, _hostButton.frame.size.height / 2)];
_hostOverlay = [[UIImageView alloc] initWithFrame:CGRectMake(_hostButton.frame.size.width / 3, _hostButton.frame.size.height / 4, _hostButton.frame.size.width / 3, _hostButton.frame.size.height / 3)];
[self addSubview:_hostButton];
[self addSubview:_hostLabel];
@@ -122,7 +122,7 @@ static const int LABEL_DY = 20;
_hostLabel.text = _host.name;
[_hostLabel sizeToFit];
if (host.online) {
if (host.state == StateOnline) {
if (host.pairState == PairStateUnpaired) {
[_hostOverlay setImage:[UIImage imageNamed:@"LockedOverlayIcon"]];
}
@@ -130,10 +130,12 @@ static const int LABEL_DY = 20;
[_hostOverlay setImage:nil];
}
}
else {
// TODO: Use updating icon if we've not determined online state yet
else if (host.state == StateOffline) {
[_hostOverlay setImage:[UIImage imageNamed:@"ErrorOverlayIcon"]];
}
else {
[_hostOverlay setImage:[UIImage imageNamed:@"UpdatingOverlayIcon"]];
}
float x = _hostButton.frame.origin.x + _hostButton.frame.size.width / 2;
_hostLabel.center = CGPointMake(x, _hostButton.frame.origin.y + _hostButton.frame.size.height + LABEL_DY);

View File

@@ -14,6 +14,12 @@ typedef NS_ENUM(int, PairState) {
PairStatePaired
};
typedef NS_ENUM(int, State) {
StateUnknown,
StateOffline,
StateOnline
};
FOUNDATION_EXPORT NSString *const deviceName;
+ (NSData*) randomBytes:(NSInteger)length;

View File

@@ -162,7 +162,7 @@ static NSMutableSet* hostList;
[self hideLoadingFrame: ^{
[[self activeViewController] presentViewController:applistAlert animated:YES completion:nil];
}];
host.online = NO;
host.state = StateOffline;
[self showHostSelectionView];
});
} else {
@@ -284,7 +284,7 @@ static NSMutableSet* hostList;
// This shows the context menu with wake, delete, etc. rather
// than just hanging for a while and failing as we would in this
// code path.
if (!host.online && view != nil) {
if (host.state != StateOnline && view != nil) {
[self hostLongClicked:host view:view];
return;
}
@@ -303,7 +303,7 @@ static NSMutableSet* hostList;
// should hit most. Check for a valid view because we don't want to hit the fast
// path after coming back from streaming, since we need to fetch serverinfo too
// so that our active game data is correct.
if (host.online && host.pairState == PairStatePaired && host.appList.count > 0 && view != nil) {
if (host.state == StateOnline && host.pairState == PairStatePaired && host.appList.count > 0 && view != nil) {
[self alreadyPaired];
return;
}
@@ -341,7 +341,7 @@ static NSMutableSet* hostList;
}
}];
host.online = NO;
host.state = StateOffline;
[self showHostSelectionView];
});
} else {
@@ -384,8 +384,32 @@ static NSMutableSet* hostList;
- (void)hostLongClicked:(TemporaryHost *)host view:(UIView *)view {
Log(LOG_D, @"Long clicked host: %@", host.name);
UIAlertController* longClickAlert = [UIAlertController alertControllerWithTitle:host.name message:@"" preferredStyle:UIAlertControllerStyleActionSheet];
if (!host.online) {
NSString* message;
switch (host.state) {
case StateOffline:
message = @"Offline";
break;
case StateOnline:
if (host.pairState == PairStatePaired) {
message = @"Online - Paired";
}
else {
message = @"Online - Not Paired";
}
break;
case StateUnknown:
message = @"Connecting";
break;
default:
break;
}
UIAlertController* longClickAlert = [UIAlertController alertControllerWithTitle:host.name message:message preferredStyle:UIAlertControllerStyleActionSheet];
if (host.state != StateOnline) {
[longClickAlert addAction:[UIAlertAction actionWithTitle:@"Wake" style:UIAlertActionStyleDefault handler:^(UIAlertAction* action){
UIAlertController* wolAlert = [UIAlertController alertControllerWithTitle:@"Wake On LAN" message:@"" preferredStyle:UIAlertControllerStyleAlert];
[wolAlert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]];
@@ -879,7 +903,7 @@ static NSMutableSet* hostList;
dispatch_async(dispatch_get_main_queue(), ^{
Log(LOG_D, @"New host list:");
for (TemporaryHost* host in hosts) {
Log(LOG_D, @"Host: \n{\n\t name:%@ \n\t address:%@ \n\t localAddress:%@ \n\t externalAddress:%@ \n\t ipv6Address:%@ \n\t uuid:%@ \n\t mac:%@ \n\t pairState:%d \n\t online:%d \n\t activeAddress:%@ \n}", host.name, host.address, host.localAddress, host.externalAddress, host.ipv6Address, host.uuid, host.mac, host.pairState, host.online, host.activeAddress);
Log(LOG_D, @"Host: \n{\n\t name:%@ \n\t address:%@ \n\t localAddress:%@ \n\t externalAddress:%@ \n\t ipv6Address:%@ \n\t uuid:%@ \n\t mac:%@ \n\t pairState:%d \n\t online:%d \n\t activeAddress:%@ \n}", host.name, host.address, host.localAddress, host.externalAddress, host.ipv6Address, host.uuid, host.mac, host.pairState, host.state, host.activeAddress);
}
@synchronized(hostList) {
[hostList removeAllObjects];