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
4 changes: 4 additions & 0 deletions Pod/Classes/NSDictionary+QueryString.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface NSDictionary (QueryString)
+ (NSDictionary *)dictionaryWithQueryString:(NSString *)queryString;
- (NSString *)queryStringValue;
@end

NS_ASSUME_NONNULL_END
12 changes: 6 additions & 6 deletions Pod/Classes/NSDictionary+QueryString.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@

@implementation NSDictionary (QueryString)

+ (NSDictionary *)dictionaryWithQueryString:(NSString *)queryString
{
+ (NSDictionary *)dictionaryWithQueryString:(NSString *)queryString {
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
NSArray *pairs = [queryString componentsSeparatedByString:@"&"];

Expand All @@ -26,11 +25,13 @@ + (NSDictionary *)dictionaryWithQueryString:(NSString *)queryString
NSString *decodedKey = [key URLDecodedString];
NSString *decodedValue = [value URLDecodedString];

if (![key isEqualToString:decodedKey])
if (![key isEqualToString:decodedKey]) {
key = decodedKey;
}

if (![value isEqualToString:decodedValue])
if (![value isEqualToString:decodedValue]) {
value = decodedValue;
}

[dictionary setObject:value forKey:key];
}
Expand All @@ -39,8 +40,7 @@ + (NSDictionary *)dictionaryWithQueryString:(NSString *)queryString
return [NSDictionary dictionaryWithDictionary:dictionary];
}

