UNPKG

1.79 kBPlain TextView Raw
1import { createClient } from "reactotron-core-client"
2import trackGlobalErrors from "./plugins/track-global-errors"
3
4export { trackGlobalErrors }
5
6// ---------------------
7// DEFAULT CONFIGURATION
8// ---------------------
9
10const REACTOTRON_ASYNC_CLIENT_ID = "@REACTOTRON/clientId"
11
12function isBrowser() {
13 return typeof window !== "undefined"
14}
15
16/**
17 * Safely get some information out the the window.navigator.
18 *
19 * @param {string} name The property to get.
20 */
21function getNavigatorProperty(name) {
22 if (!name) return undefined
23 if (!isBrowser()) return undefined
24 if (!window.navigator && typeof window.navigator !== "object") return undefined
25 return window.navigator[name]
26}
27
28const DEFAULTS = {
29 createSocket: (path) => new WebSocket(path), // eslint-disable-line
30 host: "localhost",
31 port: 9090,
32 name: "React JS App",
33 client: {},
34 getClientId: () => {
35 return Promise.resolve(localStorage.getItem(REACTOTRON_ASYNC_CLIENT_ID))
36 },
37 setClientId: (clientId: any) => {
38 localStorage.setItem(REACTOTRON_ASYNC_CLIENT_ID, clientId)
39 return Promise.resolve()
40 },
41}
42
43if (isBrowser()) {
44 DEFAULTS.client = {
45 reactotronLibraryName: "reactotron-react-js",
46 reactotronLibraryVersion: "REACTOTRON_REACT_JS_VERSION",
47 platform: "browser",
48 platformVersion: getNavigatorProperty("platform"),
49 userAgent: getNavigatorProperty("userAgent"),
50 screenWidth: (screen && screen.width) || undefined,
51 screenHeight: (screen && screen.height) || undefined,
52 screenScale: (window && window.devicePixelRatio) || 1,
53 windowWidth: (window && window.innerWidth) || undefined,
54 windowHeight: (window && window.innerHeight) || undefined,
55 }
56}
57
58// -----------
59// HERE WE GO!
60// -----------
61// Create the default reactotron.
62export default createClient(DEFAULTS)