mirror of
https://github.com/moonlight-stream/moonlight-ios.git
synced 2026-02-16 10:31:02 +00:00
Add a placeholder in the computer list if none are found. Retry service discovery if it fails.
This commit is contained in:
@@ -9,10 +9,12 @@
|
||||
#import "MDNSManager.h"
|
||||
#import "Computer.h"
|
||||
|
||||
@implementation MDNSManager : NSObject
|
||||
NSNetServiceBrowser* mDNSBrowser;
|
||||
NSMutableArray* domains;
|
||||
NSMutableArray* services;
|
||||
@implementation MDNSManager {
|
||||
NSNetServiceBrowser* mDNSBrowser;
|
||||
NSMutableArray* domains;
|
||||
NSMutableArray* services;
|
||||
BOOL scanActive;
|
||||
}
|
||||
|
||||
static NSString* NV_SERVICE_TYPE = @"_nvstream._tcp";
|
||||
|
||||
@@ -32,11 +34,13 @@ static NSString* NV_SERVICE_TYPE = @"_nvstream._tcp";
|
||||
|
||||
- (void) searchForHosts {
|
||||
NSLog(@"Starting mDNS discovery");
|
||||
scanActive = TRUE;
|
||||
[mDNSBrowser searchForServicesOfType:NV_SERVICE_TYPE inDomain:@""];
|
||||
}
|
||||
|
||||
- (void) stopSearching {
|
||||
NSLog(@"Stopping mDNS discovery");
|
||||
scanActive = FALSE;
|
||||
[mDNSBrowser stop];
|
||||
}
|
||||
|
||||
@@ -47,7 +51,7 @@ static NSString* NV_SERVICE_TYPE = @"_nvstream._tcp";
|
||||
[hosts addObject:[[Computer alloc] initWithHost:service]];
|
||||
}
|
||||
}
|
||||
return [[NSArray alloc] initWithArray:hosts];
|
||||
return hosts;
|
||||
}
|
||||
|
||||
- (void)netServiceDidResolveAddress:(NSNetService *)service {
|
||||
@@ -74,6 +78,24 @@ static NSString* NV_SERVICE_TYPE = @"_nvstream._tcp";
|
||||
- (void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser didNotSearch:(NSDictionary *)errorDict {
|
||||
NSLog(@"Did not perform search");
|
||||
NSLog(@"%@", [errorDict description]);
|
||||
|
||||
// Schedule a retry in 2 seconds
|
||||
[NSTimer scheduledTimerWithTimeInterval:2.0
|
||||
target:self
|
||||
selector:@selector(retryTimerCallback:)
|
||||
userInfo:nil
|
||||
repeats:NO];
|
||||
}
|
||||
|
||||
- (void)retryTimerCallback:(NSTimer *)timer {
|
||||
// Check if we've been stopped since this was queued
|
||||
if (!scanActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
NSLog(@"Retrying mDNS search");
|
||||
[mDNSBrowser stop];
|
||||
[mDNSBrowser searchForServicesOfType:NV_SERVICE_TYPE inDomain:@""];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -15,5 +15,6 @@
|
||||
|
||||
- (id) initWithHost:(NSNetService*)host;
|
||||
- (id) initWithIp:(NSString*)host;
|
||||
- (id) initPlaceholder;
|
||||
|
||||
@end
|
||||
|
||||
@@ -28,4 +28,13 @@
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id) initPlaceholder {
|
||||
self = [super init];
|
||||
|
||||
self.hostName = NULL;
|
||||
self.displayName = @"No computers found";
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -122,10 +122,19 @@ static StreamConfiguration* streamConfig;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setSelectedHost:(NSInteger)selectedIndex
|
||||
{
|
||||
_selectedHost = (Computer*)([self.hostPickerVals objectAtIndex:selectedIndex]);
|
||||
if (_selectedHost.hostName == NULL) {
|
||||
// This must be the placeholder computer
|
||||
_selectedHost = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
|
||||
{
|
||||
if (pickerView == self.HostPicker) {
|
||||
_selectedHost = (Computer*)([self.hostPickerVals objectAtIndex:[self.HostPicker selectedRowInComponent:0]]);
|
||||
[self setSelectedHost:[self.HostPicker selectedRowInComponent:0]];
|
||||
}
|
||||
|
||||
//TODO: figure out how to save this info!!
|
||||
@@ -154,10 +163,12 @@ static StreamConfiguration* streamConfig;
|
||||
[super viewDidLoad];
|
||||
|
||||
self.streamConfigVals = [[NSArray alloc] initWithObjects:@"1280x720 (30Hz)", @"1280x720 (60Hz)", @"1920x1080 (30Hz)", @"1920x1080 (60Hz)",nil];
|
||||
self.hostPickerVals = [[NSArray alloc] init];
|
||||
[self.StreamConfigs selectRow:1 inComponent:0 animated:NO];
|
||||
|
||||
_opQueue = [[NSOperationQueue alloc] init];
|
||||
|
||||
// Initialize the host picker list
|
||||
[self updateHosts:[[NSArray alloc] init]];
|
||||
}
|
||||
|
||||
- (void)viewDidAppear:(BOOL)animated
|
||||
@@ -172,9 +183,16 @@ static StreamConfiguration* streamConfig;
|
||||
}
|
||||
|
||||
- (void)updateHosts:(NSArray *)hosts {
|
||||
self.hostPickerVals = hosts;
|
||||
NSMutableArray *hostPickerValues = [[NSMutableArray alloc] initWithArray:hosts];
|
||||
|
||||
if ([hostPickerValues count] == 0) {
|
||||
[hostPickerValues addObject:[[Computer alloc] initPlaceholder]];
|
||||
}
|
||||
|
||||
self.hostPickerVals = hostPickerValues;
|
||||
[self.HostPicker reloadAllComponents];
|
||||
_selectedHost = (Computer*)([self.hostPickerVals objectAtIndex:[self.HostPicker selectedRowInComponent:0]]);
|
||||
|
||||
[self setSelectedHost:[self.HostPicker selectedRowInComponent:0]];
|
||||
}
|
||||
|
||||
- (void)didReceiveMemoryWarning
|
||||
|
||||
Reference in New Issue
Block a user