mirror of
https://github.com/moonlight-stream/moonlight-ios.git
synced 2026-06-15 21:21:45 +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 "MDNSManager.h"
|
||||||
#import "Computer.h"
|
#import "Computer.h"
|
||||||
|
|
||||||
@implementation MDNSManager : NSObject
|
@implementation MDNSManager {
|
||||||
NSNetServiceBrowser* mDNSBrowser;
|
NSNetServiceBrowser* mDNSBrowser;
|
||||||
NSMutableArray* domains;
|
NSMutableArray* domains;
|
||||||
NSMutableArray* services;
|
NSMutableArray* services;
|
||||||
|
BOOL scanActive;
|
||||||
|
}
|
||||||
|
|
||||||
static NSString* NV_SERVICE_TYPE = @"_nvstream._tcp";
|
static NSString* NV_SERVICE_TYPE = @"_nvstream._tcp";
|
||||||
|
|
||||||
@@ -32,11 +34,13 @@ static NSString* NV_SERVICE_TYPE = @"_nvstream._tcp";
|
|||||||
|
|
||||||
- (void) searchForHosts {
|
- (void) searchForHosts {
|
||||||
NSLog(@"Starting mDNS discovery");
|
NSLog(@"Starting mDNS discovery");
|
||||||
|
scanActive = TRUE;
|
||||||
[mDNSBrowser searchForServicesOfType:NV_SERVICE_TYPE inDomain:@""];
|
[mDNSBrowser searchForServicesOfType:NV_SERVICE_TYPE inDomain:@""];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) stopSearching {
|
- (void) stopSearching {
|
||||||
NSLog(@"Stopping mDNS discovery");
|
NSLog(@"Stopping mDNS discovery");
|
||||||
|
scanActive = FALSE;
|
||||||
[mDNSBrowser stop];
|
[mDNSBrowser stop];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,7 +51,7 @@ static NSString* NV_SERVICE_TYPE = @"_nvstream._tcp";
|
|||||||
[hosts addObject:[[Computer alloc] initWithHost:service]];
|
[hosts addObject:[[Computer alloc] initWithHost:service]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return [[NSArray alloc] initWithArray:hosts];
|
return hosts;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)netServiceDidResolveAddress:(NSNetService *)service {
|
- (void)netServiceDidResolveAddress:(NSNetService *)service {
|
||||||
@@ -74,6 +78,24 @@ static NSString* NV_SERVICE_TYPE = @"_nvstream._tcp";
|
|||||||
- (void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser didNotSearch:(NSDictionary *)errorDict {
|
- (void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser didNotSearch:(NSDictionary *)errorDict {
|
||||||
NSLog(@"Did not perform search");
|
NSLog(@"Did not perform search");
|
||||||
NSLog(@"%@", [errorDict description]);
|
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
|
@end
|
||||||
@@ -15,5 +15,6 @@
|
|||||||
|
|
||||||
- (id) initWithHost:(NSNetService*)host;
|
- (id) initWithHost:(NSNetService*)host;
|
||||||
- (id) initWithIp:(NSString*)host;
|
- (id) initWithIp:(NSString*)host;
|
||||||
|
- (id) initPlaceholder;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -28,4 +28,13 @@
|
|||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (id) initPlaceholder {
|
||||||
|
self = [super init];
|
||||||
|
|
||||||
|
self.hostName = NULL;
|
||||||
|
self.displayName = @"No computers found";
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@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
|
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
|
||||||
{
|
{
|
||||||
if (pickerView == self.HostPicker) {
|
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!!
|
//TODO: figure out how to save this info!!
|
||||||
@@ -154,10 +163,12 @@ static StreamConfiguration* streamConfig;
|
|||||||
[super viewDidLoad];
|
[super viewDidLoad];
|
||||||
|
|
||||||
self.streamConfigVals = [[NSArray alloc] initWithObjects:@"1280x720 (30Hz)", @"1280x720 (60Hz)", @"1920x1080 (30Hz)", @"1920x1080 (60Hz)",nil];
|
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];
|
[self.StreamConfigs selectRow:1 inComponent:0 animated:NO];
|
||||||
|
|
||||||
_opQueue = [[NSOperationQueue alloc] init];
|
_opQueue = [[NSOperationQueue alloc] init];
|
||||||
|
|
||||||
|
// Initialize the host picker list
|
||||||
|
[self updateHosts:[[NSArray alloc] init]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)viewDidAppear:(BOOL)animated
|
- (void)viewDidAppear:(BOOL)animated
|
||||||
@@ -172,9 +183,16 @@ static StreamConfiguration* streamConfig;
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)updateHosts:(NSArray *)hosts {
|
- (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];
|
[self.HostPicker reloadAllComponents];
|
||||||
_selectedHost = (Computer*)([self.hostPickerVals objectAtIndex:[self.HostPicker selectedRowInComponent:0]]);
|
|
||||||
|
[self setSelectedHost:[self.HostPicker selectedRowInComponent:0]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)didReceiveMemoryWarning
|
- (void)didReceiveMemoryWarning
|
||||||
|
|||||||
Reference in New Issue
Block a user