Skip to content

Commit

Permalink
React Native 0.40 fix
Browse files Browse the repository at this point in the history
  • Loading branch information
timhonders committed Jan 26, 2017
1 parent fc8a6a8 commit 33571f2
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 8 additions & 1 deletion ios/RCTReactNativeRabbitMq/RCTReactNativeRabbitMq.h
Original file line number Diff line number Diff line change
@@ -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 <React/RCTBridge.h>
#endif

@interface ReactNativeRabbitMq : NSObject <RCTBridgeModule>

Expand Down
11 changes: 9 additions & 2 deletions ios/RCTReactNativeRabbitMq/RabbitMqConnection.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#import "RCTBridge.h"
#import "RCTEventDispatcher.h"

#ifdef OLDER_IMPORT
#import "RCTBridge.h"
#import "RCTEventDispatcher.h"
#else
#import <React/RCTBridge.h>
#import <React/RCTEventDispatcher.h>
#endif

#import <RMQClient/RMQClient.h>
#import <RMQClient/RMQChannel.h>
#import "RabbitMqQueue.h"
Expand Down
11 changes: 9 additions & 2 deletions ios/RCTReactNativeRabbitMq/RabbitMqDelegateLogger.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#import "RCTBridge.h"
#import "RCTEventDispatcher.h"

#ifdef OLDER_IMPORT
#import "RCTBridge.h"
#import "RCTEventDispatcher.h"
#else
#import <React/RCTBridge.h>
#import <React/RCTEventDispatcher.h>
#endif

#import "RMQConnectionDelegate.h"

@interface RabbitMqDelegateLogger : NSObject <RMQConnectionDelegate>
Expand Down
11 changes: 9 additions & 2 deletions ios/RCTReactNativeRabbitMq/RabbitMqQueue.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#import "RCTBridge.h"
#import "RCTEventDispatcher.h"

#ifdef OLDER_IMPORT
#import "RCTBridge.h"
#import "RCTEventDispatcher.h"
#else
#import <React/RCTBridge.h>
#import <React/RCTEventDispatcher.h>
#endif

#import <RMQClient/RMQClient.h>

@interface RabbitMqQueue : NSObject <RCTBridgeModule>
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
31 changes: 31 additions & 0 deletions scripts/prelink.js
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 33571f2

Please sign in to comment.