This repository has been archived by the owner on Oct 5, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First version of the Bonjour-enabled discovery service via wifi
- Loading branch information
Adrian Kosmaczewski
committed
May 21, 2011
1 parent
38bfc37
commit f9b47e6
Showing
10 changed files
with
654 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// | ||
// PeerBrowser.h | ||
// bluewoki | ||
// | ||
// Created by Adrian on 5/21/11. | ||
// Copyright 2011 akosma software. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@class PeerProxy; | ||
|
||
@interface PeerBrowser : NSObject <NSNetServiceBrowserDelegate> | ||
|
||
@property (nonatomic, retain) NSMutableArray *peerArray; | ||
@property (nonatomic, retain) NSNetServiceBrowser *peerBrowser; | ||
|
||
- (void)startSearchingForPeers; | ||
- (void)stopSearchingForPeers; | ||
- (NSInteger)connectedPeersCount; | ||
- (PeerProxy *)peerAtIndex:(NSUInteger)index; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
// | ||
// PeerBrowser.m | ||
// bluewoki | ||
// | ||
// Created by Adrian on 5/21/11. | ||
// Copyright 2011 akosma software. All rights reserved. | ||
// | ||
|
||
#import "PeerBrowser.h" | ||
#import "Protocol.h" | ||
#import "PeerProxy.h" | ||
|
||
|
||
@implementation PeerBrowser | ||
|
||
@synthesize peerArray = _peerArray; | ||
@synthesize peerBrowser = _peerBrowser; | ||
|
||
- (id)init | ||
{ | ||
self = [super init]; | ||
if (self) | ||
{ | ||
_peerArray = [[NSMutableArray alloc] init]; | ||
} | ||
return self; | ||
} | ||
|
||
- (void)dealloc | ||
{ | ||
[self stopSearchingForPeers]; | ||
|
||
[_peerArray release]; | ||
|
||
[super dealloc]; | ||
} | ||
|
||
#pragma mark - Public methods | ||
|
||
- (NSInteger)connectedPeersCount | ||
{ | ||
return [self.peerArray count]; | ||
} | ||
|
||
- (void)startSearchingForPeers | ||
{ | ||
self.peerBrowser = [[[NSNetServiceBrowser alloc] init] autorelease]; | ||
[self.peerBrowser setDelegate:self]; | ||
[self.peerBrowser searchForServicesOfType:BLUEWOKI_PROTOCOL_NAME | ||
inDomain:@""]; | ||
} | ||
|
||
- (void)stopSearchingForPeers | ||
{ | ||
[self.peerBrowser stop]; | ||
self.peerBrowser = nil; | ||
} | ||
|
||
- (PeerProxy *)peerAtIndex:(NSUInteger)index | ||
{ | ||
return [self.peerArray objectAtIndex:index]; | ||
} | ||
|
||
#pragma mark - NSNetServiceBrowser delegate methods | ||
|
||
- (void)netServiceBrowser:(NSNetServiceBrowser *)browser | ||
didFindService:(NSNetService *)service | ||
moreComing:(BOOL)more | ||
{ | ||
if (!more) | ||
{ | ||
PeerProxy *peer = [PeerProxy proxyWithService:service]; | ||
[peer connect]; | ||
[self.peerArray addObject:peer]; | ||
|
||
[[NSNotificationCenter defaultCenter] postNotificationName:@"UPDATE_SCREEN" object:self]; | ||
} | ||
} | ||
|
||
- (void)netServiceBrowser:(NSNetServiceBrowser *)browser | ||
didRemoveService:(NSNetService *)service | ||
moreComing:(BOOL)more | ||
{ | ||
if (!more) | ||
{ | ||
PeerProxy *peerToRemove = nil; | ||
for (PeerProxy *proxy in self.peerArray) | ||
{ | ||
if ([proxy.serviceName isEqualToString:[service name]]) | ||
{ | ||
peerToRemove = proxy; | ||
} | ||
} | ||
|
||
if (peerToRemove != nil) | ||
{ | ||
[self.peerArray removeObject:peerToRemove]; | ||
} | ||
|
||
[[NSNotificationCenter defaultCenter] postNotificationName:@"UPDATE_SCREEN" object:self]; | ||
} | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// | ||
// PeerProxy.h | ||
// bluewoki | ||
// | ||
// Created by Adrian on 5/21/11. | ||
// Copyright 2011 akosma software. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import <GameKit/GameKit.h> | ||
#import <AVFoundation/AVFoundation.h> | ||
#import <AudioToolbox/AudioToolbox.h> | ||
#import "MessageBrokerDelegate.h" | ||
#import "PeerProxyDelegate.h" | ||
|
||
@interface PeerProxy : NSObject <NSNetServiceDelegate, | ||
MessageBrokerDelegate, | ||
GKPeerPickerControllerDelegate, | ||
GKSessionDelegate, | ||
GKVoiceChatClient> | ||
|
||
@property (nonatomic, retain) NSNetService *netService; | ||
@property (nonatomic, retain) GKSession *chatSession; | ||
@property (nonatomic, getter = isConnected) BOOL connected; | ||
@property (nonatomic, retain) MessageBroker *messageBroker; | ||
@property (nonatomic, assign) id<PeerProxyDelegate> delegate; | ||
@property (nonatomic, readonly) NSString *serviceName; | ||
|
||
+ (id)proxyWithService:(NSNetService *)service; | ||
- (id)initWithService:(NSNetService *)service; | ||
- (void)connect; | ||
- (void)startService; | ||
- (void)stopService; | ||
- (void)sendVoiceCallRequest; | ||
- (void)answerToCallFromPeerID:(NSString *)peerID; | ||
|
||
@end |
Oops, something went wrong.