@teardown/react-native 1.2.20 → 1.2.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- export * from './debugger-ui';
1
+ export {};
@@ -1,17 +1,2 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
2
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./debugger-ui"), exports);
@@ -1,9 +1,6 @@
1
1
  import type { FunctionComponent, PropsWithChildren } from "react";
2
2
  import type { PluginTuple, TeardownClient } from "../teardown.client";
3
- import type { DebuggerUiOptions } from "../components";
4
- export type TeardownContainerOptions = {
5
- debugger: DebuggerUiOptions;
6
- };
3
+ export type TeardownContainerOptions = {};
7
4
  export type TeardownContainerProps<T extends readonly PluginTuple[]> = PropsWithChildren<{
8
5
  client: TeardownClient<T>;
9
6
  options?: TeardownContainerOptions;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  export * from "./containers";
2
- export * from "./teardown.client";
3
2
  export * from "./plugins";
package/dist/index.js CHANGED
@@ -17,5 +17,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  // export * from './components';
18
18
  __exportStar(require("./containers"), exports);
19
19
  // export * from './services';
20
- __exportStar(require("./teardown.client"), exports);
20
+ // export * from "./teardown.client";
21
21
  __exportStar(require("./plugins"), exports);
@@ -136,9 +136,9 @@ class HTTPPlugin extends teardown_client_1.Plugin {
136
136
  return response;
137
137
  }
138
138
  sendHTTPEvent(httpRequestInfo) {
139
- if (this.client?.debugger) {
140
- this.client.debugger.send("NETWORK_HTTP_REQUEST", httpRequestInfo);
141
- }
139
+ // if (this.client?.debugger) {
140
+ // this.client.debugger.send("NETWORK_HTTP_REQUEST", httpRequestInfo);
141
+ // }
142
142
  }
143
143
  }
144
144
  exports.HTTPPlugin = HTTPPlugin;
@@ -10,10 +10,10 @@ class LoggingPlugin {
10
10
  return new Proxy(original, {
11
11
  apply: (target, thisArg, args) => {
12
12
  target.apply(thisArg, args);
13
- this.client?.debugger?.send("CONSOLE_LOG", {
14
- type: method,
15
- args,
16
- });
13
+ // this.client?.debugger?.send("CONSOLE_LOG", {
14
+ // type: method,
15
+ // args,
16
+ // });
17
17
  },
18
18
  });
19
19
  }
@@ -1,17 +1 @@
1
- import type { IPlugin, TeardownClient } from "../teardown.client";
2
- export declare class WebSocketPlugin implements IPlugin {
3
- private logger;
4
- private client;
5
- private sockets;
6
- constructor();
7
- install(client: TeardownClient<any>): void;
8
- private setupWebSocketInterceptor;
9
- private wsConnectCallback;
10
- private wsSendCallback;
11
- private wsOnMessageCallback;
12
- private wsOnCloseCallback;
13
- private sendOpenEvent;
14
- private sendMessageEvent;
15
- private sendCloseEvent;
16
- disableInterception(): void;
17
- }
1
+ export {};
@@ -1,102 +1,107 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.WebSocketPlugin = void 0;
7
2
  // @ts-ignore
