1 | import { createClient } from "reactotron-core-client"
|
2 | import trackGlobalErrors from "./plugins/track-global-errors"
|
3 |
|
4 | export { trackGlobalErrors }
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | const REACTOTRON_ASYNC_CLIENT_ID = "@REACTOTRON/clientId"
|
11 |
|
12 | function isBrowser() {
|
13 | return typeof window !== "undefined"
|
14 | }
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | function 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 |
|
28 | const DEFAULTS = {
|
29 | createSocket: (path) => new WebSocket(path),
|
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 |
|
43 | if (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 |
|
60 |
|
61 |
|
62 | export default createClient(DEFAULTS)
|