<commit_before>import React from 'react'
import ReactDOM from 'react-dom'
import createBrowserHistory from 'history/lib/createBrowserHistory'
import { useRouterHistory } from 'react-router'
import { syncHistoryWithStore, push } from 'react-router-redux'
import createStore from './store/createStore'
import AppContainer from './containers/AppContainer'
require('./css/style.css');
import initialState from './store/initialState';
import Firebase from 'firebase';
import { w3cwebsocket as W3cWebSocket } from 'websocket';

import { configureFirebase, saveUid } from './Actions/ChatList';
import { setPresence, counterChanged, counterAdded, counterRemoved } from './Actions/Socket';
import { userRef } from './Actions/Monitors';
import { controlUp, controlDown, controlLeft, controlRight, controlInteract,
  controlStop, controlSetPause, controlSetPlay, stopControl, pause } from './Actions/Videos';

// ========================================================
// Browser History Setup
// ========================================================
const browserHistory = useRouterHistory(createBrowserHistory)({
  basename: __BASENAME__
})

// ========================================================
// Store and History Instantiation
// ========================================================
// Create redux store and sync with react-router-redux. We have installed the
// react-router-redux reducer under the routerKey "router" in src/routes/index.js,
// so we need to provide a custom `selectLocationState` to inform
// react-router-redux of its location.
// const initialState = window.___INITIAL_STATE__
const store = createStore(initialState, browserHistory)
const history = syncHistoryWithStore(browserHistory, store, {
  selectLocationState: (state) => state.router
});

window.onblur = () => {
  store.dispatch(controlStop());
  store.dispatch(pause());
  store.dispatch(controlSetPause());
};
window.onfocus = () => {
  store.dispatch(controlStop());
  store.dispatch(pause());
  store.dispatch(controlSetPlay());
};

// ========================================================
// Firebase Setup
// ========================================================
const fireRef = new Firebase('https://monitor-web.firebaseio.com/records');
const presenceRef = new Firebase('https://monitor-web.firebaseio.com/presence');
const connectedRef = new Firebase('https://monitor-web.firebaseio.com/.info/connected');

store.dispatch(configureFirebase(fireRef));
<commit_msg>onblur changed to visibilitychange<commit_after>import React from 'react'
import ReactDOM from 'react-dom'
import createBrowserHistory from 'history/lib/createBrowserHistory'
import { useRouterHistory } from 'react-router'
import { syncHistoryWithStore, push } from 'react-router-redux'
import createStore from './store/createStore'
import AppContainer from './containers/AppContainer'
require('./css/style.css');
import initialState from './store/initialState';
import Firebase from 'firebase';
import { w3cwebsocket as W3cWebSocket } from 'websocket';

import { configureFirebase, saveUid } from './Actions/ChatList';
import { setPresence, counterChanged, counterAdded, counterRemoved } from './Actions/Socket';
import { userRef } from './Actions/Monitors';
import { controlUp, controlDown, controlLeft, controlRight, controlInteract,
  controlStop, controlSetPause, controlSetPlay, stopControl, pause } from './Actions/Videos';

// ========================================================
// Browser History Setup
// ========================================================
const browserHistory = useRouterHistory(createBrowserHistory)({
  basename: __BASENAME__
})

// ========================================================
// Store and History Instantiation
// ========================================================
// Create redux store and sync with react-router-redux. We have installed the
// react-router-redux reducer under the routerKey "router" in src/routes/index.js,
// so we need to provide a custom `selectLocationState` to inform
// react-router-redux of its location.
// const initialState = window.___INITIAL_STATE__
const store = createStore(initialState, browserHistory)
const history = syncHistoryWithStore(browserHistory, store, {
  selectLocationState: (state) => state.router
});

// ========================================================
// Visibility event
// ========================================================
let hidden, visibilityChange;
if (typeof document.hidden !== "undefined") { // Opera 12.10 and Firefox 18 and later support
  hidden = "hidden";
  visibilityChange = "visibilitychange";
} else if (typeof document.mozHidden !== "undefined") {
  hidden = "mozHidden";
  visibilityChange = "mozvisibilitychange";
} else if (typeof document.msHidden !== "undefined") {
  hidden = "msHidden";
  visibilityChange = "msvisibilitychange";
} else if (typeof document.webkitHidden !== "undefined") {
  hidden = "webkitHidden";
  visibilityChange = "webkitvisibilitychange";
}

document.addEventListener(visibilityChange, () => {
  if (document[hidden]) {
    store.dispatch(controlStop());
    store.dispatch(pause());
    store.dispatch(controlSetPause());
  } else {
    store.dispatch(controlStop());
    store.dispatch(pause());
    store.dispatch(controlSetPlay());
  }
}, false);

// ========================================================
// Firebase Setup
// ========================================================
const fireRef = new Firebase('https://monitor-web.firebaseio.com/records');
const presenceRef = new Firebase('https://monitor-web.firebaseio.com/presence');
const connectedRef = new Firebase('https://monitor-web.firebaseio.com/.info/connected');

store.dispatch(configureFirebase(fireRef));

{'fraction_non_alphanumeric': 0.24786026200873362, 'fraction_numerical': 0.0017467248908296944, 'mean_word_length': 6.193467336683417, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6361996', 'n_tokens_mistral': 1477, 'n_tokens_neox': 1406, 'n_words': 364}