8
- const WebSocketInterceptor_1 = __importDefault(require("react-native/Libraries/WebSocket/WebSocketInterceptor"));
9
- const logger_1 = require("@teardown/logger");
10
- const util_1 = require("@teardown/util");
11
- class WebSocketPlugin {
12
- logger = new logger_1.Logger("WebSocketPlugin");
13
- client = null;
14
- sockets = new Map();
15
- constructor() {
16
- this.setupWebSocketInterceptor();
17
- }
18
- install(client) {
19
- this.client = client;
20
- }
21
- setupWebSocketInterceptor() {
22
- if (WebSocketInterceptor_1.default.isInterceptorEnabled()) {
23
- this.logger.warn("WebSocketInterceptor is already enabled by another library, disable it or run this first when your app loads");
24
- this.disableInterception();
25
- }
26
- WebSocketInterceptor_1.default.setConnectCallback(this.wsConnectCallback);
27
- WebSocketInterceptor_1.default.setSendCallback(this.wsSendCallback);
28
- WebSocketInterceptor_1.default.setOnMessageCallback(this.wsOnMessageCallback);
29
- WebSocketInterceptor_1.default.setOnCloseCallback(this.wsOnCloseCallback);
30
- WebSocketInterceptor_1.default.enableInterception();
31
- this.logger.log("WebSocketInterceptor enabled");
32
- }
33
- wsConnectCallback = (url, protocols, options, socketId) => {
34
- const requestId = util_1.Util.generateUUID();
35
- const socketInfo = {
36
- id: requestId,
37
- url,
38
- protocols,
39
- timestamp: performance.now(),
40
- };
41
- this.sockets.set(socketId, socketInfo);
42
- this.sendOpenEvent(socketInfo);
43
- };
44
- wsSendCallback = (data, socketId) => {
45
- const socket = this.sockets.get(socketId);
46
- if (socket) {
47
- const messageInfo = {
48
- id: socket.id,
49
- data: "", // TODO: Currently getting array buffer length errors here when sending data
50
- timestamp: performance.now(),
51
- direction: "sent",
52
- };
53
- console.log("messageInfo", messageInfo);
54
- // this.sendMessageEvent(messageInfo);
55
- }
56
- };
57
- wsOnMessageCallback = (socketId, message) => {
58
- const socket = this.sockets.get(socketId);
59
- if (socket) {
60
- const messageInfo = {
61
- id: socket.id,
62
- data: "", // TODO: Currently getting array buffer length errors here when sending data
63
- timestamp: performance.now(),
64
- direction: "received",
65
- };
66
- this.sendMessageEvent(messageInfo);
67
- }
68
- };
69
- wsOnCloseCallback = (socketId, event) => {
70
- const socket = this.sockets.get(socketId);
71
- if (socket) {
72
- const closeInfo = {
73
- id: socket.id,
74
- code: event.code,
75
- reason: event.reason,
76
- timestamp: performance.now(),
77
- };
78
- this.sendCloseEvent(closeInfo);
79
- this.sockets.delete(socketId);
80
- }
81
- };
82
- sendOpenEvent(info) {
83
- if (this.client && this.client.debugger) {
84
- this.client.debugger.send("NETWORK_WEBSOCKET_OPEN", info);
85
- }
86
- }
87
- sendMessageEvent(info) {
88
- if (this.client && this.client.debugger) {
89
- this.client.debugger.send("NETWORK_WEBSOCKET_MESSAGE", info);
90
- }
91
- }
92
- sendCloseEvent(info) {
93
- if (this.client && this.client.debugger) {
94
- this.client.debugger.send("NETWORK_WEBSOCKET_CLOSE", info);
95
- }
96
- }
97
- disableInterception() {
98
- WebSocketInterceptor_1.default.disableInterception();
99
- this.sockets.clear();
100
- }
101
- }
102
- exports.WebSocketPlugin = WebSocketPlugin;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ // export class WebSocketPlugin implements IPlugin {
5
+ // private logger = new Logger("WebSocketPlugin");
6
+ // private client: TeardownClient<any> | null = null;
7
+ // private sockets: Map<string, WebSocketInfo> = new Map();
8
+ // constructor() {
9
+ // this.setupWebSocketInterceptor();
10
+ // }
11
+ // install(client: TeardownClient<any>): void {
12
+ // this.client = client;
13
+ // }
14
+ // private setupWebSocketInterceptor(): void {
15
+ // if (WebSocketInterceptor.isInterceptorEnabled()) {
16
+ // this.logger.warn(
17
+ // "WebSocketInterceptor is already enabled by another library, disable it or run this first when your app loads",
18
+ // );
19
+ // this.disableInterception();
20
+ // }
21
+ // WebSocketInterceptor.setConnectCallback(this.wsConnectCallback);
22
+ // WebSocketInterceptor.setSendCallback(this.wsSendCallback);
23
+ // WebSocketInterceptor.setOnMessageCallback(this.wsOnMessageCallback);
24
+ // WebSocketInterceptor.setOnCloseCallback(this.wsOnCloseCallback);
25
+ // WebSocketInterceptor.enableInterception();
26
+ // this.logger.log("WebSocketInterceptor enabled");
27
+ // }
28
+ // private wsConnectCallback = (
29
+ // url: string,
30
+ // protocols: string | string[] | undefined,
31
+ // options: Object,
32
+ // socketId: string,
33
+ // ): void => {
34
+ // const requestId = Util.generateUUID();
35
+ // const socketInfo: WebSocketInfo = {
36
+ // id: requestId,
37
+ // url,
38
+ // protocols,
39
+ // timestamp: performance.now(),
40
+ // };
41
+ // this.sockets.set(socketId, socketInfo);
42
+ // this.sendOpenEvent(socketInfo);
43
+ // };
44
+ // private wsSendCallback = (
45
+ // data: string | ArrayBuffer | ArrayBufferView,
46
+ // socketId: string,
47
+ // ): void => {
48
+ // const socket = this.sockets.get(socketId);
49
+ // if (socket) {
50
+ // const messageInfo: WebSocketMessageInfo = {
51
+ // id: socket.id,
52
+ // data: "", // TODO: Currently getting array buffer length errors here when sending data
53
+ // timestamp: performance.now(),
54
+ // direction: "sent",
55
+ // };
56
+ // console.log("messageInfo", messageInfo);
57
+ // // this.sendMessageEvent(messageInfo);
58
+ // }
59
+ // };
60
+ // private wsOnMessageCallback = (
61
+ // socketId: string,
62
+ // message: WebSocketMessageEvent,
63
+ // ): void => {
64
+ // const socket = this.sockets.get(socketId);
65
+ // if (socket) {
66
+ // const messageInfo: WebSocketMessageInfo = {
67
+ // id: socket.id,
68
+ // data: "", // TODO: Currently getting array buffer length errors here when sending data
69
+ // timestamp: performance.now(),
70
+ // direction: "received",
71
+ // };
72
+ // this.sendMessageEvent(messageInfo);
73
+ // }
74
+ // };
75
+ // private wsOnCloseCallback = (socketId: string, event: any): void => {
76
+ // const socket = this.sockets.get(socketId);
77
+ // if (socket) {
78
+ // const closeInfo: WebSocketCloseInfo = {
79
+ // id: socket.id,
80
+ // code: event.code,
81
+ // reason: event.reason,
82
+ // timestamp: performance.now(),
83
+ // };
84
+ // this.sendCloseEvent(closeInfo);
85
+ // this.sockets.delete(socketId);
86
+ // }
87
+ // };
88
+ // private sendOpenEvent(info: WebSocketInfo): void {
89
+ // // if (this.client && this.client.debugger) {
90
+ // // this.client.debugger.send("NETWORK_WEBSOCKET_OPEN", info);
91
+ // // }
92
+ // }
93
+ // private sendMessageEvent(info: WebSocketMessageInfo): void {
94
+ // // if (this.client && this.client.debugger) {
95
+ // // this.client.debugger.send("NETWORK_WEBSOCKET_MESSAGE", info);
96
+ // // }
97
+ // }
98
+ // private sendCloseEvent(info: WebSocketCloseInfo): void {
99
+ // // if (this.client && this.client.debugger) {
100
+ // // this.client.debugger.send("NETWORK_WEBSOCKET_CLOSE", info);
101
+ // // }
102
+ // }
103
+ // disableInterception(): void {
104
+ // WebSocketInterceptor.disableInterception();
105
+ // this.sockets.clear();
106
+ // }
107
+ // }
@@ -1,5 +1,4 @@
1
1
  import { Logger } from "@teardown/logger";
