mirror of
https://github.com/moonlight-stream/moonlight-ios.git
synced 2026-06-17 22:23:52 +00:00
Use more aggressive mDNS querying for faster PC discovery, particularly in newly online PC scenarios
This commit is contained in:
@@ -162,15 +162,15 @@
|
|||||||
- (void)updateHost:(TemporaryHost*)host {
|
- (void)updateHost:(TemporaryHost*)host {
|
||||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||||
// Discover the hosts before adding to eliminate duplicates
|
// Discover the hosts before adding to eliminate duplicates
|
||||||
Log(LOG_I, @"Found host through MDNS: %@:", host.name);
|
Log(LOG_D, @"Found host through MDNS: %@:", host.name);
|
||||||
// Since this is on a background thread, we do not need to use the opQueue
|
// Since this is on a background thread, we do not need to use the opQueue
|
||||||
DiscoveryWorker* worker = (DiscoveryWorker*)[self createWorkerForHost:host];
|
DiscoveryWorker* worker = (DiscoveryWorker*)[self createWorkerForHost:host];
|
||||||
[worker discoverHost];
|
[worker discoverHost];
|
||||||
if ([self addHostToDiscovery:host]) {
|
if ([self addHostToDiscovery:host]) {
|
||||||
Log(LOG_D, @"Adding host to discovery: %@", host.name);
|
Log(LOG_I, @"Found new host through MDNS: %@:", host.name);
|
||||||
[self->_callback updateAllHosts:self->_hostQueue];
|
[self->_callback updateAllHosts:self->_hostQueue];
|
||||||
} else {
|
} else {
|
||||||
Log(LOG_D, @"Not adding host to discovery: %@", host.name);
|
Log(LOG_D, @"Found existing host through MDNS: %@", host.name);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
NSNetServiceBrowser* mDNSBrowser;
|
NSNetServiceBrowser* mDNSBrowser;
|
||||||
NSMutableArray* services;
|
NSMutableArray* services;
|
||||||
BOOL scanActive;
|
BOOL scanActive;
|
||||||
|
BOOL timerPending;
|
||||||
}
|
}
|
||||||
|
|
||||||
static NSString* NV_SERVICE_TYPE = @"_nvstream._tcp";
|
static NSString* NV_SERVICE_TYPE = @"_nvstream._tcp";
|
||||||
@@ -39,7 +40,13 @@ static NSString* NV_SERVICE_TYPE = @"_nvstream._tcp";
|
|||||||
|
|
||||||
Log(LOG_I, @"Starting mDNS discovery");
|
Log(LOG_I, @"Starting mDNS discovery");
|
||||||
scanActive = TRUE;
|
scanActive = TRUE;
|
||||||
[mDNSBrowser searchForServicesOfType:NV_SERVICE_TYPE inDomain:@""];
|
|
||||||
|
if (!timerPending) {
|
||||||
|
timerPending = TRUE;
|
||||||
|
|
||||||
|
// Just invoke the timer callback to save a little code
|
||||||
|
[self startSearchTimerCallback:nil];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) stopSearching {
|
- (void) stopSearching {
|
||||||
@@ -73,11 +80,13 @@ static NSString* NV_SERVICE_TYPE = @"_nvstream._tcp";
|
|||||||
|
|
||||||
- (void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser didFindService:(NSNetService *)aNetService moreComing:(BOOL)moreComing {
|
- (void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser didFindService:(NSNetService *)aNetService moreComing:(BOOL)moreComing {
|
||||||
Log(LOG_D, @"Found service: %@", aNetService);
|
Log(LOG_D, @"Found service: %@", aNetService);
|
||||||
[aNetService setDelegate:self];
|
|
||||||
[aNetService resolveWithTimeout:5];
|
|
||||||
|
|
||||||
[services removeObject:aNetService];
|
if (![services containsObject:aNetService]) {
|
||||||
[services addObject:aNetService];
|
Log(LOG_I, @"Found new host: %@", aNetService.name);
|
||||||
|
[aNetService setDelegate:self];
|
||||||
|
[aNetService resolveWithTimeout:5];
|
||||||
|
[services addObject:aNetService];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser didRemoveService:(NSNetService *)aNetService moreComing:(BOOL)moreComing {
|
- (void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser didRemoveService:(NSNetService *)aNetService moreComing:(BOOL)moreComing {
|
||||||
@@ -88,23 +97,29 @@ static NSString* NV_SERVICE_TYPE = @"_nvstream._tcp";
|
|||||||
- (void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser didNotSearch:(NSDictionary *)errorDict {
|
- (void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser didNotSearch:(NSDictionary *)errorDict {
|
||||||
Log(LOG_W, @"Did not perform search: \n%@", [errorDict description]);
|
Log(LOG_W, @"Did not perform search: \n%@", [errorDict description]);
|
||||||
|
|
||||||
// Schedule a retry in 2 seconds
|
// We'll schedule a retry in startSearchTimerCallback
|
||||||
[NSTimer scheduledTimerWithTimeInterval:2.0
|
|
||||||
target:self
|
|
||||||
selector:@selector(retrySearchTimerCallback:)
|
|
||||||
userInfo:nil
|
|
||||||
repeats:NO];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)retrySearchTimerCallback:(NSTimer *)timer {
|
- (void)startSearchTimerCallback:(NSTimer *)timer {
|
||||||
// Check if we've been stopped since this was queued
|
// Check if we've been stopped since this was queued
|
||||||
if (!scanActive) {
|
if (!scanActive) {
|
||||||
|
timerPending = FALSE;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log(LOG_I, @"Retrying mDNS search");
|
Log(LOG_D, @"Restarting mDNS search");
|
||||||
[mDNSBrowser stop];
|
[mDNSBrowser stop];
|
||||||
[mDNSBrowser searchForServicesOfType:NV_SERVICE_TYPE inDomain:@""];
|
[mDNSBrowser searchForServicesOfType:NV_SERVICE_TYPE inDomain:@""];
|
||||||
|
|
||||||
|
// Search again in 5 seconds. We need to do this because
|
||||||
|
// we want more aggressive querying than Bonjour will normally
|
||||||
|
// do for when we're at the hosts screen. This also covers scenarios
|
||||||
|
// where discovery didn't work, like if WiFi was disabled.
|
||||||
|
[NSTimer scheduledTimerWithTimeInterval:5.0
|
||||||
|
target:self
|
||||||
|
selector:@selector(startSearchTimerCallback:)
|
||||||
|
userInfo:nil
|
||||||
|
repeats:NO];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)retryResolveTimerCallback:(NSTimer *)timer {
|
- (void)retryResolveTimerCallback:(NSTimer *)timer {
|
||||||
|
|||||||
Reference in New Issue
Block a user