Skip to content
This repository has been archived by the owner on Feb 9, 2018. It is now read-only.

Commit

Permalink
added stop functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Roth committed Jan 22, 2011
1 parent d961e48 commit 6ef17d4
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 59 deletions.
11 changes: 10 additions & 1 deletion AirPresent/AirPresent/UIApplication+AirPresent.m
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,20 @@ - (void) start
airplay.delegate = self;
}

[airplay findDevices];
if(!airplay.connectedDevice)
{
[airplay findDevices];
}
else
{
[self manager:airplay didConnectToDevice:airplay.connectedDevice];
}
}

- (void) stop
{
[airplay.connectedDevice sendStop];

if(runTimer)
{
[runTimer invalidate];
Expand Down
23 changes: 5 additions & 18 deletions AirPresent/Classes/AirPresentAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,40 +32,27 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(


- (void)applicationWillResignActive:(UIApplication *)application {
/*
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
*/
[[UIApplication sharedApplication] endPresentingScreen];
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
/*
Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
*/
//[[UIApplication sharedApplication] endPresentingScreen];
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
/*
Called as part of transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
*/
//[[UIApplication sharedApplication] beginPresentingScreen];
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
/*
Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
*/
[[UIApplication sharedApplication] beginPresentingScreen];
}


- (void)applicationWillTerminate:(UIApplication *)application {
/*
Called when the application is about to terminate.
See also applicationDidEnterBackground:.
*/
[[UIApplication sharedApplication] endPresentingScreen];
}


Expand Down
2 changes: 1 addition & 1 deletion MacOS/AirplayKit/AKAirplayManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ - (void)onSocket:(AsyncSocket *)sock didConnectToHost:(NSString *)host port:(UIn

- (void) dealloc
{
[connectedDevice dealloc];
[connectedDevice release];
[foundServices removeAllObjects];
[foundServices release];

Expand Down
1 change: 1 addition & 0 deletions MacOS/AirplayKit/AKDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@
- (void) sendRawMessage:(NSString *)message; // Sends a raw HTTP string over Airplay.
- (void) sendContentURL:(NSString *)url;
- (void) sendImage:(NSImage *)image;
- (void) sendStop;

@end
21 changes: 8 additions & 13 deletions MacOS/AirplayKit/AKDevice.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,6 @@ - (void) sendRawMessage:(NSString *)message
[self.socket readDataWithTimeout:20.0 tag:1];
}

/*
- (void) sendReverse
{
NSString *message = @"POST /reverse HTTP/1.1\n"
"Content-Length: 0\n"
"User-Agent: MediaControl/1.0\n"
"Upgrade: PTTH/1.0\n"
"Connection: Upgrade\n\n";
[self sendRawMessage:message];
}
*/

- (void) sendContentURL:(NSString *)url
{
NSString *body = [[NSString alloc] initWithFormat:@"Content-Location: %@\n"
Expand Down Expand Up @@ -89,6 +76,13 @@ - (void) sendImage:(NSImage *)image
[self.socket readDataWithTimeout:20.0 tag:1];
}

- (void) sendStop
{
NSString *message = @"POST /stop HTTP/1.1\n"
"User-Agent: MediaControl/1.0\n\n%@";
[self sendRawMessage:message];
}

#pragma mark -
#pragma mark Socket Delegate

Expand All @@ -103,6 +97,7 @@ - (void)onSocket:(AsyncSocket *)sock didReadData:(NSData *)data withTag:(long)ta

- (void) dealloc
{
[self sendStop];
[socket release];
[hostname release];
[super dealloc];
Expand Down
13 changes: 8 additions & 5 deletions iOS/AirplayKit/AKAirplayManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@ - (void) connectToDevice:(AKDevice *)device
{
NSLog(@"Connecting to device : %@:%d", device.hostname, device.port);

tempDevice = [device retain];

AsyncSocket *socket = [[AsyncSocket alloc] initWithDelegate:self];
[socket connectToHost:device.hostname onPort:device.port error:NULL];
if(!tempDevice)
{
tempDevice = [device retain];

AsyncSocket *socket = [[AsyncSocket alloc] initWithDelegate:self];
[socket connectToHost:device.hostname onPort:device.port error:NULL];
}
}

#pragma mark -
Expand Down Expand Up @@ -115,7 +118,7 @@ - (void)onSocket:(AsyncSocket *)sock didConnectToHost:(NSString *)host port:(UIn

- (void) dealloc
{
[connectedDevice dealloc];
[connectedDevice release];
[foundServices removeAllObjects];
[foundServices release];

Expand Down
1 change: 1 addition & 0 deletions iOS/AirplayKit/AKDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@
- (void) sendRawMessage:(NSString *)message; // Sends a raw HTTP string over Airplay.
- (void) sendContentURL:(NSString *)url;
- (void) sendImage:(UIImage *)image;
- (void) sendStop;

@end
21 changes: 8 additions & 13 deletions iOS/AirplayKit/AKDevice.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,6 @@ - (void) sendRawMessage:(NSString *)message
[self.socket readDataWithTimeout:20.0 tag:1];
}

/*
- (void) sendReverse
{
NSString *message = @"POST /reverse HTTP/1.1\n"
"Content-Length: 0\n"
"User-Agent: MediaControl/1.0\n"
"Upgrade: PTTH/1.0\n"
"Connection: Upgrade\n\n";
[self sendRawMessage:message];
}
*/

- (void) sendContentURL:(NSString *)url
{
NSString *body = [[NSString alloc] initWithFormat:@"Content-Location: %@\n"
Expand Down Expand Up @@ -89,6 +76,13 @@ - (void) sendImage:(UIImage *)image
[self.socket readDataWithTimeout:20.0 tag:1];
}

- (void) sendStop
{
NSString *message = @"POST /stop HTTP/1.1\n"
"User-Agent: MediaControl/1.0\n\n%@";
[self sendRawMessage:message];
}

#pragma mark -
#pragma mark Socket Delegate

Expand All @@ -103,6 +97,7 @@ - (void)onSocket:(AsyncSocket *)sock didReadData:(NSData *)data withTag:(long)ta

- (void) dealloc
{
[self sendStop];
[socket release];
[hostname release];
[super dealloc];
Expand Down
10 changes: 2 additions & 8 deletions iOS/iPhone/AppDelegate_iPhone.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ - (void)applicationWillResignActive:(UIApplication *)application {


- (void)applicationDidEnterBackground:(UIApplication *)application {
/*
Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
*/
[manager.connectedDevice sendStop];
}


Expand All @@ -75,10 +72,7 @@ Restart any tasks that were paused (or not yet started) while the application wa


- (void)applicationWillTerminate:(UIApplication *)application {
/*
Called when the application is about to terminate.
See also applicationDidEnterBackground:.
*/
[manager.connectedDevice sendStop];
}


Expand Down

0 comments on commit 6ef17d4

Please sign in to comment.