- (NSString *)queryStringValue
{
- (NSString *)queryStringValue {
NSMutableArray *pairs = [NSMutableArray array];
for (NSString *key in [self keyEnumerator])
{
Expand Down
4 changes: 4 additions & 0 deletions Pod/Classes/NSString+URLEncoding.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface NSString (URLEncoding)
- (NSString *)URLEncodedString;
- (NSString *)URLDecodedString;
@end

NS_ASSUME_NONNULL_END
15 changes: 9 additions & 6 deletions Pod/Classes/PhxChannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import <Foundation/Foundation.h>
#import "PhxTypes.h"

NS_ASSUME_NONNULL_BEGIN

@class PhxSocket;
@class PhxChannel;
Expand All @@ -26,12 +27,12 @@
@property (nonatomic, weak) id<PhxChannelDelegate> delegate;
@property (nonatomic, weak) PhxSocket* socket;
@property (nonatomic, readonly) ChannelState state;
@property (nonatomic, retain) NSString* topic;
@property (nonatomic, retain) NSDictionary *params;
@property (nonatomic, strong) NSString* topic;
@property (nonatomic, strong) NSDictionary *params;

- (id)initWithSocket:(PhxSocket*)socket
topic:(NSString*)topic
params:(NSDictionary*)params;
- (instancetype)initWithSocket:(PhxSocket*)socket
topic:(NSString*)topic
params:(nullable NSDictionary*)params;

- (PhxPush*)join;
- (void)leave;
Expand All @@ -44,4 +45,6 @@

- (PhxPush*)pushEvent:(NSString*)event payload:(NSDictionary*)payload;

@end
@end

NS_ASSUME_NONNULL_END
20 changes: 14 additions & 6 deletions Pod/Classes/PhxChannel.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,24 @@
#import "PhxSocket.h"
#import "PhxSocket_Private.h"

NS_ASSUME_NONNULL_BEGIN

@interface PhxChannel ()

@property (nonatomic, readwrite) ChannelState state;
@property (nonatomic) ChannelState state;

@property (nonatomic, retain) NSMutableArray *bindings;
@property (nonatomic, strong) NSMutableArray *bindings;

@property (readwrite) BOOL joinedOnce;
@property (nonatomic, retain) PhxPush *joinPush;
@property (atomic) BOOL joinedOnce;
@property (nonatomic, strong) PhxPush *joinPush;

@end

@implementation PhxChannel

- (id)initWithSocket:(PhxSocket *)socket topic:(NSString *)topic params:(NSDictionary *)params {
- (instancetype)initWithSocket:(PhxSocket *)socket
topic:(NSString *)topic
params:(nullable NSDictionary *)params {
self = [super init];
if (self) {
self.state = ChannelClosed;
Expand Down Expand Up @@ -131,7 +135,7 @@ - (NSString*)replyEventName:(NSString*)ref {
return [NSString stringWithFormat:@"chan_reply_%@", ref];
}

- (void)triggerEvent:(NSString*)event message:(id)message ref:(id)ref {
- (void)triggerEvent:(NSString*)event message:(id)message ref:(nullable id)ref {
NSPredicate *predicate = [NSPredicate predicateWithBlock:^BOOL(NSDictionary *binding, NSDictionary *bindings) {
return [[binding valueForKey:@"event"] isEqualToString:event];
}];
Expand All @@ -147,4 +151,8 @@ - (PhxPush*)pushEvent:(NSString*)event payload:(NSDictionary*)payload {
[pushEvent send];
return pushEvent;
}

@end

NS_ASSUME_NONNULL_END

8 changes: 6 additions & 2 deletions Pod/Classes/PhxChannel_Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@class PhxChannel;

@interface PhxChannel ()

- (void)rejoin;
- (void)triggerEvent:(NSString*)event message:(id)message ref:(id)ref;
- (void)triggerEvent:(NSString*)event message:(id)message ref:(nullable id)ref;
- (BOOL)isMemberOfTopic:(NSString*)topic;
- (NSString*)replyEventName:(NSString*)ref;

@end
@end

NS_ASSUME_NONNULL_END
14 changes: 9 additions & 5 deletions Pod/Classes/PhxPush.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,21 @@
#import <Foundation/Foundation.h>
#import "PhxTypes.h"

NS_ASSUME_NONNULL_BEGIN

@class PhxChannel;

@interface PhxPush : NSObject

- (id)initWithChannel:(PhxChannel*)channel
event:(NSString*)event
payload:(NSDictionary*)payload;
- (instancetype)initWithChannel:(PhxChannel*)channel
event:(NSString*)event
payload:(NSDictionary*)payload;

- (void)send;

- (PhxPush*)onReceive:(NSString*)status callback:(OnMessage)callback;
- (PhxPush*)after:(int)ms callback:(After)callback;
- (PhxPush *)onReceive:(NSString *)status callback:(OnMessage)callback;
- (PhxPush *)after:(NSTimeInterval)timeInterval callback:(After)callback;

@end

NS_ASSUME_NONNULL_END
46 changes: 25 additions & 21 deletions Pod/Classes/PhxPush.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,35 @@
#import "PhxChannel_Private.h"
#import "PhxSocket.h"

NS_ASSUME_NONNULL_BEGIN

@interface PhxPush ()

@property (nonatomic, weak) PhxChannel *channel;
@property (nonatomic, retain) NSString *event;
@property (nonatomic, retain) NSString *refEvent;
@property (nonatomic, retain) NSDictionary *payload;
@property (nonatomic, strong) NSString *event;
@property (nonatomic, strong) NSString *refEvent;
@property (nonatomic, strong) NSDictionary *payload;

@property (nonatomic, copy) After afterHook;
@property (readwrite) int afterInterval;
@property (nonatomic, retain) NSTimer *afterTimer;
@property (nullable, nonatomic, copy) After afterHook;
@property (nonatomic) NSTimeInterval afterInterval;
@property (nullable, nonatomic, strong) NSTimer *afterTimer;

@property (nonatomic, retain) NSMutableArray *recHooks;
@property (nonatomic, retain) id receivedResp;
@property (readwrite) BOOL sent;
@property (nonatomic, strong) NSMutableArray *recHooks;
@property (nullable, nonatomic, strong) id receivedResp;
@property (atomic) BOOL sent;

@end

@implementation PhxPush

- (id)initWithChannel:(PhxChannel*)channel
event:(NSString*)event
payload:(NSDictionary*)payload {
- (instancetype)initWithChannel:(PhxChannel*)channel
event:(NSString*)event
payload:(NSDictionary*)payload {
self = [super init];
if (self) {
self.channel = channel;
self.event = event;
if (payload) {
self.payload = payload;
} else {
self.payload = @{};
}
self.payload = payload;
self.receivedResp = nil;
self.afterHook = nil;
self.recHooks = [NSMutableArray new];
Expand All @@ -51,7 +49,7 @@ - (id)initWithChannel:(PhxChannel*)channel
}

- (void)send {
const NSString *ref = [self.channel.socket makeRef];
NSString *ref = [self.channel.socket makeRef];
self.refEvent = [self.channel replyEventName:ref];
self.receivedResp = nil;
self.sent = NO;
Expand All @@ -76,12 +74,16 @@ - (PhxPush*)onReceive:(NSString *)status callback:(OnMessage)callback {
return self;
}

- (PhxPush*)after:(int)ms callback:(After)callback {
- (PhxPush*)after:(NSTimeInterval)timeInterval callback:(After)callback {
if (self.afterHook) {
// ERROR
}
self.afterTimer = [NSTimer scheduledTimerWithTimeInterval:ms target:self selector:@selector(afterTimerFire:) userInfo:nil repeats:NO];
self.afterInterval = ms;
self.afterTimer = [NSTimer scheduledTimerWithTimeInterval:timeInterval
target:self
selector:@selector(afterTimerFire:)
userInfo:nil
repeats:NO];
self.afterInterval = timeInterval;
self.afterHook = callback;
return self;
}
Expand Down Expand Up @@ -129,3 +131,5 @@ - (void)matchReceive:(NSDictionary*)payload {
}

@end

NS_ASSUME_NONNULL_END
7 changes: 5 additions & 2 deletions Pod/Classes/PhxPush_Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface PhxPush()

@property (nonatomic, retain) NSDictionary *payload;
@property (nonatomic, strong) NSDictionary *payload;

@end
@end

NS_ASSUME_NONNULL_END
12 changes: 8 additions & 4 deletions Pod/Classes/PhxSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#import <Foundation/Foundation.h>
#import "PhxTypes.h"

NS_ASSUME_NONNULL_BEGIN

@protocol PhxSocketDelegate <NSObject>

- (void)phxSocketDidOpen;
Expand All @@ -22,13 +24,13 @@
@interface PhxSocket : NSObject

@property (nonatomic, weak) id<PhxSocketDelegate> delegate;
@property (nonatomic, readwrite) BOOL reconnectOnError;
@property (nonatomic) BOOL reconnectOnError;

- (id)initWithURL:(NSURL*)url;
- (id)initWithURL:(NSURL*)url heartbeatInterval:(int)interval;
- (instancetype)initWithURL:(NSURL*)url;
- (instancetype)initWithURL:(NSURL*)url heartbeatInterval:(NSTimeInterval)interval;

- (void)connect;
- (void)connectWithParams:(NSDictionary*)params;
- (void)connectWithParams:(nullable NSDictionary*)params;
- (void)disconnect;
- (void)reconnect;

Expand All @@ -47,3 +49,5 @@
- (void)push:(NSDictionary*)data;

@end

NS_ASSUME_NONNULL_END
Loading