Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added possibility to connect only to a specified Bonjour service name
  • Loading branch information
jeanregisser committed Oct 13, 2012
1 parent 0b9510d commit 74419cb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
4 changes: 3 additions & 1 deletion Examples/PDTwitterTest/PDTwitterTest/PDAppDelegate.m
Expand Up @@ -48,7 +48,9 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(

// Auto connect via bonjour discovery
[debugger autoConnect];
// Or connect on launch.
// Or to a specific ponyd bonjour service
//[debugger autoConnectToBonjourServiceNamed:@"MY PONY"];
// Or connect to a specific host
//[debugger connectToURL:[NSURL URLWithString:@"ws://localhost:9000/device"]];

#endif
Expand Down
5 changes: 4 additions & 1 deletion ObjC/PonyDebugger/PDDebugger.h
Expand Up @@ -25,7 +25,10 @@
- (void)sendEventWithName:(NSString *)string parameters:(id)params;

// Connect/Disconnect
- (void)autoConnect;
- (void)autoConnect; // Connect to any ponyd service found via Bonjour
// Only connect to the specified Bonjour service name, this makes things easier in a teamwork
// environment where multiple instances of ponyd may run on the same network
- (void)autoConnectToBonjourServiceNamed:(NSString*)serviceName;
- (void)connectToURL:(NSURL *)url;
- (BOOL)isConnected;
- (void)disconnect;
Expand Down
20 changes: 19 additions & 1 deletion ObjC/PonyDebugger/PDDebugger.m
Expand Up @@ -38,6 +38,7 @@ - (BOOL)_isTrackingDomainController:(PDDomainController *)controller;


@implementation PDDebugger {
NSString *_bonjourServiceName;
NSNetServiceBrowser *_bonjourBrowser;
NSMutableArray *_bonjourServices;
NSNetService *_currentService;
Expand Down Expand Up @@ -185,6 +186,12 @@ - (void)webSocket:(SRWebSocket *)webSocket didFailWithError:(NSError *)error;

- (void)netServiceBrowser:(NSNetServiceBrowser*)netServiceBrowser didFindService:(NSNetService*)service moreComing:(BOOL)moreComing
{
if (_bonjourServiceName
&& NSOrderedSame != [_bonjourServiceName compare:service.name
options:NSCaseInsensitiveSearch | NSNumericSearch | NSDiacriticInsensitiveSearch]) {
return;
}

NSLog(@"Found ponyd bonjour service: %@", service);
[_bonjourServices addObject:service];

Expand Down Expand Up @@ -260,16 +267,27 @@ - (void)sendEventWithName:(NSString *)methodName parameters:(id)params;
#pragma mark Connect / Disconnect

- (void)autoConnect
{
// Connect to any bonjour service
[self autoConnectToBonjourServiceNamed:nil];
}

- (void)autoConnectToBonjourServiceNamed:(NSString*)serviceName
{
if (_bonjourBrowser) {
return;
}

_bonjourServiceName = serviceName;
_bonjourServices = [NSMutableArray array];
_bonjourBrowser = [[NSNetServiceBrowser alloc] init];
[_bonjourBrowser setDelegate:self];

NSLog(@"Waiting for ponyd bonjour service...");
if (_bonjourServiceName) {
NSLog(@"Waiting for ponyd bonjour service '%@'...", _bonjourServiceName);
} else {
NSLog(@"Waiting for ponyd bonjour service...");
}
[_bonjourBrowser searchForServicesOfType:PDBonjourServiceType inDomain:@""];
}

Expand Down

0 comments on commit 74419cb

Please sign in to comment.