Permalink
Browse files

Support for CocoaPods

  • Loading branch information...
jparreira committed Jan 8, 2015
1 parent bdd0d9d commit c895e238e91e87b19d6f2b67777653a254073ba5
View
13 LICENSE
@@ -1,6 +1,4 @@
The MIT License (MIT)
Copyright (c) 2015 Realtime Framework
Copyright (c) 2015 Realtime <framework@realtime.co>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -9,14 +7,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
@@ -0,0 +1,15 @@
//
// Balancer.h
// OrtcClient
//
// Created by Marcin Kulwikowski on 15/07/14.
//
//
#import <Foundation/Foundation.h>
@interface Balancer : NSObject
- initWithCluster:(NSString*) aCluster serverUrl:(NSString*)url isCluster:(BOOL)isCluster appKey:(NSString*) anAppKey callback:(void (^)(NSString *aBalancerResponse))aCallback;
@end
@@ -0,0 +1,79 @@
//
// Balancer.m
// OrtcClient
//
// Created by Marcin Kulwikowski on 15/07/14.
//
//
#import "Balancer.h"
NSString* const BALANCER_RESPONSE_PATTERN = @"^var SOCKET_SERVER = \\\"(.*?)\\\";$";
@implementation Balancer {
NSMutableData *receivedData;
void (^theCallabck)(NSString*);
}
- (id) initWithCluster:(NSString*) aCluster serverUrl:(NSString*)url isCluster:(BOOL)isCluster appKey:(NSString*) anAppKey callback:(void (^)(NSString *aBalancerResponse))aCallback{
if ((self = [super init])) {
theCallabck = aCallback;
NSString* parsedUrl = aCluster;
if(!isCluster){
aCallback(url);
} else {
if(anAppKey != NULL){
parsedUrl = [parsedUrl stringByAppendingString:@"?appkey="];
parsedUrl = [parsedUrl stringByAppendingString:anAppKey];
}
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:parsedUrl]];
(void)[[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
}
}
return nil;
}
#pragma mark NSURLConnection delegate methods
- (NSCachedURLResponse *)connection:(NSURLConnection *)connection willCacheResponse:(NSCachedURLResponse*)cachedResponse {
// Return nil to indicate not necessary to store a cached response for this connection
return nil;
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
receivedData = [[NSMutableData alloc] init];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[receivedData appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)aError {
theCallabck(nil);
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
if(receivedData !=nil){
NSString* myString = [[NSString alloc] initWithData:receivedData encoding:NSUTF8StringEncoding];
NSRegularExpression* resRegex = [NSRegularExpression regularExpressionWithPattern:BALANCER_RESPONSE_PATTERN options:0 error:NULL];
NSTextCheckingResult* resMatch = [resRegex firstMatchInString:myString options:0 range:NSMakeRange(0, [myString length])];
if (resMatch)
{
NSRange strRange = [resMatch rangeAtIndex:1];
if (strRange.location != NSNotFound) {
theCallabck([myString substringWithRange:strRange]);
return;
}
}
}
theCallabck(nil);
}
@end
Oops, something went wrong.

0 comments on commit c895e23

Please sign in to comment.