2
- import { Debugger, type DebuggerOptions } from "./debugger";
3
2
  export interface IPlugin {
4
3
  install?(client: TeardownClient<any>): void;
5
4
  uninstall?(): void;
@@ -24,13 +23,11 @@ type InferPluginsFromArray<T extends readonly PluginTuple[]> = UnionToIntersecti
24
23
  type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
25
24
  export type TeardownClientOptions<T extends readonly PluginTuple[]> = {
26
25
  plugins?: T;
27
- debuggerEnabled?: boolean;
28
26
  loggingEnabled?: boolean;
29
- } & DebuggerOptions;
27
+ };
30
28
  export declare class TeardownClient<T extends readonly PluginTuple[]> {
31
29
  readonly options?: TeardownClientOptions<T> | undefined;
32
30
  logger: Logger;
33
- debugger: Debugger | null;
34
31
  private readonly plugins;
35
32
  api: InferPluginsFromArray<T>;
36
33
  constructor(options?: TeardownClientOptions<T> | undefined);
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createTeardownClient = exports.TeardownClient = exports.Plugin = void 0;
4
4
  const logger_1 = require("@teardown/logger");
5
- const debugger_1 = require("./debugger");
6
5
  class Plugin {
7
6
  logger;
8
7
  constructor(options) {
@@ -13,17 +12,14 @@ exports.Plugin = Plugin;
13
12
  class TeardownClient {
14
13
  options;
15
14
  logger;
16
- debugger;
17
15
  plugins = new Map();
18
16
  api = {};
19
17
  constructor(options) {
20
18
  this.options = options;
21
19
  this.logger = new logger_1.Logger("TeardownClient", options?.loggingEnabled ?? false);
22
- const debuggerEnabled = options?.debuggerEnabled ?? __DEV__;
23
- this.debugger = debuggerEnabled ? new debugger_1.Debugger(options) : null;
24
- options?.plugins?.forEach(([key, plugin]) => {
25
- this.plugins.set(key, plugin);
26
- });
20
+ // options?.plugins?.forEach(([key, plugin]) => {
21
+ // this.plugins.set(key, plugin);
22
+ // });
27
23
  this.installPlugin();
28
24
  }
29
25
  installPlugin() {
@@ -51,14 +47,12 @@ class TeardownClient {
51
47
  }
52
48
  shutdown() {
53
49
  this.uninstallAllPlugins();
54
- this.debugger?.shutdown();
55
50
  }
56
51
  }
57
52
  exports.TeardownClient = TeardownClient;
58
53
  const createTeardownClient = (plugins) => {
59
54
  return new TeardownClient({
60
55
  loggingEnabled: true,
61
- debuggerEnabled: true,
62
56
  plugins,
63
57
  });
64
58
  };
@@ -0,0 +1,5 @@
1
+ export declare const Log: {
2
+ info: (...args: any[]) => void;
3
+ warn: (...args: any[]) => void;
4
+ error: (...args: any[]) => void;
5
+ };
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Log = void 0;
4
+ exports.Log = {
5
+ info: (...args) => console.log(...args),
6
+ warn: (...args) => console.warn(...args),
7
+ error: (...args) => console.error(...args),
8
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teardown/react-native",
3
- "version": "1.2.20",
3
+ "version": "1.2.22",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",
@@ -14,27 +14,36 @@
14
14
  "dist/**/*"
15
15
  ],
16
16
  "dependencies": {
17
- "@teardown/logger": "1.2.20",
18
- "@teardown/util": "1.2.20",
19
- "@teardown/websocket": "1.2.20"
17
+ "@react-native/dev-middleware": "^0.76.1",
18
+ "@teardown/cli": "^1.2.20",
19
+ "@teardown/logger": "1.2.22",
20
+ "@teardown/util": "1.2.22",
21
+ "@teardown/websocket": "1.2.22",
22
+ "async-mutex": "^0.5.0",
23
+ "chalk": "^5.3.0",
24
+ "compression": "^1.7.5",
25
+ "connect": "^3.7.0",
26
+ "debug": "^4.3.7",
27
+ "pretty-format": "^29.7.0",
28
+ "ws": "^8.18.0"
20
29
  },
21
30
  "devDependencies": {
22
- "@teardown/config": "1.2.20",
23
- "@teardown/react-native-ui": "1.2.20",
24
- "@types/react": "^18.3.1",
31
+ "@teardown/config": "1.2.22",
32
+ "@types/compression": "^1.7.5",
33
+ "@types/connect": "^3.4.38",
34
+ "@types/react": "^18.3.12",
25
35
  "@types/react-native": "^0.73.0",
26
36
  "metro-config": "^0.81.0",
27
37
  "react": "^18.3.1",
28
38
  "react-native": "^0.75.4",
29
39
  "react-native-device-info": "^14.0.0",
30
- "react-native-gesture-handler": "^2.20.0",
40
+ "react-native-gesture-handler": "^2.20.2",
31
41
  "typescript": "^5.6.3"
32
42
  },
33
43
  "peerDependencies": {
34
44
  "react": "^18",
35
45
  "react-native": "^0.75",
36
46
  "react-native-device-info": "^14",
37
- "react-native-gesture-handler": "^2",
38
- "@teardown/react-native-ui": "^1"
47
+ "react-native-gesture-handler": "^2"
39
48
  }
40
49
  }
@@ -1,7 +0,0 @@
1
- import { FunctionComponent } from 'react';
2
- export type DebuggerUiPosition = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' | 'center-left' | 'center-right';
3
- export type DebuggerUiOptions = {
4
- enabled?: boolean;
5
- position?: DebuggerUiPosition;
6
- };
7
- export declare const DebuggerUi: FunctionComponent<DebuggerUiOptions>;
@@ -1,147 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DebuggerUi = void 0;
4
- const jsx_runtime_1 = require("react/jsx-runtime");
5
- const react_1 = require("react");
6
- const react_native_1 = require("react-native");
7
- const react_native_safe_area_context_1 = require("react-native-safe-area-context");
8
- const teardown_logo_1 = require("./teardown-logo");
9
- const react_native_gesture_handler_1 = require("react-native-gesture-handler");
10
- const react_native_ui_1 = require("@teardown/react-native-ui");
11
- const teardown_service_1 = require("../services/teardown.service");
12
- const DebuggerUi = props => {
13
- const { enabled = true } = props;
14
- return null;
15
- if (!__DEV__) {
16
- // never render the debugger ui in any mode apart from __DEV__ == true "development"
17
- return null;
18
- }
19
- const isNotEnabled = !enabled;
20
- if (isNotEnabled) {
21
- return null;
22
- }
23
- return (0, jsx_runtime_1.jsx)(DebuggerUiEnabled, { ...props });
24
- };
25
- exports.DebuggerUi = DebuggerUi;
26
- const DebuggerUiEnabled = props => {
27
- const { position } = props;
28
- const safeAreaInsets = (0, react_native_safe_area_context_1.useSafeAreaInsets)();
29
- const bottomSheetRef = (0, react_1.useRef)(null);
30
- return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles.container, pointerEvents: 'box-none', children: (0, jsx_runtime_1.jsx)(react_native_gesture_handler_1.GestureHandlerRootView, { children: (0, jsx_runtime_1.jsxs)(react_native_ui_1.BottomSheetModalProvider, { children: [(0, jsx_runtime_1.jsx)(react_native_1.Pressable, { onPress: () => {
31
- // bottomSheetRef.current?.snapToIndex(0);
32
- }, style: [
33
- styles.orb,
34
- getOrbPosition(safeAreaInsets, position ?? 'center-right'),
35
- ], children: (0, jsx_runtime_1.jsx)(teardown_logo_1.TeardownLogo, { height: 20, width: 20 }) }), (0, jsx_runtime_1.jsxs)(react_native_ui_1.BottomSheet, { sheetRef: bottomSheetRef, handleComponent: handleProps => ((0, jsx_runtime_1.jsx)(DebuggerStatusHandleComponent, { ...handleProps })), children: [(0, jsx_runtime_1.jsx)(react_native_ui_1.BottomSheetCloseIcon, {}), (0, jsx_runtime_1.jsxs)(react_native_ui_1.BottomSheetView, { style: {
36
- paddingBottom: safeAreaInsets.bottom + 16,
37
- }, children: [(0, jsx_runtime_1.jsx)(react_native_ui_1.BottomSheetHeader, { children: (0, jsx_runtime_1.jsx)(react_native_ui_1.BottomSheetTitle, { children: "Debugger" }) }), (0, jsx_runtime_1.jsx)(react_native_ui_1.BottomSheetContent, { children: (0, jsx_runtime_1.jsx)(react_native_ui_1.Button, { onPress: () => {
38
- react_native_1.DevSettings.reload('Teardown reconnect');
39
- }, children: "Reconnect debugger" }) })] })] })] }) }) }) }));
40
- };
41
- const DebuggerStatusHandleComponent = () => {
42
- const { client } = teardown_service_1.TeardownService.useState();
43
- const [debuggerStatus, setDebuggerStatus] = (0, react_1.useState)(client.debugger?.getStatus() ?? null);
44
- (0, react_1.useEffect)(() => {
45
- const listener = client.debugger?.emitter.on("CONNECTION_STATUS_CHANGED", (event) => {
46
- const { payload } = event;
47
- setDebuggerStatus(event.payload.status);
48
- });
49
- return () => {
50
- listener?.remove();
51
- };
52
- }, [client]);
53
- return ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: [
54
- {
55
- backgroundColor: getColorForDebuggerStatus(debuggerStatus),
56
- },
57
- styles.debugger_status,
58
- ], children: (0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.debugger_status_text, children: debuggerStatus }) }));
59
- };
60
- const styles = react_native_1.StyleSheet.create({
61
- debugger_status: {
62
- flex: 1,
63
- borderTopLeftRadius: 15,
64
- borderTopRightRadius: 15,
65
- padding: 4,
66
- },
67
- debugger_status_text: {
68
- color: 'white',
69
- fontSize: 12,
70
- textAlign: 'center',
71
- fontWeight: 'bold',
72
- },
73
- container: {
74
- ...react_native_1.StyleSheet.absoluteFillObject,
75
- backgroundColor: 'white',
76
- },
77
- orb: {
78
- height: 40,
79
- width: 40,
80
- backgroundColor: 'hsl(240 5% 6%)',
81
- borderRadius: 40,
82
- position: 'absolute',
83
- justifyContent: 'center',
84
- alignItems: 'center',
85
- },
86
- half_height: {
87
- height: '50%',
88
- backgroundColor: '#e1e1e1',
89
- position: 'absolute',
90
- left: 0,
91
- right: 0,
92
- bottom: 0,
93
- },
94
- logo: {
95
- height: 20,
96
- width: 20,
97
- },
98
- });
99
- const getColorForDebuggerStatus = (status) => {
100
- switch (status) {
101
- case 'CONNECTING':
102
- return 'yellow';
103
- case 'CONNECTED':
104
- return 'green';
105
- case 'DISCONNECTED':
106
- return 'red';
107
- case 'FAILED':
108
- return 'red';
109
- default:
110
- return 'gray';
111
- }
112
- };
113
- const getOrbPosition = (edgeInsets, position) => {
114
- const DEFAULT_PADDING = 16;
115
- switch (position) {
116
- case 'top-left':
117
- return {
118
- top: DEFAULT_PADDING + edgeInsets.top,
119
- left: DEFAULT_PADDING,
120
- };
121
- case 'top-right':
122
- return {
123
- top: DEFAULT_PADDING + edgeInsets.top,
124
- right: DEFAULT_PADDING,
125
- };
126
- case 'bottom-left':
127
- return {
128
- bottom: DEFAULT_PADDING + edgeInsets.bottom,
129
- left: DEFAULT_PADDING,
130
- };
131
- case 'bottom-right':
132
- return {
133
- bottom: DEFAULT_PADDING + edgeInsets.bottom,
134
- right: DEFAULT_PADDING,
135
- };
136
- case 'center-left':
137
- return {
138
- top: '50%',
139
- left: DEFAULT_PADDING,
140
- };
141
- case 'center-right':
142
- return {
143
- top: '50%',
144
- right: DEFAULT_PADDING,
145
- };
146
- }
147
- };
@@ -1,13 +0,0 @@
1
- import { type ClientWebsocketEvents, type ConnectionEstablishedWebsocketEvent, WebsocketClient, type WebsocketClientOptions, type WebsocketConnectionStatus } from "@teardown/websocket";
2
- export type DebuggerStatus = WebsocketConnectionStatus;
3
- export type DebuggerOptions = WebsocketClientOptions & {
4
- deviceName?: string;
5
- };
6
- export declare class Debugger extends WebsocketClient<ClientWebsocketEvents> {
7
- private readonly customDeviceName?;
8
- constructor(options?: DebuggerOptions);
9
- private getDeviceName;
10
- onConnectionEstablished(event: ConnectionEstablishedWebsocketEvent): Promise<void>;
11
- getHostFromUrl(url: string): string;
12
- getHost(): string;
13
- }
package/dist/debugger.js DELETED
@@ -1,75 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Debugger = void 0;
7
- const logger_1 = require("@teardown/logger");
8
- const websocket_1 = require("@teardown/websocket");
9
- const react_native_1 = require("react-native");
10
- const react_native_device_info_1 = __importDefault(require("react-native-device-info"));
11
- class Debugger extends websocket_1.WebsocketClient {
12
- customDeviceName;
13
- constructor(options) {
14
- super({
15
- logger: new logger_1.Logger("Debugger"),
16
- ...options,
17
- });
18
- this.customDeviceName = options?.deviceName;
19
- }
20
- async getDeviceName() {
21
- if (this.customDeviceName) {
22
- return this.customDeviceName;
23
- }
24
- try {
25
- return await react_native_device_info_1.default.getDeviceName();
26
- }
27
- catch (error) {
28
- return react_native_1.Platform.select({
29
- ios: "iPhone",
30
- android: "Android",
31
- default: "Unknown Device",
32
- });
33
- }
34
- }
35
- async onConnectionEstablished(event) {
36
- const [deviceId, deviceName] = await Promise.all([
37
- react_native_device_info_1.default.getUniqueId(),
38
- this.getDeviceName(),
39
- ]);
40
- this.send("DEVICE_CONNECTION_ESTABLISHED", {
41
- deviceId,
42
- deviceName,
43
- platform: react_native_1.Platform.OS,
44
- platformVersion: react_native_1.Platform.Version,
45
- reactNativeVersion: react_native_1.Platform.constants.reactNativeVersion,
46
- isDisableAnimations: react_native_1.Platform.constants.isDisableAnimations ?? false,
47
- isTesting: react_native_1.Platform.constants.isTesting,
48
- });
49
- }
50
- getHostFromUrl(url) {
51
- const host = url.match(/^(?:https?:\/\/)?(\[[^\]]+\]|[^/:\s]+)(?::\d+)?(?:[/?#]|$)/)?.[1];
52
- if (typeof host !== "string") {
53
- throw new Error("Invalid URL - host not found");
54
- }
55
- return host;
56
- }
57
- getHost() {
58
- try {
59
- // https://github.com/facebook/react-native/blob/2a7f969500cef73b621269299619ee1f0ee9521a/packages/react-native/src/private/specs/modules/NativeSourceCode.js#L16
60
- const scriptURL = react_native_1.NativeModules?.SourceCode?.getConstants().scriptURL;
61
- if (typeof scriptURL !== "string")
62
- throw new Error("Invalid non-string URL");
63
- return this.getHostFromUrl(scriptURL);
64
- }
65
- catch (error) {
66
- const superHost = super.getHost();
67
- const errorMessage = typeof error === "object" && error !== null && "message" in error
68
- ? error.message
69
- : String(error);
70
- this.logger.warn(`Failed to get host: "${errorMessage}" - Falling back to ${superHost}`);
71
- return superHost;
72
- }
73
- }
74
- }
75
- exports.Debugger = Debugger;