Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
zalmoxisus committed Jul 20, 2016
2 parents d500f5f + 36dee74 commit e7627d2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/devTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { stringify, parse } from 'jsan';
import socketCluster from 'socketcluster-client';
import configureStore from './configureStore';
import { defaultSocketOptions } from './constants';
import { getHostForRN } from './utils/reactNative';

const ERROR = '@@remotedev/ERROR';

Expand Down Expand Up @@ -260,7 +261,10 @@ function handleChange(state, liftedState, maxAge) {
}

export default function devTools(options = {}) {
init(options);
init({
...options,
hostname: getHostForRN(options.hostname)
});
const realtime = typeof options.realtime === 'undefined'
? process.env.NODE_ENV === 'development' : options.realtime;
if (!realtime && !(startOn || sendOn || sendOnError)) return f => f;
Expand Down
20 changes: 20 additions & 0 deletions src/utils/reactNative.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Get React Native server IP if hostname is `localhost`
* On Android emulator, the IP of host is `10.0.2.2` (Genymotion: 10.0.3.2)
*/
export function getHostForRN(hostname) {
if (
(hostname === 'localhost' || hostname === '127.0.0.1') &&
typeof window !== 'undefined' &&
window.__fbBatchedBridge &&
window.__fbBatchedBridge.RemoteModules &&
window.__fbBatchedBridge.RemoteModules.AndroidConstants
) {
const {
ServerHost = hostname
} = window.__fbBatchedBridge.RemoteModules.AndroidConstants;
return ServerHost.split(':')[0];
}

return hostname;
}

0 comments on commit e7627d2

Please sign in to comment.