Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion SonosKit/SonosController.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ typedef NS_ENUM(NSInteger, SonosRequestType) {
@property (nonatomic, strong) NSString *group;
@property (nonatomic, strong) NSString *name;
@property (nonatomic, strong) NSString *uuid;
@property (nonatomic, strong) NSString *status;
@property (nonatomic, strong) NSString *info;
@property (nonatomic, strong) NSString *currentvolume;

@property (nonatomic, readonly) NSArray *slaves;
@property (nonatomic, assign, getter = isCoordinator) BOOL coordinator;

Expand Down Expand Up @@ -99,4 +103,4 @@ typedef NS_ENUM(NSInteger, SonosRequestType) {
- (void)removeSlave:(SonosController *)slave;
- (void)removeAllSlaves;

@end
@end
15 changes: 11 additions & 4 deletions SonosKit/SonosController.m
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ - (void)request:(SonosRequestType)type action:(NSString *)action params:(NSDicti
if (httpResponse.statusCode != 200) return;

NSDictionary *responseDict = [XMLReader dictionaryForXMLData:data options:XMLReaderOptionsProcessNamespaces error:&error];
NSDictionary *body = responseDict[@"Envelope"][@"Body"];
NSDictionary *body = responseDict[@"s:Envelope"][@"s:Body"];

dispatch_async(dispatch_get_main_queue(), ^{
if (block) block(body, nil);
Expand Down Expand Up @@ -173,12 +173,13 @@ - (void)getTransportInfo:(void (^)(BOOL, NSDictionary *, NSError *))block
{
NSDictionary *params = @{@"InstanceID": @0};
[self request:SonosRequestTypeAVTransport action:@"GetTransportInfo" params:params completion:^(NSDictionary *response, NSError *error) {

if (error) {
block(NO, nil, error);
return;
}

if ([response[@"CurrentTransportState"] isEqualToString:@"PLAYING"]) {
if ([response[@"u:GetTransportInfoResponse"][@"CurrentTransportState"][@"text"] isEqualToString:@"PLAYING"]) {
block(YES, response, nil);
return;
}
Expand Down Expand Up @@ -306,7 +307,7 @@ - (void)getVolume:(void (^)(NSInteger, NSDictionary *, NSError *))block
NSDictionary *params = @{@"InstanceID": @0, @"Channel":@"Master"};
[self request:SonosRequestTypeRenderingControl action:@"GetVolume" params:params completion:^(NSDictionary *response, NSError *error) {
if (!error) {
NSInteger volume = [response[@"GetVolumeResponse"][@"CurrentVolume"][@"text"] integerValue];
NSInteger volume = [response[@"u:GetVolumeResponse"][@"CurrentVolume"][@"text"] integerValue];
block(volume, response, error);
return;
}
Expand Down Expand Up @@ -431,7 +432,10 @@ - (instancetype)initWithCoder:(NSCoder *)aDecoder
[self setGroup:[aDecoder decodeObjectForKey:@"group"]];
[self setName:[aDecoder decodeObjectForKey:@"name"]];
[self setUuid:[aDecoder decodeObjectForKey:@"uuid"]];
[self setStatus:[aDecoder decodeObjectForKey:@"status"]];
[self setInfo:[aDecoder decodeObjectForKey:@"info"]];
[self setCoordinator:[aDecoder decodeBoolForKey:@"coordinator"]];
[self setCurrentvolume:[aDecoder decodeObjectForKey:@"currentvolume"]];
}
return self;
}
Expand All @@ -442,7 +446,10 @@ - (void)encodeWithCoder:(NSCoder *)aCoder
[aCoder encodeObject:_group forKey:@"group"];
[aCoder encodeObject:_name forKey:@"name"];
[aCoder encodeObject:_uuid forKey:@"uuid"];
[aCoder encodeObject:_status forKey:@"status"];
[aCoder encodeObject:_info forKey:@"info"];
[aCoder encodeBool:_coordinator forKey:@"coordinator"];
[aCoder encodeObject:_currentvolume forKey:@"currentvolume"];
}

@end
@end
12 changes: 11 additions & 1 deletion SonosKit/SonosControllerStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,18 @@

@class SonosController;

@interface SonosControllerStore : NSObject
// Protocol definition starts here
@protocol SonosControllerStoreDelegate <NSObject>

@required
- (void) didFinishDiscoveringControllers: (NSArray *)controllers;
@end

@interface SonosControllerStore : NSObject {
id <SonosControllerStoreDelegate> _delegate;
}

@property (nonatomic, strong) id delegate;
@property (nonatomic, readonly) NSArray *allControllers;
@property (nonatomic, readonly) NSArray *coordinators;
@property (nonatomic, readonly) NSArray *slaves;
Expand Down
9 changes: 6 additions & 3 deletions SonosKit/SonosControllerStore.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

@implementation SonosControllerStore

@synthesize delegate;

+ (SonosControllerStore *)sharedStore
{
static SonosControllerStore *sharedStore = nil;
Expand Down Expand Up @@ -63,7 +65,7 @@ - (NSArray *)data
- (void)discoverControllers
{
[SonosDiscovery discoverControllers:^(NSArray *objects, NSError *error) {
[self willChangeValueForKey:@"allControllers"];
//[self willChangeValueForKey:@"allControllers"];

NSMutableArray *controllers = [[NSMutableArray alloc] init];

Expand All @@ -79,7 +81,8 @@ - (void)discoverControllers
_allControllers = [NSArray arrayWithArray:controllers];
[self organizeControllers];

[self didChangeValueForKey:@"allControllers"];
//[self didChangeValueForKey:@"allControllers"];
[delegate didFinishDiscoveringControllers:[NSArray arrayWithArray:controllers]];
}];
}

Expand Down Expand Up @@ -148,4 +151,4 @@ - (BOOL)saveChanges
return [NSKeyedArchiver archiveRootObject:_allControllers toFile:path];
}

@end
@end
2 changes: 1 addition & 1 deletion SonosKit/SonosDiscovery.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ + (void)discoverControllers:(void(^)(NSArray *controllers, NSError *error))compl
NSString *ip = [ipLocation substringWithRange:ipRegexMatch.range];
BOOL coordinator = [input[@"coordinator"] isEqualToString:@"true"] ? YES : NO;

if (![input[@"text"] isEqualToString:@"Sonos Bridge"]) {
if (![input[@"text"] isEqualToString:@"Sonos Bridge"] && ![input[@"text"] isEqualToString:@"BRIDGE"]) {
[controllers addObject:@{
@"ip": ip,
@"name": input[@"text"],
Expand Down