Permalink
Browse files

Clean up uses of libPusher.

This removes all uses of pusher, leaving some commented in handling
code so we don't need to re-write it later.
  • Loading branch information...
1 parent 509a803 commit ac68ffa7f1612cf4dbc063d10763bb184bade44b Danny Greg committed Jan 17, 2013
Showing with 85 additions and 141 deletions.
  1. +1 −12 Play Client/PLAController.h
  2. +83 −128 Play Client/PLAController.m
  3. +1 −1 Play Item/Classes/Controllers/PLAQueueWindowController.m
@@ -7,39 +7,28 @@
//
#import <Foundation/Foundation.h>
-#import "PTPusher.h"
extern NSString *const PLANowPlayingUpdated;
@class PLATrack;
-@interface PLAController : NSObject <PTPusherDelegate>{
+@interface PLAController : NSObject {
NSArray *queuedTracks;
PLATrack *currentlyPlayingTrack;
- PTPusher *pusherClient;
- NSString *pusherKey;
NSString *streamUrl;
- PTPusherEventBinding *updateNowPlayingPusherChannelBinding;
}
@property (nonatomic, retain) NSArray *queuedTracks;
@property (nonatomic, retain) PLATrack *currentlyPlayingTrack;
-@property (nonatomic, retain) PTPusher *pusherClient;
-@property (nonatomic, retain) PTPusherEventBinding *updateNowPlayingPusherChannelBinding;
@property (nonatomic, retain) NSString *streamUrl;
-@property (nonatomic, retain) NSString *pusherKey;
+ (PLAController *)sharedController;
- (void)logInWithBlock:(void(^)(BOOL succeeded))block;
-- (PTPusherChannel *)nowPlayingPusherChannel;
-- (void)setUpPusher;
-- (void)subscribeToChannels;
- (void)setPlayUrl:(NSString *)url;
- (NSString *)playUrl;
- (void)setAuthToken:(NSString *)token;
- (NSString *)authToken;
- (void)updateNowPlaying:(NSDictionary *)nowPlayingDict;
-- (void)channelEventPushed:(PTPusherEvent *)channelEvent;
@end
View
@@ -10,7 +10,6 @@
#import "PLAPlayClient.h"
#import "PLATrack.h"
-#import "PTPusherChannel.h"
#if TARGET_OS_EMBEDDED
#import "Reachability.h"
@@ -20,15 +19,12 @@
@implementation PLAController
-@synthesize queuedTracks, currentlyPlayingTrack, pusherClient, updateNowPlayingPusherChannelBinding, streamUrl, pusherKey;
+@synthesize queuedTracks, currentlyPlayingTrack, streamUrl;
- (void) dealloc{
[queuedTracks release];
[currentlyPlayingTrack release];
- [pusherClient release];
- [updateNowPlayingPusherChannelBinding release];
[streamUrl release];
- [pusherKey release];
[super dealloc];
}
@@ -55,9 +51,6 @@ - (id)init {
- (void)logInWithBlock:(void(^)(BOOL succeeded))block{
[[PLAPlayClient sharedClient] getPath:@"/streaming_info" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
self.streamUrl = [responseObject objectForKey:@"stream_url"];
- self.pusherKey = [responseObject objectForKey:@"pusher_key"];
-
- [self setUpPusher];
[self subscribeToChannels];
if (block != nil)
@@ -70,44 +63,6 @@ - (void)logInWithBlock:(void(^)(BOOL succeeded))block{
}
-#pragma mark - Pusher Bootstrap
-
-- (PTPusherChannel *)nowPlayingPusherChannel{
- if (pusherClient) {
- return [pusherClient subscribeToChannelNamed:@"now_playing_updates"];
- }
-
- return nil;
-}
-
-- (void)setUpPusher{
- if (pusherClient) {
- NSLog(@"destroying pusherClient to be ready to create a new one");
- PTPusherChannel *channel = [self nowPlayingPusherChannel];
- [channel removeBinding:updateNowPlayingPusherChannelBinding];
- self.updateNowPlayingPusherChannelBinding = nil;
-
- [self.pusherClient setDelegate:nil];
- [self.pusherClient unsubscribeFromChannel:channel];
- [self.pusherClient setReconnectAutomatically:NO];
- [self.pusherClient disconnect];
- [self.pusherClient retain]; //intentional leak. For some when these object die they occasionally wreak havoc with a hard-as-shit crash.
- self.pusherClient = nil;
- }
-
- self.pusherClient = [PTPusher pusherWithKey:pusherKey delegate:self encrypted:NO];
- [pusherClient setReconnectAutomatically:YES];
- [pusherClient setReconnectDelay:30];
-}
-
-- (void)subscribeToChannels{
- if (pusherClient) {
- NSLog(@"subscribing to channels");
- PTPusherChannel *channel = [self nowPlayingPusherChannel];
- self.updateNowPlayingPusherChannelBinding = [channel bindToEventNamed:@"update_now_playing" target:self action:@selector(channelEventPushed:)];
- }
-}
-
#pragma mark - Settings
- (void)setPlayUrl:(NSString *)url{
@@ -148,91 +103,91 @@ - (void)updateNowPlaying:(NSDictionary *)nowPlayingDict{
#pragma mark - Channel Event handler
-- (void)channelEventPushed:(PTPusherEvent *)channelEvent{
- if ([[channelEvent name] isEqualToString:@"update_now_playing"]) {
- [self updateNowPlaying:(NSDictionary *)[channelEvent data]];
- }
-}
+//- (void)channelEventPushed:(PTPusherEvent *)channelEvent{
+// if ([[channelEvent name] isEqualToString:@"update_now_playing"]) {
+// [self updateNowPlaying:(NSDictionary *)[channelEvent data]];
+// }
+//}
#pragma mark - PTPusher Delegate Methods
-- (void)pusher:(PTPusher *)client connectionDidConnect:(PTPusherConnection *)connection{
- NSLog(@"connectionDidConnect");
- client.reconnectAutomatically = YES;
-}
-
-- (void)pusher:(PTPusher *)pusher didSubscribeToChannel:(PTPusherChannel *)channel {
- NSLog(@"did subscribe to channel: %@", [channel name]);
-}
-
-- (void)pusher:(PTPusher *)pusher didFailToSubscribeToChannel:(PTPusherChannel *)channel withError:(NSError *)error{
- NSLog(@"failed to subscribe: %@", error.description);
-}
-
-- (void)pusher:(PTPusher *)pusher didReceiveErrorEvent:(PTPusherErrorEvent *)errorEvent{
- NSLog(@"received error event: %@", errorEvent);
-}
-
-- (void)pusher:(PTPusher *)client connectionDidDisconnect:(PTPusherConnection *)connection{
- NSLog(@"connectionDidDisconnect");
-
-#if TARGET_OS_EMBEDDED
- Reachability *reachability = [Reachability reachabilityForInternetConnection];
-
- if ([reachability currentReachabilityStatus] == NotReachable) {
- NSLog(@"NotReachable");
- client.reconnectAutomatically = NO;
-
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object:reachability];
-
- [reachability startNotifier];
- }else{
- [PLATrack currentTrackWithBlock:^(PLATrack *track, NSError *error) {
- dispatch_async(dispatch_get_main_queue(), ^(void) {
- self.currentlyPlayingTrack = track;
- [[NSNotificationCenter defaultCenter] postNotificationName:PLANowPlayingUpdated object:nil];
- [self setUpPusher];
- [self subscribeToChannels];
- });
- }];
- }
-
-#else
- [PLATrack currentTrackWithBlock:^(PLATrack *track, NSError *err) {
- dispatch_async(dispatch_get_main_queue(), ^(void) {
- self.currentlyPlayingTrack = track;
- [[NSNotificationCenter defaultCenter] postNotificationName:PLANowPlayingUpdated object:nil];
- [self setUpPusher];
- [self subscribeToChannels];
- });
- }];
-
- [PLATrack currentQueueWithBlock:^(NSArray *tracks, NSError *err) {
- if (tracks != nil)
- self.queuedTracks = tracks;
- }];
-#endif
-}
-
-#if TARGET_OS_EMBEDDED
-- (void)reachabilityChanged:(NSNotification *)note{
- NSLog(@"reachabilityChanged");
- Reachability *reachability = note.object;
-
- if ([reachability currentReachabilityStatus] != NotReachable) {
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- [reachability stopNotifier];
-
- [PLATrack currentTrackWithBlock:^(PLATrack *track, NSError *error) {
- self.currentlyPlayingTrack = track;
- [[NSNotificationCenter defaultCenter] postNotificationName:PLANowPlayingUpdated object:nil];
- [self setUpPusher];
- [self subscribeToChannels];
- }];
-
- }
-}
-#endif
+//- (void)pusher:(PTPusher *)client connectionDidConnect:(PTPusherConnection *)connection{
+// NSLog(@"connectionDidConnect");
+// client.reconnectAutomatically = YES;
+//}
+//
+//- (void)pusher:(PTPusher *)pusher didSubscribeToChannel:(PTPusherChannel *)channel {
+// NSLog(@"did subscribe to channel: %@", [channel name]);
+//}
+//
+//- (void)pusher:(PTPusher *)pusher didFailToSubscribeToChannel:(PTPusherChannel *)channel withError:(NSError *)error{
+// NSLog(@"failed to subscribe: %@", error.description);
+//}
+//
+//- (void)pusher:(PTPusher *)pusher didReceiveErrorEvent:(PTPusherErrorEvent *)errorEvent{
+// NSLog(@"received error event: %@", errorEvent);
+//}
+
+//- (void)pusher:(PTPusher *)client connectionDidDisconnect:(PTPusherConnection *)connection{
+// NSLog(@"connectionDidDisconnect");
+//
+//#if TARGET_OS_EMBEDDED
+// Reachability *reachability = [Reachability reachabilityForInternetConnection];
+//
+// if ([reachability currentReachabilityStatus] == NotReachable) {
+// NSLog(@"NotReachable");
+// client.reconnectAutomatically = NO;
+//
+// [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object:reachability];
+//
+// [reachability startNotifier];
+// }else{
+// [PLATrack currentTrackWithBlock:^(PLATrack *track, NSError *error) {
+// dispatch_async(dispatch_get_main_queue(), ^(void) {
+// self.currentlyPlayingTrack = track;
+// [[NSNotificationCenter defaultCenter] postNotificationName:PLANowPlayingUpdated object:nil];
+// [self setUpPusher];
+// [self subscribeToChannels];
+// });
+// }];
+// }
+//
+//#else
+// [PLATrack currentTrackWithBlock:^(PLATrack *track, NSError *err) {
+// dispatch_async(dispatch_get_main_queue(), ^(void) {
+// self.currentlyPlayingTrack = track;
+// [[NSNotificationCenter defaultCenter] postNotificationName:PLANowPlayingUpdated object:nil];
+// [self setUpPusher];
+// [self subscribeToChannels];
+// });
+// }];
+//
+// [PLATrack currentQueueWithBlock:^(NSArray *tracks, NSError *err) {
+// if (tracks != nil)
+// self.queuedTracks = tracks;
+// }];
+//#endif
+//}
+//
+//#if TARGET_OS_EMBEDDED
+//- (void)reachabilityChanged:(NSNotification *)note{
+// NSLog(@"reachabilityChanged");
+// Reachability *reachability = note.object;
+//
+// if ([reachability currentReachabilityStatus] != NotReachable) {
+// [[NSNotificationCenter defaultCenter] removeObserver:self];
+// [reachability stopNotifier];
+//
+// [PLATrack currentTrackWithBlock:^(PLATrack *track, NSError *error) {
+// self.currentlyPlayingTrack = track;
+// [[NSNotificationCenter defaultCenter] postNotificationName:PLANowPlayingUpdated object:nil];
+// [self setUpPusher];
+// [self subscribeToChannels];
+// }];
+//
+// }
+//}
+//#endif
@@ -116,7 +116,7 @@ - (IBAction)showPrefs:(id)sender
if (downloadFolderPaths.count < 1)
return (NSURL *)nil;
- return [NSURL fileURLWithPath:[downloadFolderPaths objectAtIndex:0]];
+ return (NSURL *)[NSURL fileURLWithPath:[downloadFolderPaths objectAtIndex:0]];
};
- (void)downloadTrack:(PLATrack *)track

0 comments on commit ac68ffa

Please sign in to comment.