{"action":"created","issue":{"url":"https://api.github.com/repos/ckrey/MQTT-Client-Framework/issues/103","repository_url":"https://api.github.com/repos/ckrey/MQTT-Client-Framework","labels_url":"https://api.github.com/repos/ckrey/MQTT-Client-Framework/issues/103/labels{/name}","comments_url":"https://api.github.com/repos/ckrey/MQTT-Client-Framework/issues/103/comments","events_url":"https://api.github.com/repos/ckrey/MQTT-Client-Framework/issues/103/events","html_url":"https://github.com/ckrey/MQTT-Client-Framework/issues/103","id":131088722,"number":103,"title":"react-native module wrap, doesn't work","user":{"login":"tuanpmt","id":1904924,"avatar_url":"https://avatars.githubusercontent.com/u/1904924?v=3","gravatar_id":"","url":"https://api.github.com/users/tuanpmt","html_url":"https://github.com/tuanpmt","followers_url":"https://api.github.com/users/tuanpmt/followers","following_url":"https://api.github.com/users/tuanpmt/following{/other_user}","gists_url":"https://api.github.com/users/tuanpmt/gists{/gist_id}","starred_url":"https://api.github.com/users/tuanpmt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tuanpmt/subscriptions","organizations_url":"https://api.github.com/users/tuanpmt/orgs","repos_url":"https://api.github.com/users/tuanpmt/repos","events_url":"https://api.github.com/users/tuanpmt/events{/privacy}","received_events_url":"https://api.github.com/users/tuanpmt/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-02-03T17:03:38Z","updated_at":"2016-02-05T06:56:13Z","closed_at":"2016-02-05T06:56:13Z","body":"Hello @ckrey \r\nThank you for your professional and full features mqtt library . And now i want to integrate with my app using [react-native](https://github.com/facebook/react-native), this is simple code, when i click in button, it will call connect \r\n```javascript\r\nvar mqtt = require('react-native').NativeModules.Mqtt;\r\nmqtt.connect({});\r\n```\r\n\r\n```c\r\n#import \"RCTMqtt.h\"\r\n#import \"RCTBridgeModule.h\"\r\n#import \"RCTLog.h\"\r\n#import \"RCTUtils.h\"\r\n#import \"RCTEventDispatcher.h\"\r\n\r\n#import <MQTTClient/MQTTClient.h>\r\n#import <MQTTClient/MQTTSessionManager.h>\r\n\r\n#import <CocoaLumberjack/CocoaLumberjack.h>\r\n\r\n@interface RCTMqtt : NSObject<RCTBridgeModule,  MQTTSessionManagerDelegate>\r\n\r\n@end\r\n\r\n@interface RCTMqtt ()\r\n\r\n@property (strong, nonatomic) MQTTSessionManager *manager;\r\n@property (nonatomic, strong) NSDictionary *defaultOptions;\r\n@property (nonatomic, retain) NSMutableDictionary *options;\r\n\r\n@end\r\n\r\n@implementation RCTMqtt\r\n@synthesize bridge = _bridge;\r\nRCT_EXPORT_MODULE();\r\n- (instancetype)init\r\n{\r\n    [DDLog addLogger:[DDASLLogger sharedInstance]];\r\n    [DDLog addLogger:[DDTTYLogger sharedInstance]];\r\n\r\n    self.defaultOptions = @{\r\n                            @\"host\": @\"test.mosquitto.org\",\r\n                            @\"port\": @1883,\r\n                            @\"protcol\": @\"tcp\", //ws\r\n                            @\"tls\": @NO,\r\n                            @\"keepalice\": @120, //second\r\n                            @\"clientId\" : @\"react-native-mqtt\",\r\n                            @\"protocolLevel\": @4,\r\n                            @\"clean\": @YES,\r\n                            @\"auth\": @NO,\r\n                            @\"user\": @\"\",\r\n                            @\"pass\": @\"\",\r\n                            @\"willtopic\": @\"\",\r\n                            @\"will\": @\"\",\r\n                            @\"willQos\": @0,\r\n                            @\"willRetainFlag\": @NO\r\n                            };\r\n    return self;\r\n    \r\n}\r\n\r\nRCT_EXPORT_METHOD(connect:(NSDictionary *)options) {\r\n    \r\n    self.options = [NSMutableDictionary dictionaryWithDictionary:self.defaultOptions]; // Set default options\r\n    for (NSString *key in options.keyEnumerator) { // Replace default options\r\n        [self.options setValue:options[key] forKey:key];\r\n    }\r\n    \r\n    if (!self.manager) {\r\n        RCTLogInfo(@\"react-native:first time create\");\r\n        self.manager = [[MQTTSessionManager alloc] init];\r\n        \r\n        self.manager.delegate = self;\r\n        \r\n        [self.manager connectTo:self.options[@\"host\"]\r\n                           port:[self.options[@\"port\"] intValue]\r\n                            tls:[self.options[@\"tls\"] boolValue]\r\n                      keepalive:[self.options[@\"keepalive\"] intValue]\r\n                          clean:[self.options[@\"clean\"] intValue]\r\n                           auth:[self.options[@\"auth\"] intValue]\r\n                           user:[self.options valueForKey:@\"user\"]\r\n                           pass:[self.options valueForKey:@\"pass\"]\r\n                      willTopic:[self.options valueForKey:@\"willTopic\"]\r\n                           will:[self.options[@\"will\"] dataUsingEncoding:NSUTF8StringEncoding]\r\n                        willQos:MQTTQosLevelExactlyOnce\r\n                 willRetainFlag:[self.options[@\"willRetainFlag\"] boolValue]\r\n                   withClientId:[self.options valueForKey:@\"clientId\"]];\r\n    } else {\r\n        [self.manager connectToLast];\r\n    }\r\n    \r\n}\r\n\r\n\r\n- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {\r\n    \r\n    switch (self.manager.state) {\r\n        case MQTTSessionManagerStateClosed:\r\n            RCTLogInfo(@\"Closed\");\r\n            \r\n            break;\r\n        case MQTTSessionManagerStateClosing:\r\n            RCTLogInfo(@\"closing\");\r\n            break;\r\n        case MQTTSessionManagerStateConnected:\r\n            RCTLogInfo(@\"connected\");\r\n            \r\n            break;\r\n        case MQTTSessionManagerStateConnecting:\r\n            RCTLogInfo(@\"connecting\");\r\n            break;\r\n        case MQTTSessionManagerStateError:\r\n            RCTLogInfo(@\"Error\");\r\n            break;\r\n        case MQTTSessionManagerStateStarting:\r\n        default:\r\n            RCTLogInfo(@\"not connected\");\r\n            break;\r\n    }\r\n}\r\n\r\n/*\r\n * MQTTSessionManagerDelegate\r\n */\r\n- (void)handleMessage:(NSData *)data onTopic:(NSString *)topic retained:(BOOL)retained {\r\n    /*\r\n     * MQTTClient: process received message\r\n     */\r\n    \r\n    NSString *dataString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];\r\n   RCTLogInfo(@\" %@ : %@\", topic, dataString);\r\n    \r\n}\r\n\r\n- (void)connected:(MQTTSession *)session sessionPresent:(BOOL)sessionPresent {\r\n    RCTLogInfo(@\"connected\");\r\n}\r\n@end\r\n```\r\n\r\n```\r\n2016-02-04 00:25:38.971 [trace][tid:com.facebook.React.JavaScript][RCTJSCProfiler.m:63] JSC profiler is not supported.\r\n2016-02-04 00:25:39.198 [trace][tid:NSOperationQueue 0x7fa0f8788fa0 :: NSOperation 0x7fa0f879be70 (QOS: LEGACY)][RCTPerformanceLogger.m:29] Unbalanced calls start/end for tag 0\r\n2016-02-04 00:25:41.684 [trace][tid:com.facebook.React.RCTMqttQueue][RCTMqtt.m:78] react-native:first time create\r\n2016-02-04 00:25:41:686 GreenBot[14814:334355] MQTTSessionManager connectTo:test.mosquitto.org\r\n2016-02-04 00:25:41:686 GreenBot[14814:334355] MQTTSessionManager connectTo:test.mosquitto.org\r\n2016-02-04 00:25:41:687 GreenBot[14814:334355] [MQTTSessionLegacy] initWithClientId:react-native-mqtt \r\n2016-02-04 00:25:41:687 GreenBot[14814:334355] [MQTTSessionLegacy] initWithClientId:react-native-mqtt \r\n2016-02-04 00:25:41:688 GreenBot[14814:334355] [MQTTSession] init\r\n2016-02-04 00:25:41:688 GreenBot[14814:334355] [MQTTSession] init\r\n2016-02-04 00:25:41:690 GreenBot[14814:334355] [MQTTSessionManager] connecting\r\n2016-02-04 00:25:41:690 GreenBot[14814:334355] [MQTTSessionManager] connecting\r\n2016-02-04 00:25:41:690 GreenBot[14814:334355] MQTTSessionLegacy connectToHost:test.mosquitto.org port:1883 usingSSL:0 connectHandler:0x0\r\n2016-02-04 00:25:41:690 GreenBot[14814:334355] MQTTSessionLegacy connectToHost:test.mosquitto.org port:1883 usingSSL:0 connectHandler:0x0\r\n2016-02-04 00:25:41:691 GreenBot[14814:334355] [MQTTSession] connectWithConnectHandler:0x0\r\n2016-02-04 00:25:41:691 GreenBot[14814:334355] [MQTTSession] connectWithConnectHandler:0x0\r\n2016-02-04 00:25:41:691 GreenBot[14814:334355] [MQTTSession] connecting\r\n2016-02-04 00:25:41:691 GreenBot[14814:334355] [MQTTSession] connecting\r\n2016-02-04 00:25:41:691 GreenBot[14814:334355] [MQTTPersistence] Persistent store: /Users/TuanPM/Library/Developer/CoreSimulator/Devices/F8C98F2E-7893-4018-9527-BA2181079F0F/data/Containers/Data/Application/389034FF-6FA2-4401-99C0-831400D181E8/Documents/MQTTClient\r\n2016-02-04 00:25:41:691 GreenBot[14814:334355] [MQTTPersistence] Persistent store: /Users/TuanPM/Library/Developer/CoreSimulator/Devices/F8C98F2E-7893-4018-9527-BA2181079F0F/data/Containers/Data/Application/389034FF-6FA2-4401-99C0-831400D181E8/Documents/MQTTClient\r\n2016-02-04 00:25:41:695 GreenBot[14814:334355] [MQTTCFSocketTransport] open\r\n2016-02-04 00:25:41:695 GreenBot[14814:334355] [MQTTCFSocketTransport] open\r\n2016-02-04 00:25:41:695 GreenBot[14814:334355] [MQTTCFSocketEncoder] setState 0/0\r\n2016-02-04 00:25:41:695 GreenBot[14814:334355] [MQTTCFSocketEncoder] setState 0/0\r\n\r\n```\r\n\r\nSomething appear 2 times, i don't know what i'm doing wrong, please see briefly and give me an advice.\r\n\r\nThank you "},"comment":{"url":"https://api.github.com/repos/ckrey/MQTT-Client-Framework/issues/comments/180227475","html_url":"https://github.com/ckrey/MQTT-Client-Framework/issues/103#issuecomment-180227475","issue_url":"https://api.github.com/repos/ckrey/MQTT-Client-Framework/issues/103","id":180227475,"user":{"login":"tuanpmt","id":1904924,"avatar_url":"https://avatars.githubusercontent.com/u/1904924?v=3","gravatar_id":"","url":"https://api.github.com/users/tuanpmt","html_url":"https://github.com/tuanpmt","followers_url":"https://api.github.com/users/tuanpmt/followers","following_url":"https://api.github.com/users/tuanpmt/following{/other_user}","gists_url":"https://api.github.com/users/tuanpmt/gists{/gist_id}","starred_url":"https://api.github.com/users/tuanpmt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tuanpmt/subscriptions","organizations_url":"https://api.github.com/users/tuanpmt/orgs","repos_url":"https://api.github.com/users/tuanpmt/repos","events_url":"https://api.github.com/users/tuanpmt/events{/privacy}","received_events_url":"https://api.github.com/users/tuanpmt/received_events","type":"User","site_admin":false},"created_at":"2016-02-05T06:56:13Z","updated_at":"2016-02-05T06:56:13Z","body":"It works now with\r\n```c\r\n[[NSOperationQueue mainQueue] addOperationWithBlock:^ {\r\n        [self mqttConnect];\r\n}];\r\n```"}}