2015-12-28 23:34:32 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { render } from 'react-dom';
|
2016-01-15 19:56:03 +00:00
|
|
|
import { browserHistory } from 'react-router';
|
2016-01-26 21:10:44 +00:00
|
|
|
import { routeActions } from 'redux-simple-router';
|
2015-12-28 23:34:32 +00:00
|
|
|
import configureStore from './store';
|
|
|
|
import createRoutes from './routes';
|
|
|
|
import Socket from './util/Socket';
|
|
|
|
import handleSocket from './socket';
|
|
|
|
import Root from './containers/Root';
|
|
|
|
|
2015-12-29 21:23:07 +00:00
|
|
|
const host = __DEV__ ? `${window.location.hostname}:1337` : window.location.host;
|
2016-01-15 01:27:30 +00:00
|
|
|
const socket = new Socket(host);
|
2015-12-28 23:34:32 +00:00
|
|
|
|
2016-01-15 19:56:03 +00:00
|
|
|
const store = configureStore(socket, browserHistory);
|
2016-01-26 21:10:44 +00:00
|
|
|
|
|
|
|
if (window.__ENV__.servers) {
|
|
|
|
store.dispatch({
|
|
|
|
type: 'SOCKET_SERVERS',
|
|
|
|
data: window.__ENV__.servers
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
store.dispatch(routeActions.replace('/connect'));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (window.__ENV__.channels) {
|
|
|
|
store.dispatch({
|
|
|
|
type: 'SOCKET_CHANNELS',
|
|
|
|
data: window.__ENV__.channels
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (window.__ENV__.users) {
|
|
|
|
store.dispatch({
|
|
|
|
type: 'SOCKET_USERS',
|
|
|
|
...window.__ENV__.users
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-01-15 19:56:03 +00:00
|
|
|
handleSocket(socket, store);
|
2015-12-28 23:34:32 +00:00
|
|
|
|
2015-12-29 21:23:07 +00:00
|
|
|
const routes = createRoutes();
|
2015-12-28 23:34:32 +00:00
|
|
|
|
2016-01-15 19:56:03 +00:00
|
|
|
render(
|
|
|
|
<Root store={store} routes={routes} history={browserHistory} />,
|
|
|
|
document.getElementById('root')
|
|
|
|
);
|