-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #85 from ckrey/websocket
Websocket
- Loading branch information
Showing
241 changed files
with
17,951 additions
and
8,971 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
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 |
---|---|---|
@@ -1,18 +1,52 @@ | ||
Pod::Spec.new do |s| | ||
s.name = "MQTTClient" | ||
s.version = "0.5.0" | ||
s.summary = "iOS, OSX and tvOS native ObjectiveC MQTT Client Framework" | ||
s.homepage = "https://github.com/ckrey/MQTT-Client-Framework" | ||
s.license = { :type => "EPLv1", :file => "LICENSE" } | ||
s.author = { "Christoph Krey" => "krey.christoph@gmail.com" } | ||
s.source = { :git => "https://github.com/ckrey/MQTT-Client-Framework.git", :tag => "0.5.0" } | ||
Pod::Spec.new do |mqttc| | ||
mqttc.name = "MQTTClient" | ||
mqttc.version = "0.6.0" | ||
mqttc.summary = "iOS, OSX and tvOS native ObjectiveC MQTT Client Framework" | ||
mqttc.homepage = "https://github.com/ckrey/MQTT-Client-Framework" | ||
mqttc.license = { :type => "EPLv1", :file => "LICENSE" } | ||
mqttc.author = { "Christoph Krey" => "krey.christoph@gmail.com" } | ||
mqttc.source = { | ||
:git => "https://github.com/ckrey/MQTT-Client-Framework.git", | ||
:tag => "0.6.0", | ||
:submodules => true | ||
} | ||
|
||
s.source_files = "MQTTClient/MQTTClient", "MQTTClient/MQTTClient/**/*.{h,m}" | ||
s.requires_arc = true | ||
mqttc.requires_arc = true | ||
mqttc.platform = :ios, "6.1", :osx, "10.10", :tvos, "9.0" | ||
mqttc.ios.deployment_target = "6.1" | ||
mqttc.osx.deployment_target = "10.10" | ||
mqttc.tvos.deployment_target = "9.0" | ||
mqttc.default_subspec = 'Classic' | ||
mqttc.compiler_flags = '-DLUMBERJACK' | ||
|
||
s.platform = :ios, "6.1", :osx, "10.10", :tvos, "9.0" | ||
mqttc.subspec 'Classic' do |classic| | ||
classic.dependency 'MQTTClient/Core' | ||
classic.dependency 'MQTTClient/SSLSecurityPolicy' | ||
classic.dependency 'MQTTClient/CoreData' | ||
end | ||
|
||
s.ios.deployment_target = "6.1" | ||
s.osx.deployment_target = "10.10" | ||
s.tvos.deployment_target = "9.0" | ||
mqttc.subspec 'Core' do |core| | ||
core.source_files = "MQTTClient/MQTTClient", | ||
"MQTTClient/MQTTClient/*.{h,m}", | ||
"MQTTClient/MQTTClient/MQTTInMemoryPersistence/*.{h,m}" | ||
core.dependency 'CocoaLumberjack' | ||
end | ||
|
||
mqttc.subspec 'CoreData' do |coredata| | ||
coredata.source_files = "MQTTClient/MQTTClient/MQTTCoreDataPersistence/*.{h,m}" | ||
coredata.dependency 'MQTTClient/Core' | ||
end | ||
|
||
mqttc.subspec 'SSLSecurityPolicy' do |secpol| | ||
secpol.source_files = "MQTTClient/MQTTClient/MQTTSSLSecurityPolicyTransport/*.{h,m}" | ||
secpol.dependency 'MQTTClient/Core' | ||
end | ||
|
||
mqttc.subspec 'Websocket' do |ws| | ||
ws.source_files = "MQTTClient/MQTTClient/MQTTWebsocketTransport/*.{h,m}" | ||
ws.dependency 'SocketRocket' | ||
ws.dependency 'MQTTClient/Core' | ||
ws.requires_arc = true | ||
ws.libraries = "icucore" | ||
end | ||
end |
Large diffs are not rendered by default.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
MQTTClient/MQTTClient.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,39 @@ | ||
// | ||
// MQTTCFSocketDecoder.h | ||
// MQTTClient.framework | ||
// | ||
// Copyright (c) 2013-2015, Christoph Krey | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
typedef NS_ENUM(NSInteger, MQTTCFSocketDecoderState) { | ||
MQTTCFSocketDecoderStateInitializing, | ||
MQTTCFSocketDecoderStateReady, | ||
MQTTCFSocketDecoderStateError | ||
}; | ||
|
||
@class MQTTCFSocketDecoder; | ||
|
||
@protocol MQTTCFSocketDecoderDelegate <NSObject> | ||
- (void)decoder:(MQTTCFSocketDecoder *)sender didReceiveMessage:(NSData *)data; | ||
- (void)decoderDidOpen:(MQTTCFSocketDecoder *)sender; | ||
- (void)decoder:(MQTTCFSocketDecoder *)sender didFailWithError:(NSError *)error; | ||
- (void)decoderdidClose:(MQTTCFSocketDecoder *)sender; | ||
|
||
@end | ||
|
||
@interface MQTTCFSocketDecoder : NSObject <NSStreamDelegate> | ||
@property (nonatomic) MQTTCFSocketDecoderState state; | ||
@property (strong, nonatomic) NSError *error; | ||
@property (strong, nonatomic) NSInputStream *stream; | ||
@property (strong, nonatomic) NSRunLoop *runLoop; | ||
@property (strong, nonatomic) NSString *runLoopMode; | ||
@property (weak, nonatomic ) id<MQTTCFSocketDecoderDelegate> delegate; | ||
|
||
- (void)open; | ||
- (void)close; | ||
|
||
@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,107 @@ | ||
// | ||
// MQTTCFSocketDecoder.m | ||
// MQTTClient.framework | ||
// | ||
// Copyright (c) 2013-2015, Christoph Krey | ||
// | ||
|
||
#import "MQTTCFSocketDecoder.h" | ||
|
||
#ifdef LUMBERJACK | ||
#define LOG_LEVEL_DEF ddLogLevel | ||
#import <CocoaLumberjack/CocoaLumberjack.h> | ||
#ifdef DEBUG | ||
static const DDLogLevel ddLogLevel = DDLogLevelVerbose; | ||
#else | ||
static const DDLogLevel ddLogLevel = DDLogLevelWarning; | ||
#endif | ||
#else | ||
#define DDLogVerbose NSLog | ||
#define DDLogWarn NSLog | ||
#define DDLogInfo NSLog | ||
#define DDLogError NSLog | ||
#endif | ||
|
||
@interface MQTTCFSocketDecoder() | ||
|
||
@end | ||
|
||
@implementation MQTTCFSocketDecoder | ||
|
||
- (instancetype)init { | ||
self = [super init]; | ||
self.state = MQTTCFSocketDecoderStateInitializing; | ||
|
||
self.stream = nil; | ||
self.runLoop = [NSRunLoop currentRunLoop]; | ||
self.runLoopMode = NSRunLoopCommonModes; | ||
return self; | ||
} | ||
|
||
- (void)open { | ||
if (self.state == MQTTCFSocketDecoderStateInitializing) { | ||
[self.stream setDelegate:self]; | ||
[self.stream scheduleInRunLoop:self.runLoop forMode:self.runLoopMode]; | ||
[self.stream open]; | ||
} | ||
} | ||
|
||
- (void)close { | ||
if (self.state == MQTTCFSocketDecoderStateReady || self.state == MQTTCFSocketDecoderStateError) { | ||
[self.stream close]; | ||
[self.stream removeFromRunLoop:self.runLoop forMode:self.runLoopMode]; | ||
[self.stream setDelegate:nil]; | ||
self.state = MQTTCFSocketDecoderStateInitializing; | ||
} | ||
} | ||
|
||
- (void)stream:(NSStream*)sender handleEvent:(NSStreamEvent)eventCode { | ||
|
||
if (eventCode & NSStreamEventOpenCompleted) { | ||
DDLogVerbose(@"[MQTTCFSocketDecoder] NSStreamEventOpenCompleted"); | ||
self.state = MQTTCFSocketDecoderStateReady; | ||
[self.delegate decoderDidOpen:self]; | ||
} | ||
|
||
if (eventCode & NSStreamEventHasBytesAvailable) { | ||
DDLogVerbose(@"[MQTTCFSocketDecoder] NSStreamEventHasBytesAvailable"); | ||
if (self.state == MQTTCFSocketDecoderStateInitializing) { | ||
self.state = MQTTCFSocketDecoderStateReady; | ||
} | ||
|
||
if (self.state == MQTTCFSocketDecoderStateReady) { | ||
NSInteger n; | ||
UInt8 buffer[768]; | ||
|
||
n = [self.stream read:buffer maxLength:sizeof(buffer)]; | ||
if (n == -1) { | ||
self.state = MQTTCFSocketDecoderStateError; | ||
[self.delegate decoder:self didFailWithError:nil]; | ||
} else { | ||
NSData *data = [NSData dataWithBytes:buffer length:n]; | ||
DDLogVerbose(@"[MQTTCFSocketDecoder] received (%lu)=%@...", (unsigned long)data.length, | ||
[data subdataWithRange:NSMakeRange(0, MIN(256, data.length))]); | ||
[self.delegate decoder:self didReceiveMessage:data]; | ||
} | ||
} | ||
} | ||
if (eventCode & NSStreamEventHasSpaceAvailable) { | ||
DDLogVerbose(@"[MQTTCFSocketDecoder] NSStreamEventHasSpaceAvailable"); | ||
} | ||
|
||
if (eventCode & NSStreamEventEndEncountered) { | ||
DDLogVerbose(@"[MQTTCFSocketDecoder] NSStreamEventEndEncountered"); | ||
self.state = MQTTCFSocketDecoderStateInitializing; | ||
self.error = nil; | ||
[self.delegate decoderdidClose:self]; | ||
} | ||
|
||
if (eventCode & NSStreamEventErrorOccurred) { | ||
DDLogVerbose(@"[MQTTCFSocketDecoder] NSStreamEventErrorOccurred"); | ||
self.state = MQTTCFSocketDecoderStateError; | ||
self.error = self.stream.streamError; | ||
[self.delegate decoder:self didFailWithError:self.error]; | ||
} | ||
} | ||
|
||
@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,38 @@ | ||
// | ||
// MQTTCFSocketEncoder.h | ||
// MQTTClient.framework | ||
// | ||
// Copyright (c) 2013-2015, Christoph Krey | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
typedef NS_ENUM(NSInteger, MQTTCFSocketEncoderState) { | ||
MQTTCFSocketEncoderStateInitializing, | ||
MQTTCFSocketEncoderStateReady, | ||
MQTTCFSocketEncoderStateError | ||
}; | ||
|
||
@class MQTTCFSocketEncoder; | ||
|
||
@protocol MQTTCFSocketEncoderDelegate <NSObject> | ||
- (void)encoderDidOpen:(MQTTCFSocketEncoder *)sender; | ||
- (void)encoder:(MQTTCFSocketEncoder *)sender didFailWithError:(NSError *)error; | ||
- (void)encoderdidClose:(MQTTCFSocketEncoder *)sender; | ||
|
||
@end | ||
|
||
@interface MQTTCFSocketEncoder : NSObject <NSStreamDelegate> | ||
@property (nonatomic) MQTTCFSocketEncoderState state; | ||
@property (strong, nonatomic) NSError *error; | ||
@property (strong, nonatomic) NSOutputStream *stream; | ||
@property (strong, nonatomic) NSRunLoop *runLoop; | ||
@property (strong, nonatomic) NSString *runLoopMode; | ||
@property (weak, nonatomic ) id<MQTTCFSocketEncoderDelegate> delegate; | ||
|
||
- (void)open; | ||
- (void)close; | ||
- (BOOL)send:(NSData *)data; | ||
|
||
@end | ||
|
Oops, something went wrong.