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