Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start Migrating iOS Samples to Examples Project
- Loading branch information
Alex Billingsley
committed
Mar 2, 2016
1 parent
b5ad4c0
commit ac66c2a
Showing
24 changed files
with
1,263 additions
and
14 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 @@ | ||
// | ||
// ConnectionStatusConnection.h | ||
// SignalR.Client.ObjC Example | ||
// | ||
// Created by Alex Billingsley on 3/1/16. | ||
// | ||
// | ||
|
||
#import "SignalR.h" | ||
|
||
@interface ConnectionStatusConnection : SRHubConnection | ||
|
||
+ (instancetype)sharedConnection; | ||
|
||
- (void)ping; | ||
|
||
- (void)setPongBlock:(void (^)(void))block; | ||
- (void)setJoinedBlock:(void (^)(NSString *connectionId, NSString *when))block; | ||
- (void)setRejoinedBlock:(void (^)(NSString *connectionId, NSString *when))block; | ||
- (void)setLeaveBlock:(void (^)(NSString *connectionId, NSString *when))block; | ||
|
||
|
||
@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,101 @@ | ||
// | ||
// ConnectionStatusConnection.m | ||
// SignalR.Client.ObjC Example | ||
// | ||
// Created by Alex Billingsley on 3/1/16. | ||
// | ||
// | ||
|
||
#import "ConnectionStatusConnection.h" | ||
|
||
static NSString * const SRConnectionBaseURLString = @"http://abill-win10:9090/"; | ||
|
||
typedef void (^SRPongBlock)(); | ||
typedef void (^SRConnectionStatusBlock)(NSString *connectionId, NSString *when); | ||
|
||
@interface ConnectionStatusConnection () | ||
|
||
@property (strong, nonatomic, readwrite) SRHubProxy * hub; | ||
|
||
@property (readwrite, nonatomic, copy) SRPongBlock pong; | ||
@property (readwrite, nonatomic, copy) SRConnectionStatusBlock joined; | ||
@property (readwrite, nonatomic, copy) SRConnectionStatusBlock rejoined; | ||
@property (readwrite, nonatomic, copy) SRConnectionStatusBlock leave; | ||
|
||
@end | ||
|
||
@implementation ConnectionStatusConnection | ||
|
||
+ (instancetype)sharedConnection { | ||
static ConnectionStatusConnection *_sharedConnection = nil; | ||
static dispatch_once_t onceToken; | ||
dispatch_once(&onceToken, ^{ | ||
_sharedConnection = [[ConnectionStatusConnection alloc] initWithURLString:SRConnectionBaseURLString]; | ||
}); | ||
|
||
return _sharedConnection; | ||
} | ||
|
||
- (instancetype)initWithURLString:(NSString *)url { | ||
self = [super initWithURLString:url]; | ||
if (!self) { | ||
return nil; | ||
} | ||
|
||
_hub = [self createHubProxy:@"statushub"]; | ||
[_hub on:@"pong" perform:self selector:@selector(handlePong)]; | ||
[_hub on:@"joined" perform:self selector:@selector(handleJoined:when:)]; | ||
[_hub on:@"rejoined" perform:self selector:@selector(handleRejoined:when:)]; | ||
[_hub on:@"leave" perform:self selector:@selector(handleLeave:when:)]; | ||
|
||
return self; | ||
} | ||
|
||
- (void)ping { | ||
[self.hub invoke:@"ping" withArgs:@[] completionHandler:nil]; | ||
} | ||
|
||
- (void)setPongBlock:(void (^)(void))block { | ||
self.pong = block; | ||
} | ||
|
||
- (void)setJoinedBlock:(void (^)(NSString *connectionId, NSString *when))block; { | ||
self.joined = block; | ||
} | ||
|
||
- (void)setRejoinedBlock:(void (^)(NSString *connectionId, NSString *when))block; { | ||
self.rejoined = block; | ||
} | ||
|
||
- (void)setLeaveBlock:(void (^)(NSString *connectionId, NSString *when))block; { | ||
self.leave = block; | ||
} | ||
|
||
#pragma mark - | ||
#pragma mark Private | ||
|
||
- (void)handlePong { | ||
if(self.pong) { | ||
self.pong(); | ||
} | ||
} | ||
|
||
- (void)handleJoined:(NSString *)connectionId when:(NSString *)when { | ||
if(self.joined) { | ||
self.joined(connectionId,when); | ||
} | ||
} | ||
|
||
- (void)handleRejoined:(NSString *)connectionId when:(NSString *)when { | ||
if(self.rejoined) { | ||
self.rejoined(connectionId,when); | ||
} | ||
} | ||
|
||
- (void)handleLeave:(NSString *)connectionId when:(NSString *)when { | ||
if(self.leave) { | ||
self.leave(connectionId,when); | ||
} | ||
} | ||
|
||
@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,18 @@ | ||
// | ||
// MouseTrackingConnection.h | ||
// SignalR.Client.ObjC Example | ||
// | ||
// Created by Alex Billingsley on 3/2/16. | ||
// | ||
// | ||
|
||
#import "SignalR.h" | ||
|
||
@interface MouseTrackingConnection : SRHubConnection | ||
|
||
- (void)join; | ||
- (void)move:(CGPoint)point completionHandler:(void (^)(id response, NSError *error))block; | ||
|
||
- (void)setMoveBlock:(void (^)(NSString *connectionId, NSNumber *x, NSNumber *y))block; | ||
|
||
@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,65 @@ | ||
// | ||
// MouseTrackingConnection.m | ||
// SignalR.Client.ObjC Example | ||
// | ||
// Created by Alex Billingsley on 3/2/16. | ||
// | ||
// | ||
|
||
#import "MouseTrackingConnection.h" | ||
|
||
static NSString * const SRConnectionBaseURLString = @"http://abill-win10:9090/"; | ||
|
||
typedef void (^SRConnectionMouseMoveBlock)(NSString *connectionId, NSNumber *x, NSNumber *y); | ||
|
||
@interface MouseTrackingConnection () | ||
|
||
@property (strong, nonatomic, readwrite) SRHubProxy * hub; | ||
|
||
@property (readwrite, nonatomic, copy) SRConnectionMouseMoveBlock move; | ||
|
||
@end | ||
|
||
@implementation MouseTrackingConnection | ||
|
||
+ (instancetype)sharedConnection { | ||
static MouseTrackingConnection *_sharedConnection = nil; | ||
static dispatch_once_t onceToken; | ||
dispatch_once(&onceToken, ^{ | ||
_sharedConnection = [[MouseTrackingConnection alloc] initWithURLString:SRConnectionBaseURLString]; | ||
}); | ||
|
||
return _sharedConnection; | ||
} | ||
|
||
- (instancetype)initWithURLString:(NSString *)url { | ||
self = [super initWithURLString:url]; | ||
if (!self) { | ||
return nil; | ||
} | ||
|
||
_hub = [self createHubProxy:@"statushub"]; | ||
[_hub on:@"move" perform:self selector:@selector(handleMove:x:y:)]; | ||
|
||
return self; | ||
} | ||
|
||
- (void)join { | ||
[_hub invoke:@"join" withArgs:@[] completionHandler:nil]; | ||
} | ||
|
||
- (void)move:(CGPoint)point completionHandler:(void (^)(id response, NSError *error))block; { | ||
[_hub invoke:@"move" withArgs:@[@(point.x), @(point.y)] completionHandler:block]; | ||
} | ||
|
||
- (void)setMoveBlock:(void (^)(NSString *connectionId, NSNumber *x, NSNumber *y))block { | ||
self.move = block; | ||
} | ||
|
||
- (void)handleMove:(NSString *)connectionId x:(NSNumber *)x y:(NSNumber *)y { | ||
if(self.move) { | ||
self.move(connectionId,x,y); | ||
} | ||
} | ||
|
||
@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,26 @@ | ||
// | ||
// RawConnection.h | ||
// SignalR.Client.ObjC Example | ||
// | ||
// Created by Alex Billingsley on 3/1/16. | ||
// | ||
// | ||
|
||
#import "SignalR.h" | ||
|
||
@interface RawConnection : SRConnection | ||
|
||
+ (instancetype)sharedConnection; | ||
|
||
- (void)sendMessage:(NSString *)message completionHandler:(void (^)(id response, NSError *error))block; | ||
- (void)broadcastMessage:(NSString *)message completionHandler:(void (^)(id response, NSError *error))block; | ||
- (void)broadcastMessageExceptMe:(NSString *)message completionHandler:(void (^)(id response, NSError *error))block; | ||
|
||
- (void)join:(NSString *)username completionHandler:(void (^)(id response, NSError *error))block; | ||
- (void)sendMessage:(NSString *)message toUser:(NSString *)username completionHandler:(void (^)(id response, NSError *error))block; | ||
|
||
- (void)joinGroup:(NSString *)group completionHandler:(void (^)(id response, NSError *error))block; | ||
- (void)sendMessage:(NSString *)message toGroup:(NSString *)group completionHandler:(void (^)(id response, NSError *error))block; | ||
- (void)leaveGroup:(NSString *)group completionHandler:(void (^)(id response, NSError *error))block; | ||
|
||
@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,100 @@ | ||
// | ||
// RawConnection.m | ||
// SignalR.Client.ObjC Example | ||
// | ||
// Created by Alex Billingsley on 3/1/16. | ||
// | ||
// | ||
|
||
#import "RawConnection.h" | ||
|
||
typedef enum { | ||
SRMessageTypeSend = 0, | ||
SRMessageTypeBroadcast, | ||
SRMessageTypeJoin, | ||
SRMessageTypePrivateMessage, | ||
SRMessageTypeAddToGroup, | ||
SRMessageTypeRemoveFromGroup, | ||
SRMessageTypeSendToGroup, | ||
SRMessageTypeBroadcastExceptMe | ||
} SRMessageType; | ||
|
||
static NSString * const SRConnectionBaseURLString = @"http://abill-win10:9090/"; | ||
|
||
@implementation RawConnection | ||
|
||
+ (instancetype)sharedConnection { | ||
static RawConnection *_sharedConnection = nil; | ||
static dispatch_once_t onceToken; | ||
dispatch_once(&onceToken, ^{ | ||
_sharedConnection = [[RawConnection alloc] initWithURLString:[SRConnectionBaseURLString stringByAppendingFormat:@"raw-connection"]]; | ||
}); | ||
|
||
return _sharedConnection; | ||
} | ||
|
||
- (void)sendMessage:(NSString *)message completionHandler:(void (^)(id response, NSError *error))block; { | ||
id json = @{ | ||
@"type": @(SRMessageTypeSend), | ||
@"value": message | ||
}; | ||
[self send:json completionHandler:block]; | ||
} | ||
|
||
- (void)broadcastMessage:(NSString *)message completionHandler:(void (^)(id response, NSError *error))block; { | ||
id json = @{ | ||
@"type": @(SRMessageTypeBroadcast), | ||
@"value": message | ||
}; | ||
[self send:json completionHandler:block]; | ||
} | ||
|
||
- (void)broadcastMessageExceptMe:(NSString *)message completionHandler:(void (^)(id response, NSError *error))block { | ||
id json = @{ | ||
@"type": @(SRMessageTypeBroadcastExceptMe), | ||
@"value": message | ||
}; | ||
[self send:json completionHandler:block]; | ||
} | ||
|
||
- (void)join:(NSString *)username completionHandler:(void (^)(id response, NSError *error))block; { | ||
id json = @{ | ||
@"type": @(SRMessageTypeJoin), | ||
@"value": username | ||
}; | ||
[self send:json completionHandler:block]; | ||
} | ||
|
||
- (void)sendMessage:(NSString *)message toUser:(NSString *)username completionHandler:(void (^)(id response, NSError *error))block; { | ||
id json = @{ | ||
@"type": @(SRMessageTypePrivateMessage), | ||
@"value": [NSString stringWithFormat:@"%@|%@",username, message] | ||
}; | ||
[self send:json completionHandler:block]; | ||
} | ||
|
||
- (void)joinGroup:(NSString *)group completionHandler:(void (^)(id response, NSError *error))block; { | ||
id json = @{ | ||
@"type": @(SRMessageTypeAddToGroup), | ||
@"value": group | ||
}; | ||
[self send:json completionHandler:block]; | ||
} | ||
|
||
- (void)sendMessage:(NSString *)message toGroup:(NSString *)group completionHandler:(void (^)(id response, NSError *error))block; { | ||
id json = @{ | ||
@"type": @(SRMessageTypeSendToGroup), | ||
@"value": [NSString stringWithFormat:@"%@|%@",group, message] | ||
}; | ||
[self send:json completionHandler:block]; | ||
} | ||
|
||
- (void)leaveGroup:(NSString *)group completionHandler:(void (^)(id response, NSError *error))block { | ||
id json = @{ | ||
@"type": @(SRMessageTypeRemoveFromGroup), | ||
@"value": group | ||
}; | ||
[self send:json completionHandler:block]; | ||
} | ||
|
||
@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,15 @@ | ||
// | ||
// StreamingConnection.h | ||
// SignalR.Client.ObjC Example | ||
// | ||
// Created by Alex Billingsley on 3/1/16. | ||
// | ||
// | ||
|
||
#import "SignalR.h" | ||
|
||
@interface StreamingConnection : SRConnection | ||
|
||
+ (instancetype)sharedConnection; | ||
|
||
@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,25 @@ | ||
// | ||
// StreamingConnection.m | ||
// SignalR.Client.ObjC Example | ||
// | ||
// Created by Alex Billingsley on 3/1/16. | ||
// | ||
// | ||
|
||
#import "StreamingConnection.h" | ||
|
||
static NSString * const SRConnectionBaseURLString = @"http://abill-win10:9090/"; | ||
|
||
@implementation StreamingConnection | ||
|
||
+ (instancetype)sharedConnection { | ||
static StreamingConnection *_sharedConnection = nil; | ||
static dispatch_once_t onceToken; | ||
dispatch_once(&onceToken, ^{ | ||
_sharedConnection = [[StreamingConnection alloc] initWithURLString:[SRConnectionBaseURLString stringByAppendingFormat:@"streaming-connection"]]; | ||
}); | ||
|
||
return _sharedConnection; | ||
} | ||
|
||
@end |
Oops, something went wrong.