From 33571f23484d2193212e13a27c01bc2d645e5da8 Mon Sep 17 00:00:00 2001 From: Tim Honders Date: Thu, 26 Jan 2017 13:53:54 +0100 Subject: [PATCH] React Native 0.40 fix --- .../reactnativerabbitmq/RabbitMqExchange.java | 5 +-- .../RCTReactNativeRabbitMq.h | 9 +++++- .../RabbitMqConnection.h | 11 +++++-- .../RabbitMqDelegateLogger.h | 11 +++++-- ios/RCTReactNativeRabbitMq/RabbitMqQueue.h | 11 +++++-- package.json | 7 ++++- scripts/prelink.js | 31 +++++++++++++++++++ 7 files changed, 75 insertions(+), 10 deletions(-) create mode 100644 scripts/prelink.js diff --git a/android/src/main/java/nl/kega/reactnativerabbitmq/RabbitMqExchange.java b/android/src/main/java/nl/kega/reactnativerabbitmq/RabbitMqExchange.java index 06a7c25..7332448 100644 --- a/android/src/main/java/nl/kega/reactnativerabbitmq/RabbitMqExchange.java +++ b/android/src/main/java/nl/kega/reactnativerabbitmq/RabbitMqExchange.java @@ -53,8 +53,9 @@ public void publish(String message, String routing_key){ byte[] message_body_bytes = message.getBytes(); AMQP.BasicProperties properties = new AMQP.BasicProperties(); - //properties.setExpiration("60000"); - + + // AMQP.BasicProperties properties = new BasicProperties.Builder().expiration("60000").build(); + this.channel.basicPublish(this.name, routing_key, properties, message_body_bytes); } catch (Exception e){ Log.e("RabbitMqExchange", "Exchange publish error " + e); diff --git a/ios/RCTReactNativeRabbitMq/RCTReactNativeRabbitMq.h b/ios/RCTReactNativeRabbitMq/RCTReactNativeRabbitMq.h index 9c344e9..ba4085d 100644 --- a/ios/RCTReactNativeRabbitMq/RCTReactNativeRabbitMq.h +++ b/ios/RCTReactNativeRabbitMq/RCTReactNativeRabbitMq.h @@ -1,4 +1,11 @@ -#import "RCTBridge.h" +//DO NO REMOVE THIS LINE IF YOU'RE USING IT ON RN > 0.40 PROJECT +//#define OLDER_IMPORT + +#ifdef OLDER_IMPORT + #import "RCTBridge.h" +#else + #import +#endif @interface ReactNativeRabbitMq : NSObject diff --git a/ios/RCTReactNativeRabbitMq/RabbitMqConnection.h b/ios/RCTReactNativeRabbitMq/RabbitMqConnection.h index a9ab623..d2230f3 100644 --- a/ios/RCTReactNativeRabbitMq/RabbitMqConnection.h +++ b/ios/RCTReactNativeRabbitMq/RabbitMqConnection.h @@ -1,5 +1,12 @@ -#import "RCTBridge.h" -#import "RCTEventDispatcher.h" + +#ifdef OLDER_IMPORT + #import "RCTBridge.h" + #import "RCTEventDispatcher.h" +#else + #import + #import +#endif + #import #import #import "RabbitMqQueue.h" diff --git a/ios/RCTReactNativeRabbitMq/RabbitMqDelegateLogger.h b/ios/RCTReactNativeRabbitMq/RabbitMqDelegateLogger.h index 59f9b1c..99da939 100644 --- a/ios/RCTReactNativeRabbitMq/RabbitMqDelegateLogger.h +++ b/ios/RCTReactNativeRabbitMq/RabbitMqDelegateLogger.h @@ -1,5 +1,12 @@ -#import "RCTBridge.h" -#import "RCTEventDispatcher.h" + +#ifdef OLDER_IMPORT + #import "RCTBridge.h" + #import "RCTEventDispatcher.h" +#else + #import + #import +#endif + #import "RMQConnectionDelegate.h" @interface RabbitMqDelegateLogger : NSObject diff --git a/ios/RCTReactNativeRabbitMq/RabbitMqQueue.h b/ios/RCTReactNativeRabbitMq/RabbitMqQueue.h index 67728e9..458fb68 100644 --- a/ios/RCTReactNativeRabbitMq/RabbitMqQueue.h +++ b/ios/RCTReactNativeRabbitMq/RabbitMqQueue.h @@ -1,5 +1,12 @@ -#import "RCTBridge.h" -#import "RCTEventDispatcher.h" + +#ifdef OLDER_IMPORT + #import "RCTBridge.h" + #import "RCTEventDispatcher.h" +#else + #import + #import +#endif + #import @interface RabbitMqQueue : NSObject diff --git a/package.json b/package.json index 3d87853..d787630 100644 --- a/package.json +++ b/package.json @@ -82,6 +82,11 @@ "type": "git", "url": "git+https://github.com/kegaretail/react-native-rabbitmq.git" }, + "rnpm": { + "commands": { + "prelink": "node ./node_modules/react-native-rabbitmq/scripts/prelink.js" + } + }, "scripts": {}, - "version": "0.4.3" + "version": "0.5.0" } diff --git a/scripts/prelink.js b/scripts/prelink.js new file mode 100644 index 0000000..21c3c4b --- /dev/null +++ b/scripts/prelink.js @@ -0,0 +1,31 @@ +try { + var fs = require('fs'); + var glob = require('glob'); + var PACKAGE_JSON = process.cwd() + '/package.json'; + var package = JSON.parse(fs.readFileSync(PACKAGE_JSON)); + var APP_NAME = package.name; + var PACKAGE_GRADLE = process.cwd() + '/node_modules/react-native-rabbitmq/android/build.gradle' + var VERSION = checkVersion(); + + if (VERSION < 0.40) { + glob('**/RCTReactNativeRabbitMq.h',{}, function(err, files) { + if(Array.isArray(files)) { + var target = process.cwd() + '/' + files[0]; + console.log('\033[92mPatching .. \033[97m' + target); + var data = fs.readFileSync(target); + fs.writeFileSync(target, String(data).replace(/\/\/#define OLDER_IMPORT/, '#define OLDER_IMPORT')); + console.log('done.') + } + }) + } + + function checkVersion() { + console.log('react-native-rabbitmq checking app version ..'); + return parseFloat(/\d\.\d+(?=\.)/.exec(package.dependencies['react-native'])); + } + +} catch(err) { + console.log( + '\033[95mreact-native-rabbitmq\033[97m link \033[91mFAILED \033[97m\nCould not automatically link package :'+ + err.stack) +}