react-native-xenon 0.3.0 → 0.4.0
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.
- package/README.md +13 -3
- package/lib/commonjs/contexts/MainContext.js.map +1 -1
- package/lib/commonjs/core/constants.js.map +1 -0
- package/lib/commonjs/core/data.js +10 -0
- package/lib/commonjs/core/data.js.map +1 -0
- package/lib/commonjs/core/global.d.js.map +1 -0
- package/lib/commonjs/{utils.js → core/utils.js} +18 -2
- package/lib/commonjs/core/utils.js.map +1 -0
- package/lib/commonjs/hooks/useConsoleInterceptor.js +8 -5
- package/lib/commonjs/hooks/useConsoleInterceptor.js.map +1 -1
- package/lib/commonjs/hooks/useNetworkInterceptor.js +16 -11
- package/lib/commonjs/hooks/useNetworkInterceptor.js.map +1 -1
- package/lib/commonjs/interceptors/ConsoleInterceptor.js +4 -8
- package/lib/commonjs/interceptors/ConsoleInterceptor.js.map +1 -1
- package/lib/commonjs/interceptors/FetchInterceptor.js +8 -12
- package/lib/commonjs/interceptors/FetchInterceptor.js.map +1 -1
- package/lib/commonjs/interceptors/HttpInterceptor.js +0 -21
- package/lib/commonjs/interceptors/HttpInterceptor.js.map +1 -1
- package/lib/commonjs/interceptors/Interceptor.js +2 -2
- package/lib/commonjs/interceptors/Interceptor.js.map +1 -1
- package/lib/commonjs/interceptors/NetworkInterceptor.js +14 -1
- package/lib/commonjs/interceptors/NetworkInterceptor.js.map +1 -1
- package/lib/commonjs/interceptors/WebSocketInterceptor.js +19 -44
- package/lib/commonjs/interceptors/WebSocketInterceptor.js.map +1 -1
- package/lib/commonjs/interceptors/XHRInterceptor.js +7 -11
- package/lib/commonjs/interceptors/XHRInterceptor.js.map +1 -1
- package/lib/commonjs/theme/colors.js.map +1 -0
- package/lib/commonjs/theme/icons.js +15 -0
- package/lib/commonjs/theme/icons.js.map +1 -0
- package/lib/commonjs/types/common.js.map +1 -1
- package/lib/commonjs/ui/Xenon.js +69 -61
- package/lib/commonjs/ui/Xenon.js.map +1 -1
- package/lib/commonjs/ui/components/bubble/Bubble.js +86 -55
- package/lib/commonjs/ui/components/bubble/Bubble.js.map +1 -1
- package/lib/commonjs/ui/components/details/DetailsViewer.js +6 -11
- package/lib/commonjs/ui/components/details/DetailsViewer.js.map +1 -1
- package/lib/commonjs/ui/components/details/LogMessageDetails.js +2 -2
- package/lib/commonjs/ui/components/details/LogMessageDetails.js.map +1 -1
- package/lib/commonjs/ui/components/details/NetworkRequestDetails.js +22 -7
- package/lib/commonjs/ui/components/details/NetworkRequestDetails.js.map +1 -1
- package/lib/commonjs/ui/components/headers/DebuggerHeader.js +38 -18
- package/lib/commonjs/ui/components/headers/DebuggerHeader.js.map +1 -1
- package/lib/commonjs/ui/components/headers/NetworkPanelHeader.js +1 -1
- package/lib/commonjs/ui/components/headers/NetworkPanelHeader.js.map +1 -1
- package/lib/commonjs/ui/components/headers/NetworkRequestDetailsHeader.js +0 -1
- package/lib/commonjs/ui/components/headers/NetworkRequestDetailsHeader.js.map +1 -1
- package/lib/commonjs/ui/components/items/ConsolePanelItem.js +2 -2
- package/lib/commonjs/ui/components/items/ConsolePanelItem.js.map +1 -1
- package/lib/commonjs/ui/components/items/DebuggerHeaderItem.js +4 -2
- package/lib/commonjs/ui/components/items/DebuggerHeaderItem.js.map +1 -1
- package/lib/commonjs/ui/components/items/NetworkPanelItem.js +2 -2
- package/lib/commonjs/ui/components/items/NetworkPanelItem.js.map +1 -1
- package/lib/commonjs/ui/components/items/NetworkRequestDetailsHeaderItem.js +2 -3
- package/lib/commonjs/ui/components/items/NetworkRequestDetailsHeaderItem.js.map +1 -1
- package/lib/commonjs/ui/components/items/NetworkRequestDetailsItem.js +7 -6
- package/lib/commonjs/ui/components/items/NetworkRequestDetailsItem.js.map +1 -1
- package/lib/commonjs/ui/components/panels/ConsolePanel.js +14 -14
- package/lib/commonjs/ui/components/panels/ConsolePanel.js.map +1 -1
- package/lib/commonjs/ui/components/panels/NetworkPanel.js +15 -17
- package/lib/commonjs/ui/components/panels/NetworkPanel.js.map +1 -1
- package/lib/module/contexts/MainContext.js.map +1 -1
- package/lib/module/core/constants.js.map +1 -0
- package/lib/module/core/data.js +10 -0
- package/lib/module/core/data.js.map +1 -0
- package/lib/module/core/global.d.js.map +1 -0
- package/lib/module/{utils.js → core/utils.js} +18 -2
- package/lib/module/core/utils.js.map +1 -0
- package/lib/module/hooks/useConsoleInterceptor.js +8 -5
- package/lib/module/hooks/useConsoleInterceptor.js.map +1 -1
- package/lib/module/hooks/useNetworkInterceptor.js +16 -11
- package/lib/module/hooks/useNetworkInterceptor.js.map +1 -1
- package/lib/module/interceptors/ConsoleInterceptor.js +4 -8
- package/lib/module/interceptors/ConsoleInterceptor.js.map +1 -1
- package/lib/module/interceptors/FetchInterceptor.js +8 -12
- package/lib/module/interceptors/FetchInterceptor.js.map +1 -1
- package/lib/module/interceptors/HttpInterceptor.js +0 -21
- package/lib/module/interceptors/HttpInterceptor.js.map +1 -1
- package/lib/module/interceptors/Interceptor.js +2 -2
- package/lib/module/interceptors/Interceptor.js.map +1 -1
- package/lib/module/interceptors/NetworkInterceptor.js +14 -1
- package/lib/module/interceptors/NetworkInterceptor.js.map +1 -1
- package/lib/module/interceptors/WebSocketInterceptor.js +19 -44
- package/lib/module/interceptors/WebSocketInterceptor.js.map +1 -1
- package/lib/module/interceptors/XHRInterceptor.js +7 -11
- package/lib/module/interceptors/XHRInterceptor.js.map +1 -1
- package/lib/module/theme/colors.js.map +1 -0
- package/lib/module/theme/icons.js +15 -0
- package/lib/module/theme/icons.js.map +1 -0
- package/lib/module/types/common.js.map +1 -1
- package/lib/module/ui/Xenon.js +69 -61
- package/lib/module/ui/Xenon.js.map +1 -1
- package/lib/module/ui/components/bubble/Bubble.js +86 -55
- package/lib/module/ui/components/bubble/Bubble.js.map +1 -1
- package/lib/module/ui/components/details/DetailsViewer.js +6 -11
- package/lib/module/ui/components/details/DetailsViewer.js.map +1 -1
- package/lib/module/ui/components/details/LogMessageDetails.js +2 -2
- package/lib/module/ui/components/details/LogMessageDetails.js.map +1 -1
- package/lib/module/ui/components/details/NetworkRequestDetails.js +22 -7
- package/lib/module/ui/components/details/NetworkRequestDetails.js.map +1 -1
- package/lib/module/ui/components/headers/DebuggerHeader.js +38 -18
- package/lib/module/ui/components/headers/DebuggerHeader.js.map +1 -1
- package/lib/module/ui/components/headers/NetworkPanelHeader.js +1 -1
- package/lib/module/ui/components/headers/NetworkPanelHeader.js.map +1 -1
- package/lib/module/ui/components/headers/NetworkRequestDetailsHeader.js +0 -1
- package/lib/module/ui/components/headers/NetworkRequestDetailsHeader.js.map +1 -1
- package/lib/module/ui/components/items/ConsolePanelItem.js +2 -2
- package/lib/module/ui/components/items/ConsolePanelItem.js.map +1 -1
- package/lib/module/ui/components/items/DebuggerHeaderItem.js +4 -2
- package/lib/module/ui/components/items/DebuggerHeaderItem.js.map +1 -1
- package/lib/module/ui/components/items/NetworkPanelItem.js +2 -2
- package/lib/module/ui/components/items/NetworkPanelItem.js.map +1 -1
- package/lib/module/ui/components/items/NetworkRequestDetailsHeaderItem.js +2 -3
- package/lib/module/ui/components/items/NetworkRequestDetailsHeaderItem.js.map +1 -1
- package/lib/module/ui/components/items/NetworkRequestDetailsItem.js +7 -6
- package/lib/module/ui/components/items/NetworkRequestDetailsItem.js.map +1 -1
- package/lib/module/ui/components/panels/ConsolePanel.js +14 -14
- package/lib/module/ui/components/panels/ConsolePanel.js.map +1 -1
- package/lib/module/ui/components/panels/NetworkPanel.js +15 -17
- package/lib/module/ui/components/panels/NetworkPanel.js.map +1 -1
- package/lib/typescript/commonjs/src/contexts/MainContext.d.ts +5 -17
- package/lib/typescript/commonjs/src/contexts/MainContext.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/core/constants.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/core/data.d.ts +10 -0
- package/lib/typescript/commonjs/src/core/data.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/{utils.d.ts → core/utils.d.ts} +9 -1
- package/lib/typescript/commonjs/src/core/utils.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/hooks/useConsoleInterceptor.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/hooks/useNetworkInterceptor.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/interceptors/ConsoleInterceptor.d.ts +0 -2
- package/lib/typescript/commonjs/src/interceptors/ConsoleInterceptor.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/interceptors/FetchInterceptor.d.ts +0 -2
- package/lib/typescript/commonjs/src/interceptors/FetchInterceptor.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/interceptors/HttpInterceptor.d.ts +0 -8
- package/lib/typescript/commonjs/src/interceptors/HttpInterceptor.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/interceptors/NetworkInterceptor.d.ts +6 -2
- package/lib/typescript/commonjs/src/interceptors/NetworkInterceptor.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/interceptors/WebSocketInterceptor.d.ts +1 -10
- package/lib/typescript/commonjs/src/interceptors/WebSocketInterceptor.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/interceptors/XHRInterceptor.d.ts +0 -2
- package/lib/typescript/commonjs/src/interceptors/XHRInterceptor.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/theme/colors.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/theme/icons.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/types/common.d.ts +6 -4
- package/lib/typescript/commonjs/src/types/common.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types/http.d.ts +5 -11
- package/lib/typescript/commonjs/src/types/http.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types/websocket.d.ts +7 -15
- package/lib/typescript/commonjs/src/types/websocket.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/ui/Xenon.d.ts +1 -0
- package/lib/typescript/commonjs/src/ui/Xenon.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/ui/components/bubble/Bubble.d.ts +4 -1
- package/lib/typescript/commonjs/src/ui/components/bubble/Bubble.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/ui/components/details/DetailsViewer.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/ui/components/details/NetworkRequestDetails.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/ui/components/headers/DebuggerHeader.d.ts +5 -1
- package/lib/typescript/commonjs/src/ui/components/headers/DebuggerHeader.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/ui/components/headers/NetworkRequestDetailsHeader.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/ui/components/items/NetworkRequestDetailsHeaderItem.d.ts +1 -3
- package/lib/typescript/commonjs/src/ui/components/items/NetworkRequestDetailsHeaderItem.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/ui/components/items/NetworkRequestDetailsItem.d.ts +3 -3
- package/lib/typescript/commonjs/src/ui/components/items/NetworkRequestDetailsItem.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/ui/components/panels/ConsolePanel.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/ui/components/panels/NetworkPanel.d.ts.map +1 -1
- package/lib/typescript/module/src/contexts/MainContext.d.ts +5 -17
- package/lib/typescript/module/src/contexts/MainContext.d.ts.map +1 -1
- package/lib/typescript/module/src/core/constants.d.ts.map +1 -0
- package/lib/typescript/module/src/core/data.d.ts +10 -0
- package/lib/typescript/module/src/core/data.d.ts.map +1 -0
- package/lib/typescript/module/src/{utils.d.ts → core/utils.d.ts} +9 -1
- package/lib/typescript/module/src/core/utils.d.ts.map +1 -0
- package/lib/typescript/module/src/hooks/useConsoleInterceptor.d.ts.map +1 -1
- package/lib/typescript/module/src/hooks/useNetworkInterceptor.d.ts.map +1 -1
- package/lib/typescript/module/src/interceptors/ConsoleInterceptor.d.ts +0 -2
- package/lib/typescript/module/src/interceptors/ConsoleInterceptor.d.ts.map +1 -1
- package/lib/typescript/module/src/interceptors/FetchInterceptor.d.ts +0 -2
- package/lib/typescript/module/src/interceptors/FetchInterceptor.d.ts.map +1 -1
- package/lib/typescript/module/src/interceptors/HttpInterceptor.d.ts +0 -8
- package/lib/typescript/module/src/interceptors/HttpInterceptor.d.ts.map +1 -1
- package/lib/typescript/module/src/interceptors/NetworkInterceptor.d.ts +6 -2
- package/lib/typescript/module/src/interceptors/NetworkInterceptor.d.ts.map +1 -1
- package/lib/typescript/module/src/interceptors/WebSocketInterceptor.d.ts +1 -10
- package/lib/typescript/module/src/interceptors/WebSocketInterceptor.d.ts.map +1 -1
- package/lib/typescript/module/src/interceptors/XHRInterceptor.d.ts +0 -2
- package/lib/typescript/module/src/interceptors/XHRInterceptor.d.ts.map +1 -1
- package/lib/typescript/module/src/theme/colors.d.ts.map +1 -0
- package/lib/typescript/module/src/theme/icons.d.ts.map +1 -0
- package/lib/typescript/module/src/types/common.d.ts +6 -4
- package/lib/typescript/module/src/types/common.d.ts.map +1 -1
- package/lib/typescript/module/src/types/http.d.ts +5 -11
- package/lib/typescript/module/src/types/http.d.ts.map +1 -1
- package/lib/typescript/module/src/types/websocket.d.ts +7 -15
- package/lib/typescript/module/src/types/websocket.d.ts.map +1 -1
- package/lib/typescript/module/src/ui/Xenon.d.ts +1 -0
- package/lib/typescript/module/src/ui/Xenon.d.ts.map +1 -1
- package/lib/typescript/module/src/ui/components/bubble/Bubble.d.ts +4 -1
- package/lib/typescript/module/src/ui/components/bubble/Bubble.d.ts.map +1 -1
- package/lib/typescript/module/src/ui/components/details/DetailsViewer.d.ts.map +1 -1
- package/lib/typescript/module/src/ui/components/details/NetworkRequestDetails.d.ts.map +1 -1
- package/lib/typescript/module/src/ui/components/headers/DebuggerHeader.d.ts +5 -1
- package/lib/typescript/module/src/ui/components/headers/DebuggerHeader.d.ts.map +1 -1
- package/lib/typescript/module/src/ui/components/headers/NetworkRequestDetailsHeader.d.ts.map +1 -1
- package/lib/typescript/module/src/ui/components/items/NetworkRequestDetailsHeaderItem.d.ts +1 -3
- package/lib/typescript/module/src/ui/components/items/NetworkRequestDetailsHeaderItem.d.ts.map +1 -1
- package/lib/typescript/module/src/ui/components/items/NetworkRequestDetailsItem.d.ts +3 -3
- package/lib/typescript/module/src/ui/components/items/NetworkRequestDetailsItem.d.ts.map +1 -1
- package/lib/typescript/module/src/ui/components/panels/ConsolePanel.d.ts.map +1 -1
- package/lib/typescript/module/src/ui/components/panels/NetworkPanel.d.ts.map +1 -1
- package/package.json +5 -3
- package/src/contexts/MainContext.ts +6 -25
- package/src/core/data.ts +12 -0
- package/src/{utils.ts → core/utils.ts} +21 -1
- package/src/hooks/useConsoleInterceptor.ts +9 -6
- package/src/hooks/useNetworkInterceptor.ts +21 -14
- package/src/interceptors/ConsoleInterceptor.ts +2 -7
- package/src/interceptors/FetchInterceptor.ts +12 -12
- package/src/interceptors/HttpInterceptor.ts +0 -24
- package/src/interceptors/Interceptor.ts +2 -2
- package/src/interceptors/NetworkInterceptor.ts +17 -2
- package/src/interceptors/WebSocketInterceptor.ts +15 -38
- package/src/interceptors/XHRInterceptor.ts +5 -10
- package/src/theme/icons.ts +9 -0
- package/src/types/common.ts +8 -8
- package/src/types/http.ts +22 -34
- package/src/types/websocket.ts +14 -32
- package/src/ui/Xenon.tsx +83 -71
- package/src/ui/components/bubble/Bubble.tsx +96 -56
- package/src/ui/components/details/DetailsViewer.tsx +6 -9
- package/src/ui/components/details/LogMessageDetails.tsx +2 -2
- package/src/ui/components/details/NetworkRequestDetails.tsx +26 -9
- package/src/ui/components/headers/DebuggerHeader.tsx +46 -24
- package/src/ui/components/headers/NetworkPanelHeader.tsx +1 -1
- package/src/ui/components/headers/NetworkRequestDetailsHeader.tsx +0 -1
- package/src/ui/components/items/ConsolePanelItem.tsx +2 -2
- package/src/ui/components/items/DebuggerHeaderItem.tsx +3 -1
- package/src/ui/components/items/NetworkPanelItem.tsx +2 -2
- package/src/ui/components/items/NetworkRequestDetailsHeaderItem.tsx +1 -5
- package/src/ui/components/items/NetworkRequestDetailsItem.tsx +7 -7
- package/src/ui/components/panels/ConsolePanel.tsx +15 -15
- package/src/ui/components/panels/NetworkPanel.tsx +18 -22
- package/lib/commonjs/colors.js.map +0 -1
- package/lib/commonjs/constants.js.map +0 -1
- package/lib/commonjs/global.d.js.map +0 -1
- package/lib/commonjs/icons.js +0 -15
- package/lib/commonjs/icons.js.map +0 -1
- package/lib/commonjs/utils.js.map +0 -1
- package/lib/module/colors.js.map +0 -1
- package/lib/module/constants.js.map +0 -1
- package/lib/module/global.d.js.map +0 -1
- package/lib/module/icons.js +0 -15
- package/lib/module/icons.js.map +0 -1
- package/lib/module/utils.js.map +0 -1
- package/lib/typescript/commonjs/src/colors.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/constants.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/icons.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/utils.d.ts.map +0 -1
- package/lib/typescript/module/src/colors.d.ts.map +0 -1
- package/lib/typescript/module/src/constants.d.ts.map +0 -1
- package/lib/typescript/module/src/icons.d.ts.map +0 -1
- package/lib/typescript/module/src/utils.d.ts.map +0 -1
- package/src/icons.ts +0 -9
- /package/lib/commonjs/{constants.js → core/constants.js} +0 -0
- /package/lib/commonjs/{global.d.js → core/global.d.js} +0 -0
- /package/lib/commonjs/{colors.js → theme/colors.js} +0 -0
- /package/lib/module/{constants.js → core/constants.js} +0 -0
- /package/lib/module/{global.d.js → core/global.d.js} +0 -0
- /package/lib/module/{colors.js → theme/colors.js} +0 -0
- /package/lib/typescript/commonjs/src/{constants.d.ts → core/constants.d.ts} +0 -0
- /package/lib/typescript/commonjs/src/{colors.d.ts → theme/colors.d.ts} +0 -0
- /package/lib/typescript/commonjs/src/{icons.d.ts → theme/icons.d.ts} +0 -0
- /package/lib/typescript/module/src/{constants.d.ts → core/constants.d.ts} +0 -0
- /package/lib/typescript/module/src/{colors.d.ts → theme/colors.d.ts} +0 -0
- /package/lib/typescript/module/src/{icons.d.ts → theme/icons.d.ts} +0 -0
- /package/src/{constants.ts → core/constants.ts} +0 -0
- /package/src/{global.d.ts → core/global.d.ts} +0 -0
- /package/src/{colors.ts → theme/colors.ts} +0 -0
@@ -1,6 +1,21 @@
|
|
1
1
|
import Interceptor from './Interceptor';
|
2
2
|
|
3
|
+
type Callbacks<T> = { [K in keyof T as `${string & K}Callback`]: T[K] };
|
4
|
+
|
3
5
|
export abstract class NetworkInterceptor<T extends Object> extends Interceptor<T> {
|
4
|
-
protected
|
5
|
-
|
6
|
+
protected getCallbacks(): Callbacks<T> {
|
7
|
+
const callbacks = {} as Callbacks<T>;
|
8
|
+
|
9
|
+
for (const key in this.handlers) {
|
10
|
+
(callbacks as any)[`${key}Callback`] = this.handlers[key as keyof T];
|
11
|
+
}
|
12
|
+
|
13
|
+
return callbacks;
|
14
|
+
}
|
15
|
+
|
16
|
+
protected clearCallbacks(): void {
|
17
|
+
for (const key in this.handlers) {
|
18
|
+
(this.handlers as any)[key] = null;
|
19
|
+
}
|
20
|
+
}
|
6
21
|
}
|
@@ -1,17 +1,16 @@
|
|
1
1
|
import { NativeEventEmitter, type EmitterSubscription } from 'react-native';
|
2
2
|
import NativeWebSocketModule from 'react-native/Libraries/WebSocket/NativeWebSocketModule';
|
3
|
+
import { frozen, singleton } from '../core/utils';
|
3
4
|
import type { WebSocketHandlers } from '../types';
|
4
5
|
import { NetworkInterceptor } from './NetworkInterceptor';
|
5
|
-
import { frozen } from '../utils';
|
6
6
|
|
7
7
|
const originalWebSocketConnect = NativeWebSocketModule.connect;
|
8
8
|
const originalWebSocketSend = NativeWebSocketModule.send;
|
9
9
|
const originalWebSocketSendBinary = NativeWebSocketModule.sendBinary;
|
10
10
|
const originalWebSocketClose = NativeWebSocketModule.close;
|
11
11
|
|
12
|
+
@singleton
|
12
13
|
export default class WebSocketInterceptor extends NetworkInterceptor<WebSocketHandlers> {
|
13
|
-
static readonly instance = new WebSocketInterceptor();
|
14
|
-
|
15
14
|
protected handlers: WebSocketHandlers = {
|
16
15
|
connect: null,
|
17
16
|
send: null,
|
@@ -22,32 +21,9 @@ export default class WebSocketInterceptor extends NetworkInterceptor<WebSocketHa
|
|
22
21
|
onClose: null,
|
23
22
|
};
|
24
23
|
|
25
|
-
private constructor() {
|
26
|
-
super();
|
27
|
-
}
|
28
|
-
|
29
|
-
protected getCallbacks() {
|
30
|
-
const connect = this.handlers.connect;
|
31
|
-
const send = this.handlers.send;
|
32
|
-
const close = this.handlers.close;
|
33
|
-
const arrayBufferToString = this.arrayBufferToString;
|
34
|
-
|
35
|
-
return { connect, send, close, arrayBufferToString };
|
36
|
-
}
|
37
|
-
|
38
|
-
protected clearCallbacks(): void {
|
39
|
-
this.handlers.connect = null;
|
40
|
-
this.handlers.send = null;
|
41
|
-
this.handlers.close = null;
|
42
|
-
this.handlers.onOpen = null;
|
43
|
-
this.handlers.onMessage = null;
|
44
|
-
this.handlers.onError = null;
|
45
|
-
this.handlers.onClose = null;
|
46
|
-
}
|
47
|
-
|
48
24
|
private eventEmitter: NativeEventEmitter | null = null;
|
49
25
|
private subscriptions: EmitterSubscription[] = [];
|
50
|
-
private readonly
|
26
|
+
private readonly startTimes: Map<number, number> = new Map();
|
51
27
|
|
52
28
|
private arrayBufferToString(data?: string) {
|
53
29
|
try {
|
@@ -68,10 +44,10 @@ export default class WebSocketInterceptor extends NetworkInterceptor<WebSocketHa
|
|
68
44
|
|
69
45
|
this.subscriptions = [
|
70
46
|
this.eventEmitter.addListener('websocketOpen', ev => {
|
71
|
-
const
|
72
|
-
const
|
73
|
-
const duration =
|
74
|
-
this.
|
47
|
+
const startTime = this.startTimes.get(ev.id);
|
48
|
+
const endTime = Date.now();
|
49
|
+
const duration = endTime - (startTime ?? 0);
|
50
|
+
this.startTimes.delete(ev.id);
|
75
51
|
|
76
52
|
this.handlers.onOpen?.(ev.id, duration);
|
77
53
|
}),
|
@@ -104,31 +80,32 @@ export default class WebSocketInterceptor extends NetworkInterceptor<WebSocketHa
|
|
104
80
|
|
105
81
|
this.registerEvents();
|
106
82
|
|
107
|
-
const {
|
83
|
+
const { connectCallback, sendCallback, closeCallback } = this.getCallbacks();
|
108
84
|
|
109
|
-
const
|
85
|
+
const startTimes = this.startTimes;
|
110
86
|
NativeWebSocketModule.connect = function (...args) {
|
111
|
-
|
87
|
+
connectCallback?.(...args);
|
112
88
|
|
113
|
-
|
89
|
+
startTimes.set(args[3], Date.now());
|
114
90
|
|
115
91
|
originalWebSocketConnect.call(this, ...args);
|
116
92
|
};
|
117
93
|
|
118
94
|
NativeWebSocketModule.send = function (...args) {
|
119
|
-
|
95
|
+
sendCallback?.(...args);
|
120
96
|
|
121
97
|
originalWebSocketSend.call(this, ...args);
|
122
98
|
};
|
123
99
|
|
100
|
+
const arrayBufferToString = this.arrayBufferToString;
|
124
101
|
NativeWebSocketModule.sendBinary = function (base64String, socketId) {
|
125
|
-
|
102
|
+
sendCallback?.(arrayBufferToString(base64String), socketId);
|
126
103
|
|
127
104
|
originalWebSocketSendBinary.call(this, base64String, socketId);
|
128
105
|
};
|
129
106
|
|
130
107
|
NativeWebSocketModule.close = function (code, reason, socketId) {
|
131
|
-
|
108
|
+
closeCallback?.(code, reason, socketId);
|
132
109
|
|
133
110
|
originalWebSocketClose.call(this, code, reason, socketId);
|
134
111
|
};
|
@@ -1,18 +1,13 @@
|
|
1
|
+
import { frozen, getHttpInterceptorId, singleton } from '../core/utils';
|
1
2
|
import { NetworkType } from '../types';
|
2
|
-
import { frozen, getHttpInterceptorId } from '../utils';
|
3
3
|
import HttpInterceptor from './HttpInterceptor';
|
4
4
|
|
5
5
|
const originalXHROpen = XMLHttpRequest.prototype.open;
|
6
6
|
const originalXHRSend = XMLHttpRequest.prototype.send;
|
7
7
|
const originalXHRSetRequestHeader = XMLHttpRequest.prototype.setRequestHeader;
|
8
8
|
|
9
|
+
@singleton
|
9
10
|
export default class XHRInterceptor extends HttpInterceptor {
|
10
|
-
static readonly instance = new XHRInterceptor();
|
11
|
-
|
12
|
-
private constructor() {
|
13
|
-
super();
|
14
|
-
}
|
15
|
-
|
16
11
|
@frozen
|
17
12
|
enableInterception() {
|
18
13
|
if (this.isInterceptorEnabled) return;
|
@@ -44,7 +39,7 @@ export default class XHRInterceptor extends HttpInterceptor {
|
|
44
39
|
XMLHttpRequest.prototype.send = function (data) {
|
45
40
|
sendCallback?.(this._interceptionId, data);
|
46
41
|
|
47
|
-
const
|
42
|
+
const startTime = Date.now();
|
48
43
|
|
49
44
|
this.addEventListener?.('readystatechange', () => {
|
50
45
|
if (!isInterceptorEnabled()) return;
|
@@ -68,8 +63,8 @@ export default class XHRInterceptor extends HttpInterceptor {
|
|
68
63
|
}
|
69
64
|
|
70
65
|
if (this.readyState === this.DONE) {
|
71
|
-
const
|
72
|
-
const duration =
|
66
|
+
const endTime = Date.now();
|
67
|
+
const duration = endTime - startTime;
|
73
68
|
|
74
69
|
responseCallback?.(
|
75
70
|
this._interceptionId,
|
@@ -0,0 +1,9 @@
|
|
1
|
+
const icons = Object.freeze({
|
2
|
+
bug: require('../assets/icons/bug.png'),
|
3
|
+
delete: require('../assets/icons/delete.png'),
|
4
|
+
hide: require('../assets/icons/hide.png'),
|
5
|
+
move: require('../assets/icons/move.png'),
|
6
|
+
record: require('../assets/icons/record.png'),
|
7
|
+
});
|
8
|
+
|
9
|
+
export default icons;
|
package/src/types/common.ts
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
import type { Dispatch, SetStateAction } from 'react';
|
2
|
-
|
3
1
|
export enum NetworkType {
|
4
2
|
XHR = 'xhr',
|
5
3
|
Fetch = 'fetch',
|
@@ -11,6 +9,8 @@ export enum DebuggerPanel {
|
|
11
9
|
Console = 'console',
|
12
10
|
}
|
13
11
|
|
12
|
+
export type AnyFunction = (...args: any[]) => any;
|
13
|
+
|
14
14
|
export type ID = string | undefined;
|
15
15
|
|
16
16
|
export interface NetworkRequest {
|
@@ -19,10 +19,10 @@ export interface NetworkRequest {
|
|
19
19
|
duration?: number;
|
20
20
|
}
|
21
21
|
|
22
|
-
export type DebuggerVisibility = 'hidden' | 'bubble' | 'panel';
|
23
|
-
|
24
|
-
export type DebuggerPosition = 'top' | 'bottom';
|
25
|
-
|
26
|
-
export type SetState<T> = Dispatch<SetStateAction<T>>;
|
27
|
-
|
28
22
|
export type NetworkTab = 'headers' | 'queryStringParameters' | 'body' | 'response' | 'messages';
|
23
|
+
|
24
|
+
export interface DebuggerState {
|
25
|
+
visibility: 'hidden' | 'bubble' | 'panel';
|
26
|
+
position: 'top' | 'bottom';
|
27
|
+
selectedPanel: DebuggerPanel | null;
|
28
|
+
}
|
package/src/types/http.ts
CHANGED
@@ -14,39 +14,27 @@ export interface HttpRequest extends NetworkRequest {
|
|
14
14
|
responseType?: string;
|
15
15
|
}
|
16
16
|
|
17
|
-
type HttpOpenCallback =
|
18
|
-
| ((id: ID, type: HttpRequest['type'], method: string, url: string) => void)
|
19
|
-
| null;
|
20
|
-
|
21
|
-
type HttpRequestHeaderCallback = ((id: ID, header: string, value: string) => void) | null;
|
22
|
-
|
23
|
-
type HttpSendCallback = ((id: ID, data?: any) => void) | null;
|
24
|
-
|
25
|
-
type HttpHeaderReceivedCallback =
|
26
|
-
| ((
|
27
|
-
id: ID,
|
28
|
-
responseContentType: string | undefined,
|
29
|
-
responseSize: number | undefined,
|
30
|
-
responseHeaders: string,
|
31
|
-
) => void)
|
32
|
-
| null;
|
33
|
-
|
34
|
-
type HttpResponseCallback =
|
35
|
-
| ((
|
36
|
-
id: ID,
|
37
|
-
status: number | undefined,
|
38
|
-
timeout: number | undefined,
|
39
|
-
duration: number,
|
40
|
-
response: any,
|
41
|
-
responseURL: string | undefined,
|
42
|
-
responseType: string | undefined,
|
43
|
-
) => void)
|
44
|
-
| null;
|
45
|
-
|
46
17
|
export interface HttpHandlers {
|
47
|
-
open:
|
48
|
-
requestHeader:
|
49
|
-
send:
|
50
|
-
headerReceived:
|
51
|
-
|
18
|
+
open: ((id: ID, type: HttpRequest['type'], method: string, url: string) => void) | null;
|
19
|
+
requestHeader: ((id: ID, header: string, value: string) => void) | null;
|
20
|
+
send: ((id: ID, data?: any) => void) | null;
|
21
|
+
headerReceived:
|
22
|
+
| ((
|
23
|
+
id: ID,
|
24
|
+
responseContentType: string | undefined,
|
25
|
+
responseSize: number | undefined,
|
26
|
+
responseHeaders: string,
|
27
|
+
) => void)
|
28
|
+
| null;
|
29
|
+
response:
|
30
|
+
| ((
|
31
|
+
id: ID,
|
32
|
+
status: number | undefined,
|
33
|
+
timeout: number | undefined,
|
34
|
+
duration: number,
|
35
|
+
response: any,
|
36
|
+
responseURL: string | undefined,
|
37
|
+
responseType: string | undefined,
|
38
|
+
) => void)
|
39
|
+
| null;
|
52
40
|
}
|
package/src/types/websocket.ts
CHANGED
@@ -13,37 +13,19 @@ export interface WebSocketRequest extends NetworkRequest {
|
|
13
13
|
serverClose?: { code?: number; reason?: string };
|
14
14
|
}
|
15
15
|
|
16
|
-
type WebSocketConnectCallback =
|
17
|
-
| ((
|
18
|
-
url: string,
|
19
|
-
protocols?: WebSocketRequest['protocols'],
|
20
|
-
options?: WebSocketRequest['options'],
|
21
|
-
socketId?: number,
|
22
|
-
) => void)
|
23
|
-
| null;
|
24
|
-
|
25
|
-
type WebSocketSendCallback = ((data: string, socketId: number) => void) | null;
|
26
|
-
|
27
|
-
type WebSocketCloseCallback = ((code: number, reason: string, socketId: number) => void) | null;
|
28
|
-
|
29
|
-
type WebSocketOnOpenCallback = ((socketId: number, duration: number) => void) | null;
|
30
|
-
|
31
|
-
type WebSocketOnMessageCallback = ((socketId: number, message: any) => void) | null;
|
32
|
-
|
33
|
-
type WebSocketOnErrorCallback =
|
34
|
-
| ((socketId: number, error: WebSocketRequest['serverError']) => void)
|
35
|
-
| null;
|
36
|
-
|
37
|
-
type WebSocketOnCloseCallback =
|
38
|
-
| ((socketId: number, data: WebSocketRequest['serverClose']) => void)
|
39
|
-
| null;
|
40
|
-
|
41
16
|
export interface WebSocketHandlers {
|
42
|
-
connect:
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
17
|
+
connect:
|
18
|
+
| ((
|
19
|
+
url: string,
|
20
|
+
protocols?: WebSocketRequest['protocols'],
|
21
|
+
options?: WebSocketRequest['options'],
|
22
|
+
socketId?: number,
|
23
|
+
) => void)
|
24
|
+
| null;
|
25
|
+
send: ((data: string, socketId: number) => void) | null;
|
26
|
+
close: ((code: number, reason: string, socketId: number) => void) | null;
|
27
|
+
onOpen: ((socketId: number, duration: number) => void) | null;
|
28
|
+
onMessage: ((socketId: number, message: any) => void) | null;
|
29
|
+
onError: ((socketId: number, error: WebSocketRequest['serverError']) => void) | null;
|
30
|
+
onClose: ((socketId: number, data: WebSocketRequest['serverClose']) => void) | null;
|
49
31
|
}
|
package/src/ui/Xenon.tsx
CHANGED
@@ -3,15 +3,19 @@ import {
|
|
3
3
|
createRef,
|
4
4
|
memo,
|
5
5
|
useImperativeHandle,
|
6
|
+
useMemo,
|
6
7
|
useRef,
|
7
|
-
useState,
|
8
8
|
type NamedExoticComponent,
|
9
9
|
} from 'react';
|
10
|
-
import { Animated,
|
11
|
-
import
|
12
|
-
import
|
10
|
+
import { Animated, StyleSheet, useWindowDimensions } from 'react-native';
|
11
|
+
import { SafeAreaProvider, SafeAreaView } from 'react-native-safe-area-context';
|
12
|
+
import { useImmer } from 'use-immer';
|
13
|
+
import MainContext from '../contexts/MainContext';
|
14
|
+
import { detailsData } from '../core/data';
|
15
|
+
import { getVerticalSafeMargin } from '../core/utils';
|
13
16
|
import { useConsoleInterceptor, useNetworkInterceptor } from '../hooks';
|
14
|
-
import
|
17
|
+
import colors from '../theme/colors';
|
18
|
+
import { DebuggerPanel, type DebuggerState } from '../types';
|
15
19
|
import { Bubble, ConsolePanel, DebuggerHeader, DetailsViewer, NetworkPanel } from './components';
|
16
20
|
|
17
21
|
interface XenonComponentMethods {
|
@@ -24,6 +28,7 @@ interface XenonComponentProps {
|
|
24
28
|
autoInspectNetworkEnabled?: boolean;
|
25
29
|
autoInspectConsoleEnabled?: boolean;
|
26
30
|
bubbleSize?: number;
|
31
|
+
idleBubbleOpacity?: number;
|
27
32
|
}
|
28
33
|
|
29
34
|
interface ReactNativeXenon extends XenonComponentMethods {
|
@@ -35,14 +40,25 @@ enableMapSet();
|
|
35
40
|
const rootRef = createRef<XenonComponentMethods>();
|
36
41
|
|
37
42
|
const XenonComponent = memo<XenonComponentProps>(
|
38
|
-
({
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
const
|
45
|
-
const
|
43
|
+
({
|
44
|
+
autoInspectNetworkEnabled = true,
|
45
|
+
autoInspectConsoleEnabled = true,
|
46
|
+
bubbleSize = 40,
|
47
|
+
idleBubbleOpacity = 0.5,
|
48
|
+
}) => {
|
49
|
+
const { width, height } = useWindowDimensions();
|
50
|
+
const pan = useRef(new Animated.ValueXY({ x: 0, y: getVerticalSafeMargin(height) }));
|
51
|
+
|
52
|
+
const [debuggerState, setDebuggerState] = useImmer<DebuggerState>({
|
53
|
+
visibility: 'hidden',
|
54
|
+
position: 'bottom',
|
55
|
+
selectedPanel: DebuggerPanel.Network,
|
56
|
+
});
|
57
|
+
|
58
|
+
const detailsShown = useMemo(
|
59
|
+
() => !debuggerState.selectedPanel && !!detailsData.value,
|
60
|
+
[debuggerState.selectedPanel],
|
61
|
+
);
|
46
62
|
|
47
63
|
const networkInterceptor = useNetworkInterceptor({
|
48
64
|
autoEnabled: autoInspectNetworkEnabled,
|
@@ -52,72 +68,70 @@ const XenonComponent = memo<XenonComponentProps>(
|
|
52
68
|
autoEnabled: autoInspectConsoleEnabled,
|
53
69
|
});
|
54
70
|
|
55
|
-
useImperativeHandle(
|
56
|
-
|
57
|
-
|
71
|
+
useImperativeHandle(rootRef, () => {
|
72
|
+
const changeVisibility = (condition: boolean, value: DebuggerState['visibility']) => {
|
73
|
+
if (!condition) return;
|
74
|
+
|
75
|
+
setDebuggerState(draft => {
|
76
|
+
draft.visibility = value;
|
77
|
+
});
|
78
|
+
};
|
79
|
+
|
80
|
+
return {
|
58
81
|
isVisible() {
|
59
|
-
return
|
82
|
+
return debuggerState.visibility !== 'hidden';
|
60
83
|
},
|
61
84
|
show() {
|
62
|
-
|
85
|
+
changeVisibility(!this.isVisible(), 'bubble');
|
63
86
|
},
|
64
87
|
hide() {
|
65
|
-
|
88
|
+
changeVisibility(this.isVisible(), 'hidden');
|
66
89
|
},
|
67
|
-
}
|
68
|
-
|
69
|
-
);
|
90
|
+
};
|
91
|
+
}, [debuggerState.visibility, setDebuggerState]);
|
70
92
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
{
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
93
|
+
const renderContent = () => {
|
94
|
+
switch (debuggerState.visibility) {
|
95
|
+
case 'bubble':
|
96
|
+
return (
|
97
|
+
<Bubble
|
98
|
+
bubbleSize={bubbleSize}
|
99
|
+
idleBubbleOpacity={idleBubbleOpacity}
|
100
|
+
pan={pan}
|
101
|
+
screenWidth={width}
|
102
|
+
screenHeight={height}
|
103
|
+
/>
|
104
|
+
);
|
105
|
+
case 'panel':
|
106
|
+
return (
|
107
|
+
<SafeAreaProvider
|
108
|
+
style={[
|
109
|
+
styles.container,
|
110
|
+
// eslint-disable-next-line react-native/no-inline-styles
|
111
|
+
{
|
112
|
+
[debuggerState.position]: 0,
|
113
|
+
height: Math.min(width, height) * 0.75,
|
114
|
+
},
|
115
|
+
]}
|
116
|
+
>
|
117
|
+
<SafeAreaView style={styles.safeArea}>
|
118
|
+
<DebuggerHeader detailsShown={detailsShown} />
|
119
|
+
{debuggerState.selectedPanel === DebuggerPanel.Network && <NetworkPanel />}
|
120
|
+
{debuggerState.selectedPanel === DebuggerPanel.Console && <ConsolePanel />}
|
121
|
+
{detailsShown && <DetailsViewer />}
|
122
|
+
</SafeAreaView>
|
123
|
+
</SafeAreaProvider>
|
124
|
+
);
|
125
|
+
default:
|
126
|
+
return null;
|
127
|
+
}
|
128
|
+
};
|
102
129
|
|
103
130
|
return (
|
104
131
|
<MainContext.Provider
|
105
|
-
value={{
|
106
|
-
debuggerVisibility,
|
107
|
-
setDebuggerVisibility,
|
108
|
-
debuggerPosition,
|
109
|
-
setDebuggerPosition,
|
110
|
-
panelSelected,
|
111
|
-
setPanelSelected,
|
112
|
-
networkInterceptor,
|
113
|
-
logInterceptor,
|
114
|
-
detailsData,
|
115
|
-
screenWidth,
|
116
|
-
screenHeight,
|
117
|
-
verticalSafeMargin,
|
118
|
-
}}
|
132
|
+
value={{ debuggerState, setDebuggerState, networkInterceptor, logInterceptor }}
|
119
133
|
>
|
120
|
-
{
|
134
|
+
{renderContent()}
|
121
135
|
</MainContext.Provider>
|
122
136
|
);
|
123
137
|
},
|
@@ -132,10 +146,8 @@ const styles = StyleSheet.create({
|
|
132
146
|
zIndex: 9999,
|
133
147
|
backgroundColor: colors.lightGray,
|
134
148
|
},
|
135
|
-
|
149
|
+
safeArea: {
|
136
150
|
flex: 1,
|
137
|
-
...StyleSheet.absoluteFillObject,
|
138
|
-
pointerEvents: 'box-none',
|
139
151
|
},
|
140
152
|
});
|
141
153
|
|