react-native-xenon 0.2.1 → 0.3.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 +8 -0
- package/lib/commonjs/assets/icons/bug.png +0 -0
- package/lib/commonjs/contexts/index.js +1 -1
- package/lib/commonjs/hooks/index.js +2 -9
- package/lib/commonjs/hooks/index.js.map +1 -1
- package/lib/commonjs/hooks/useConsoleInterceptor.js +4 -4
- package/lib/commonjs/hooks/useConsoleInterceptor.js.map +1 -1
- package/lib/commonjs/hooks/useNetworkInterceptor.js +14 -14
- package/lib/commonjs/hooks/useNetworkInterceptor.js.map +1 -1
- package/lib/commonjs/icons.js +1 -1
- package/lib/commonjs/icons.js.map +1 -1
- package/lib/commonjs/index.js +1 -1
- package/lib/commonjs/interceptors/ConsoleInterceptor.js +12 -13
- package/lib/commonjs/interceptors/ConsoleInterceptor.js.map +1 -1
- package/lib/commonjs/interceptors/FetchInterceptor.js +12 -13
- package/lib/commonjs/interceptors/FetchInterceptor.js.map +1 -1
- package/lib/commonjs/interceptors/HttpInterceptor.js +18 -36
- package/lib/commonjs/interceptors/HttpInterceptor.js.map +1 -1
- package/lib/commonjs/interceptors/Interceptor.js +9 -3
- package/lib/commonjs/interceptors/Interceptor.js.map +1 -1
- package/lib/commonjs/interceptors/NetworkInterceptor.js +1 -1
- package/lib/commonjs/interceptors/NetworkInterceptor.js.map +1 -1
- package/lib/commonjs/interceptors/WebSocketInterceptor.js +40 -64
- package/lib/commonjs/interceptors/WebSocketInterceptor.js.map +1 -1
- package/lib/commonjs/interceptors/XHRInterceptor.js +10 -11
- package/lib/commonjs/interceptors/XHRInterceptor.js.map +1 -1
- package/lib/commonjs/interceptors/index.js +4 -4
- package/lib/commonjs/types/index.js +4 -4
- package/lib/commonjs/ui/Xenon.js +19 -13
- package/lib/commonjs/ui/Xenon.js.map +1 -1
- package/lib/commonjs/ui/components/bubble/Bubble.js +8 -7
- package/lib/commonjs/ui/components/bubble/Bubble.js.map +1 -1
- package/lib/commonjs/ui/components/details/DetailsViewer.js +7 -7
- 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/NetworkRequestDetails.js +6 -6
- package/lib/commonjs/ui/components/details/NetworkRequestDetails.js.map +1 -1
- package/lib/commonjs/ui/components/headers/DebuggerHeader.js +10 -10
- package/lib/commonjs/ui/components/headers/DebuggerHeader.js.map +1 -1
- package/lib/commonjs/ui/components/headers/NetworkPanelHeader.js +2 -2
- package/lib/commonjs/ui/components/headers/NetworkPanelHeader.js.map +1 -1
- package/lib/commonjs/ui/components/headers/NetworkRequestDetailsHeader.js +1 -1
- package/lib/commonjs/ui/components/index.js +5 -5
- package/lib/commonjs/ui/components/items/ConsolePanelItem.js +2 -2
- package/lib/commonjs/ui/components/items/DebuggerHeaderItem.js +1 -1
- package/lib/commonjs/ui/components/items/NetworkPanelItem.js +2 -2
- package/lib/commonjs/ui/components/items/NetworkRequestDetailsHeaderItem.js +1 -1
- package/lib/commonjs/ui/components/items/NetworkRequestDetailsItem.js +1 -1
- package/lib/commonjs/ui/components/panels/ConsolePanel.js +8 -10
- package/lib/commonjs/ui/components/panels/ConsolePanel.js.map +1 -1
- package/lib/commonjs/ui/components/panels/NetworkPanel.js +17 -18
- package/lib/commonjs/ui/components/panels/NetworkPanel.js.map +1 -1
- package/lib/commonjs/utils.js +8 -1
- package/lib/commonjs/utils.js.map +1 -1
- package/lib/module/assets/icons/bug.png +0 -0
- package/lib/module/colors.js +5 -1
- package/lib/module/colors.js.map +1 -1
- package/lib/module/constants.js +5 -1
- package/lib/module/constants.js.map +1 -1
- package/lib/module/contexts/MainContext.js +7 -3
- package/lib/module/contexts/MainContext.js.map +1 -1
- package/lib/module/contexts/index.js +11 -1
- package/lib/module/contexts/index.js.map +1 -1
- package/lib/module/hooks/index.js +18 -3
- package/lib/module/hooks/index.js.map +1 -1
- package/lib/module/hooks/useConsoleInterceptor.js +16 -12
- package/lib/module/hooks/useConsoleInterceptor.js.map +1 -1
- package/lib/module/hooks/useNetworkInterceptor.js +31 -27
- package/lib/module/hooks/useNetworkInterceptor.js.map +1 -1
- package/lib/module/icons.js +6 -2
- package/lib/module/icons.js.map +1 -1
- package/lib/module/index.js +11 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/interceptors/ConsoleInterceptor.js +16 -10
- package/lib/module/interceptors/ConsoleInterceptor.js.map +1 -1
- package/lib/module/interceptors/FetchInterceptor.js +20 -15
- package/lib/module/interceptors/FetchInterceptor.js.map +1 -1
- package/lib/module/interceptors/HttpInterceptor.js +24 -37
- package/lib/module/interceptors/HttpInterceptor.js.map +1 -1
- package/lib/module/interceptors/Interceptor.js +13 -2
- package/lib/module/interceptors/Interceptor.js.map +1 -1
- package/lib/module/interceptors/NetworkInterceptor.js +8 -2
- package/lib/module/interceptors/NetworkInterceptor.js.map +1 -1
- package/lib/module/interceptors/WebSocketInterceptor.js +60 -78
- package/lib/module/interceptors/WebSocketInterceptor.js.map +1 -1
- package/lib/module/interceptors/XHRInterceptor.js +16 -11
- package/lib/module/interceptors/XHRInterceptor.js.map +1 -1
- package/lib/module/interceptors/index.js +32 -4
- package/lib/module/interceptors/index.js.map +1 -1
- package/lib/module/types/common.js +6 -2
- package/lib/module/types/common.js.map +1 -1
- package/lib/module/types/http.js +3 -1
- package/lib/module/types/index.js +47 -4
- package/lib/module/types/index.js.map +1 -1
- package/lib/module/types/websocket.js +3 -1
- package/lib/module/ui/Xenon.js +45 -34
- package/lib/module/ui/Xenon.js.map +1 -1
- package/lib/module/ui/components/bubble/Bubble.js +24 -18
- package/lib/module/ui/components/bubble/Bubble.js.map +1 -1
- package/lib/module/ui/components/details/DetailsViewer.js +17 -12
- package/lib/module/ui/components/details/DetailsViewer.js.map +1 -1
- package/lib/module/ui/components/details/LogMessageDetails.js +15 -10
- package/lib/module/ui/components/details/LogMessageDetails.js.map +1 -1
- package/lib/module/ui/components/details/NetworkRequestDetails.js +48 -43
- package/lib/module/ui/components/details/NetworkRequestDetails.js.map +1 -1
- package/lib/module/ui/components/headers/DebuggerHeader.js +37 -32
- package/lib/module/ui/components/headers/DebuggerHeader.js.map +1 -1
- package/lib/module/ui/components/headers/NetworkPanelHeader.js +26 -21
- package/lib/module/ui/components/headers/NetworkPanelHeader.js.map +1 -1
- package/lib/module/ui/components/headers/NetworkRequestDetailsHeader.js +14 -9
- package/lib/module/ui/components/headers/NetworkRequestDetailsHeader.js.map +1 -1
- package/lib/module/ui/components/index.js +39 -5
- package/lib/module/ui/components/index.js.map +1 -1
- package/lib/module/ui/components/items/ConsolePanelItem.js +15 -10
- package/lib/module/ui/components/items/ConsolePanelItem.js.map +1 -1
- package/lib/module/ui/components/items/DebuggerHeaderItem.js +17 -12
- package/lib/module/ui/components/items/DebuggerHeaderItem.js.map +1 -1
- package/lib/module/ui/components/items/NetworkPanelItem.js +28 -23
- package/lib/module/ui/components/items/NetworkPanelItem.js.map +1 -1
- package/lib/module/ui/components/items/NetworkRequestDetailsHeaderItem.js +14 -9
- package/lib/module/ui/components/items/NetworkRequestDetailsHeaderItem.js.map +1 -1
- package/lib/module/ui/components/items/NetworkRequestDetailsItem.js +15 -10
- package/lib/module/ui/components/items/NetworkRequestDetailsItem.js.map +1 -1
- package/lib/module/ui/components/panels/ConsolePanel.js +23 -20
- package/lib/module/ui/components/panels/ConsolePanel.js.map +1 -1
- package/lib/module/ui/components/panels/NetworkPanel.js +31 -27
- package/lib/module/ui/components/panels/NetworkPanel.js.map +1 -1
- package/lib/module/utils.js +27 -8
- package/lib/module/utils.js.map +1 -1
- package/lib/typescript/commonjs/src/hooks/index.d.ts +0 -1
- package/lib/typescript/commonjs/src/hooks/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/hooks/useNetworkInterceptor.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/icons.d.ts +1 -1
- package/lib/typescript/commonjs/src/interceptors/ConsoleInterceptor.d.ts +3 -3
- package/lib/typescript/commonjs/src/interceptors/ConsoleInterceptor.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/interceptors/FetchInterceptor.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/interceptors/HttpInterceptor.d.ts +8 -17
- package/lib/typescript/commonjs/src/interceptors/HttpInterceptor.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/interceptors/Interceptor.d.ts +3 -1
- package/lib/typescript/commonjs/src/interceptors/Interceptor.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/interceptors/NetworkInterceptor.d.ts +1 -1
- package/lib/typescript/commonjs/src/interceptors/NetworkInterceptor.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/interceptors/WebSocketInterceptor.d.ts +6 -18
- package/lib/typescript/commonjs/src/interceptors/WebSocketInterceptor.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/interceptors/XHRInterceptor.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types/console.d.ts +3 -0
- package/lib/typescript/commonjs/src/types/console.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types/http.d.ts +13 -5
- package/lib/typescript/commonjs/src/types/http.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types/websocket.d.ts +17 -7
- 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.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/commonjs/src/utils.d.ts +1 -0
- package/lib/typescript/commonjs/src/utils.d.ts.map +1 -1
- package/lib/typescript/module/src/hooks/index.d.ts +0 -1
- package/lib/typescript/module/src/hooks/index.d.ts.map +1 -1
- package/lib/typescript/module/src/hooks/useNetworkInterceptor.d.ts.map +1 -1
- package/lib/typescript/module/src/icons.d.ts +1 -1
- package/lib/typescript/module/src/interceptors/ConsoleInterceptor.d.ts +3 -3
- package/lib/typescript/module/src/interceptors/ConsoleInterceptor.d.ts.map +1 -1
- package/lib/typescript/module/src/interceptors/FetchInterceptor.d.ts.map +1 -1
- package/lib/typescript/module/src/interceptors/HttpInterceptor.d.ts +8 -17
- package/lib/typescript/module/src/interceptors/HttpInterceptor.d.ts.map +1 -1
- package/lib/typescript/module/src/interceptors/Interceptor.d.ts +3 -1
- package/lib/typescript/module/src/interceptors/Interceptor.d.ts.map +1 -1
- package/lib/typescript/module/src/interceptors/NetworkInterceptor.d.ts +1 -1
- package/lib/typescript/module/src/interceptors/NetworkInterceptor.d.ts.map +1 -1
- package/lib/typescript/module/src/interceptors/WebSocketInterceptor.d.ts +6 -18
- package/lib/typescript/module/src/interceptors/WebSocketInterceptor.d.ts.map +1 -1
- package/lib/typescript/module/src/interceptors/XHRInterceptor.d.ts.map +1 -1
- package/lib/typescript/module/src/types/console.d.ts +3 -0
- package/lib/typescript/module/src/types/console.d.ts.map +1 -1
- package/lib/typescript/module/src/types/http.d.ts +13 -5
- package/lib/typescript/module/src/types/http.d.ts.map +1 -1
- package/lib/typescript/module/src/types/websocket.d.ts +17 -7
- 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.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/lib/typescript/module/src/utils.d.ts +1 -0
- package/lib/typescript/module/src/utils.d.ts.map +1 -1
- package/package.json +8 -4
- package/src/assets/icons/bug.png +0 -0
- package/src/hooks/index.ts +0 -1
- package/src/hooks/useConsoleInterceptor.ts +1 -1
- package/src/hooks/useNetworkInterceptor.ts +31 -41
- package/src/icons.ts +1 -1
- package/src/interceptors/ConsoleInterceptor.ts +11 -10
- package/src/interceptors/FetchInterceptor.ts +6 -7
- package/src/interceptors/HttpInterceptor.ts +19 -48
- package/src/interceptors/Interceptor.ts +11 -1
- package/src/interceptors/NetworkInterceptor.ts +1 -1
- package/src/interceptors/WebSocketInterceptor.ts +37 -81
- package/src/interceptors/XHRInterceptor.ts +7 -6
- package/src/types/console.ts +4 -0
- package/src/types/http.ts +13 -5
- package/src/types/websocket.ts +17 -9
- package/src/ui/Xenon.tsx +10 -11
- package/src/ui/components/bubble/Bubble.tsx +3 -7
- package/src/ui/components/headers/NetworkPanelHeader.tsx +1 -1
- package/src/ui/components/panels/ConsolePanel.tsx +5 -8
- package/src/ui/components/panels/NetworkPanel.tsx +14 -14
- package/src/utils.ts +6 -0
- package/lib/commonjs/assets/icons/code.png +0 -0
- package/lib/commonjs/hooks/useScrollToBottom.js +0 -23
- package/lib/commonjs/hooks/useScrollToBottom.js.map +0 -1
- package/lib/module/assets/icons/code.png +0 -0
- package/lib/module/hooks/useScrollToBottom.js +0 -19
- package/lib/module/hooks/useScrollToBottom.js.map +0 -1
- package/lib/typescript/commonjs/src/hooks/useScrollToBottom.d.ts +0 -3
- package/lib/typescript/commonjs/src/hooks/useScrollToBottom.d.ts.map +0 -1
- package/lib/typescript/module/src/hooks/useScrollToBottom.d.ts +0 -3
- package/lib/typescript/module/src/hooks/useScrollToBottom.d.ts.map +0 -1
- package/src/assets/icons/code.png +0 -0
- package/src/hooks/useScrollToBottom.ts +0 -23
@@ -4,21 +4,11 @@ import { NETWORK_REQUEST_HEADER } from '../constants';
|
|
4
4
|
import { FetchInterceptor, WebSocketInterceptor, XHRInterceptor } from '../interceptors';
|
5
5
|
import {
|
6
6
|
NetworkType,
|
7
|
-
type
|
8
|
-
type HttpOpenCallback,
|
7
|
+
type HttpHandlers,
|
9
8
|
type HttpRequest,
|
10
|
-
type HttpRequestHeaderCallback,
|
11
|
-
type HttpResponseCallback,
|
12
|
-
type HttpSendCallback,
|
13
9
|
type ID,
|
14
|
-
type
|
15
|
-
type WebSocketConnectCallback,
|
16
|
-
type WebSocketOnCloseCallback,
|
17
|
-
type WebSocketOnErrorCallback,
|
18
|
-
type WebSocketOnMessageCallback,
|
19
|
-
type WebSocketOnOpenCallback,
|
10
|
+
type WebSocketHandlers,
|
20
11
|
type WebSocketRequest,
|
21
|
-
type WebSocketSendCallback,
|
22
12
|
} from '../types';
|
23
13
|
import { keyValueToString } from '../utils';
|
24
14
|
|
@@ -45,7 +35,7 @@ export default function useNetworkInterceptor({ autoEnabled }: NetworkIntercepto
|
|
45
35
|
};
|
46
36
|
|
47
37
|
const enableHttpInterceptions = useCallback(() => {
|
48
|
-
const openCallback:
|
38
|
+
const openCallback: HttpHandlers['open'] = (id, type, method, url) => {
|
49
39
|
if (!id) return;
|
50
40
|
|
51
41
|
setNetworkRequests((draft: NetworkRequests<HttpRequest>) => {
|
@@ -53,7 +43,7 @@ export default function useNetworkInterceptor({ autoEnabled }: NetworkIntercepto
|
|
53
43
|
});
|
54
44
|
};
|
55
45
|
|
56
|
-
const requestHeaderCallback:
|
46
|
+
const requestHeaderCallback: HttpHandlers['requestHeader'] = (id, header, value) => {
|
57
47
|
if (!id) return;
|
58
48
|
|
59
49
|
setNetworkRequests((draft: NetworkRequests<HttpRequest>) => {
|
@@ -81,7 +71,7 @@ export default function useNetworkInterceptor({ autoEnabled }: NetworkIntercepto
|
|
81
71
|
});
|
82
72
|
};
|
83
73
|
|
84
|
-
const sendCallback:
|
74
|
+
const sendCallback: HttpHandlers['send'] = (id, data) => {
|
85
75
|
if (!id) return;
|
86
76
|
|
87
77
|
setNetworkRequests((draft: NetworkRequests<HttpRequest>) => {
|
@@ -91,7 +81,7 @@ export default function useNetworkInterceptor({ autoEnabled }: NetworkIntercepto
|
|
91
81
|
});
|
92
82
|
};
|
93
83
|
|
94
|
-
const headerReceivedCallback:
|
84
|
+
const headerReceivedCallback: HttpHandlers['headerReceived'] = (
|
95
85
|
id,
|
96
86
|
responseContentType,
|
97
87
|
responseSize,
|
@@ -108,7 +98,7 @@ export default function useNetworkInterceptor({ autoEnabled }: NetworkIntercepto
|
|
108
98
|
});
|
109
99
|
};
|
110
100
|
|
111
|
-
const responseCallback:
|
101
|
+
const responseCallback: HttpHandlers['response'] = (
|
112
102
|
id,
|
113
103
|
status,
|
114
104
|
timeout,
|
@@ -132,24 +122,24 @@ export default function useNetworkInterceptor({ autoEnabled }: NetworkIntercepto
|
|
132
122
|
};
|
133
123
|
|
134
124
|
XHRInterceptor.instance
|
135
|
-
.
|
136
|
-
.
|
137
|
-
.
|
138
|
-
.
|
139
|
-
.
|
125
|
+
.set('open', openCallback)
|
126
|
+
.set('requestHeader', requestHeaderCallback)
|
127
|
+
.set('send', sendCallback)
|
128
|
+
.set('headerReceived', headerReceivedCallback)
|
129
|
+
.set('response', responseCallback)
|
140
130
|
.enableInterception();
|
141
131
|
|
142
132
|
FetchInterceptor.instance
|
143
|
-
.
|
144
|
-
.
|
145
|
-
.
|
146
|
-
.
|
147
|
-
.
|
133
|
+
.set('open', openCallback)
|
134
|
+
.set('requestHeader', requestHeaderCallback)
|
135
|
+
.set('send', sendCallback)
|
136
|
+
.set('headerReceived', headerReceivedCallback)
|
137
|
+
.set('response', responseCallback)
|
148
138
|
.enableInterception();
|
149
139
|
}, [setNetworkRequests]);
|
150
140
|
|
151
141
|
const enableWebSocketInterception = useCallback(() => {
|
152
|
-
const connectCallback:
|
142
|
+
const connectCallback: WebSocketHandlers['connect'] = (url, protocols, options, socketId) => {
|
153
143
|
if (typeof socketId !== 'number') return;
|
154
144
|
|
155
145
|
setNetworkRequests((draft: NetworkRequests<WebSocketRequest>) => {
|
@@ -162,7 +152,7 @@ export default function useNetworkInterceptor({ autoEnabled }: NetworkIntercepto
|
|
162
152
|
});
|
163
153
|
};
|
164
154
|
|
165
|
-
const sendCallback:
|
155
|
+
const sendCallback: WebSocketHandlers['send'] = (data, socketId) => {
|
166
156
|
if (typeof socketId !== 'number') return;
|
167
157
|
|
168
158
|
setNetworkRequests((draft: NetworkRequests<WebSocketRequest>) => {
|
@@ -173,7 +163,7 @@ export default function useNetworkInterceptor({ autoEnabled }: NetworkIntercepto
|
|
173
163
|
});
|
174
164
|
};
|
175
165
|
|
176
|
-
const closeCallback:
|
166
|
+
const closeCallback: WebSocketHandlers['close'] = (code, reason, socketId) => {
|
177
167
|
if (typeof socketId !== 'number') return;
|
178
168
|
|
179
169
|
setNetworkRequests((draft: NetworkRequests<WebSocketRequest>) => {
|
@@ -184,7 +174,7 @@ export default function useNetworkInterceptor({ autoEnabled }: NetworkIntercepto
|
|
184
174
|
});
|
185
175
|
};
|
186
176
|
|
187
|
-
const onOpenCallback:
|
177
|
+
const onOpenCallback: WebSocketHandlers['onOpen'] = (socketId, duration) => {
|
188
178
|
if (typeof socketId !== 'number') return;
|
189
179
|
|
190
180
|
setNetworkRequests((draft: NetworkRequests<WebSocketRequest>) => {
|
@@ -194,7 +184,7 @@ export default function useNetworkInterceptor({ autoEnabled }: NetworkIntercepto
|
|
194
184
|
});
|
195
185
|
};
|
196
186
|
|
197
|
-
const onMessageCallback:
|
187
|
+
const onMessageCallback: WebSocketHandlers['onMessage'] = (socketId, message) => {
|
198
188
|
if (typeof socketId !== 'number') return;
|
199
189
|
|
200
190
|
setNetworkRequests((draft: NetworkRequests<WebSocketRequest>) => {
|
@@ -205,7 +195,7 @@ export default function useNetworkInterceptor({ autoEnabled }: NetworkIntercepto
|
|
205
195
|
});
|
206
196
|
};
|
207
197
|
|
208
|
-
const onErrorCallback:
|
198
|
+
const onErrorCallback: WebSocketHandlers['onError'] = (socketId, data) => {
|
209
199
|
if (typeof socketId !== 'number') return;
|
210
200
|
|
211
201
|
setNetworkRequests((draft: NetworkRequests<WebSocketRequest>) => {
|
@@ -215,7 +205,7 @@ export default function useNetworkInterceptor({ autoEnabled }: NetworkIntercepto
|
|
215
205
|
});
|
216
206
|
};
|
217
207
|
|
218
|
-
const onCloseCallback:
|
208
|
+
const onCloseCallback: WebSocketHandlers['onClose'] = (socketId, data) => {
|
219
209
|
if (typeof socketId !== 'number') return;
|
220
210
|
|
221
211
|
setNetworkRequests((draft: NetworkRequests<WebSocketRequest>) => {
|
@@ -226,13 +216,13 @@ export default function useNetworkInterceptor({ autoEnabled }: NetworkIntercepto
|
|
226
216
|
};
|
227
217
|
|
228
218
|
WebSocketInterceptor.instance
|
229
|
-
.
|
230
|
-
.
|
231
|
-
.
|
232
|
-
.
|
233
|
-
.
|
234
|
-
.
|
235
|
-
.
|
219
|
+
.set('connect', connectCallback)
|
220
|
+
.set('send', sendCallback)
|
221
|
+
.set('close', closeCallback)
|
222
|
+
.set('onOpen', onOpenCallback)
|
223
|
+
.set('onMessage', onMessageCallback)
|
224
|
+
.set('onError', onErrorCallback)
|
225
|
+
.set('onClose', onCloseCallback)
|
236
226
|
.enableInterception();
|
237
227
|
}, [setNetworkRequests]);
|
238
228
|
|
package/src/icons.ts
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
/* eslint-disable no-console */
|
2
|
+
import type { ConsoleHandlers } from '../types';
|
3
|
+
import { frozen } from '../utils';
|
2
4
|
import Interceptor from './Interceptor';
|
3
5
|
|
4
6
|
const originalConsoleError = console.error;
|
@@ -12,24 +14,22 @@ const originalConsoleGroupCollapsed = console.groupCollapsed;
|
|
12
14
|
const originalConsoleGroupEnd = console.groupEnd;
|
13
15
|
const originalConsoleGroup = console.group;
|
14
16
|
|
15
|
-
export default class ConsoleInterceptor extends Interceptor {
|
17
|
+
export default class ConsoleInterceptor extends Interceptor<ConsoleHandlers> {
|
16
18
|
static readonly instance = new ConsoleInterceptor();
|
17
19
|
|
20
|
+
protected readonly handlers: ConsoleHandlers = {
|
21
|
+
callback: null,
|
22
|
+
};
|
23
|
+
|
18
24
|
private constructor() {
|
19
25
|
super();
|
20
26
|
}
|
21
27
|
|
22
|
-
|
23
|
-
|
24
|
-
setCallback(callback: typeof this.callback) {
|
25
|
-
this.callback = callback;
|
26
|
-
return this;
|
27
|
-
}
|
28
|
-
|
28
|
+
@frozen
|
29
29
|
enableInterception(): void {
|
30
30
|
if (this.isInterceptorEnabled) return;
|
31
31
|
|
32
|
-
const callback = this.callback
|
32
|
+
const callback = this.handlers.callback;
|
33
33
|
|
34
34
|
console.error = function (...args) {
|
35
35
|
callback?.('error', args);
|
@@ -94,6 +94,7 @@ export default class ConsoleInterceptor extends Interceptor {
|
|
94
94
|
this.isInterceptorEnabled = true;
|
95
95
|
}
|
96
96
|
|
97
|
+
@frozen
|
97
98
|
disableInterception(): void {
|
98
99
|
if (!this.isInterceptorEnabled) return;
|
99
100
|
|
@@ -110,6 +111,6 @@ export default class ConsoleInterceptor extends Interceptor {
|
|
110
111
|
console.groupEnd = originalConsoleGroupEnd;
|
111
112
|
console.group = originalConsoleGroup;
|
112
113
|
|
113
|
-
this.callback = null;
|
114
|
+
this.handlers.callback = null;
|
114
115
|
}
|
115
116
|
}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { NETWORK_REQUEST_HEADER } from '../constants';
|
2
2
|
import { NetworkType } from '../types';
|
3
|
-
import { formatRequestMethod, getHttpInterceptorId, keyValueToString } from '../utils';
|
3
|
+
import { formatRequestMethod, frozen, getHttpInterceptorId, keyValueToString } from '../utils';
|
4
4
|
import HttpInterceptor from './HttpInterceptor';
|
5
5
|
|
6
6
|
const originalFetch = global.fetch;
|
@@ -12,6 +12,7 @@ export default class FetchInterceptor extends HttpInterceptor {
|
|
12
12
|
super();
|
13
13
|
}
|
14
14
|
|
15
|
+
@frozen
|
15
16
|
enableInterception() {
|
16
17
|
if (this.isInterceptorEnabled) return;
|
17
18
|
|
@@ -90,13 +91,10 @@ export default class FetchInterceptor extends HttpInterceptor {
|
|
90
91
|
const contentTypeString = clonedResponseHeaders.get('Content-Type');
|
91
92
|
const contentLengthString = clonedResponseHeaders.get('Content-Length');
|
92
93
|
|
93
|
-
|
94
|
-
|
95
|
-
let responseHeaders: string = '';
|
96
|
-
|
97
|
-
if (contentTypeString) responseContentType = contentTypeString.split(';')[0];
|
94
|
+
const responseContentType = contentTypeString ? contentTypeString.split(';')[0] : undefined;
|
95
|
+
const responseSize = contentLengthString ? parseInt(contentLengthString, 10) : undefined;
|
98
96
|
|
99
|
-
|
97
|
+
let responseHeaders: string = '';
|
100
98
|
|
101
99
|
for (const [headerKey, headerValue] of clonedResponseHeaders.entries()) {
|
102
100
|
responseHeaders += keyValueToString(headerKey, headerValue);
|
@@ -126,6 +124,7 @@ export default class FetchInterceptor extends HttpInterceptor {
|
|
126
124
|
this.isInterceptorEnabled = true;
|
127
125
|
}
|
128
126
|
|
127
|
+
@frozen
|
129
128
|
disableInterception() {
|
130
129
|
if (!this.isInterceptorEnabled) return;
|
131
130
|
|
@@ -1,50 +1,21 @@
|
|
1
|
-
import type {
|
2
|
-
HttpHeaderReceivedCallback,
|
3
|
-
HttpOpenCallback,
|
4
|
-
HttpRequestHeaderCallback,
|
5
|
-
HttpResponseCallback,
|
6
|
-
HttpSendCallback,
|
7
|
-
} from '../types';
|
1
|
+
import type { HttpHandlers } from '../types';
|
8
2
|
import { NetworkInterceptor } from './NetworkInterceptor';
|
9
3
|
|
10
|
-
export default abstract class HttpInterceptor extends NetworkInterceptor {
|
11
|
-
protected
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
this.openCallback = callback;
|
19
|
-
return this;
|
20
|
-
}
|
21
|
-
|
22
|
-
setRequestHeaderCallback(callback: typeof this.requestHeaderCallback) {
|
23
|
-
this.requestHeaderCallback = callback;
|
24
|
-
return this;
|
25
|
-
}
|
26
|
-
|
27
|
-
setSendCallback(callback: typeof this.sendCallback) {
|
28
|
-
this.sendCallback = callback;
|
29
|
-
return this;
|
30
|
-
}
|
31
|
-
|
32
|
-
setHeaderReceivedCallback(callback: typeof this.headerReceivedCallback) {
|
33
|
-
this.headerReceivedCallback = callback;
|
34
|
-
return this;
|
35
|
-
}
|
36
|
-
|
37
|
-
setResponseCallback(callback: typeof this.responseCallback) {
|
38
|
-
this.responseCallback = callback;
|
39
|
-
return this;
|
40
|
-
}
|
4
|
+
export default abstract class HttpInterceptor extends NetworkInterceptor<HttpHandlers> {
|
5
|
+
protected handlers: HttpHandlers = {
|
6
|
+
open: null,
|
7
|
+
requestHeader: null,
|
8
|
+
send: null,
|
9
|
+
headerReceived: null,
|
10
|
+
response: null,
|
11
|
+
};
|
41
12
|
|
42
13
|
protected getCallbacks() {
|
43
|
-
const openCallback = this.
|
44
|
-
const requestHeaderCallback = this.
|
45
|
-
const sendCallback = this.
|
46
|
-
const headerReceivedCallback = this.
|
47
|
-
const responseCallback = this.
|
14
|
+
const openCallback = this.handlers.open;
|
15
|
+
const requestHeaderCallback = this.handlers.requestHeader;
|
16
|
+
const sendCallback = this.handlers.send;
|
17
|
+
const headerReceivedCallback = this.handlers.headerReceived;
|
18
|
+
const responseCallback = this.handlers.response;
|
48
19
|
|
49
20
|
return {
|
50
21
|
openCallback,
|
@@ -56,10 +27,10 @@ export default abstract class HttpInterceptor extends NetworkInterceptor {
|
|
56
27
|
}
|
57
28
|
|
58
29
|
protected clearCallbacks(): void {
|
59
|
-
this.
|
60
|
-
this.
|
61
|
-
this.
|
62
|
-
this.
|
63
|
-
this.
|
30
|
+
this.handlers.open = null;
|
31
|
+
this.handlers.requestHeader = null;
|
32
|
+
this.handlers.send = null;
|
33
|
+
this.handlers.headerReceived = null;
|
34
|
+
this.handlers.response = null;
|
64
35
|
}
|
65
36
|
}
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
import { frozen } from '../utils';
|
2
|
+
|
3
|
+
export default abstract class Interceptor<T extends Object> {
|
2
4
|
#isInterceptorEnabled = false;
|
3
5
|
|
4
6
|
get isInterceptorEnabled() {
|
@@ -9,6 +11,14 @@ export default abstract class Interceptor {
|
|
9
11
|
this.#isInterceptorEnabled = value;
|
10
12
|
}
|
11
13
|
|
14
|
+
protected abstract handlers: T;
|
15
|
+
|
16
|
+
@frozen
|
17
|
+
set<K extends keyof T>(key: K, handler: T[K]) {
|
18
|
+
this.handlers[key] = handler;
|
19
|
+
return this;
|
20
|
+
}
|
21
|
+
|
12
22
|
abstract enableInterception(): void;
|
13
23
|
abstract disableInterception(): void;
|
14
24
|
}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import Interceptor from './Interceptor';
|
2
2
|
|
3
|
-
export abstract class NetworkInterceptor extends Interceptor {
|
3
|
+
export abstract class NetworkInterceptor<T extends Object> extends Interceptor<T> {
|
4
4
|
protected abstract getCallbacks(): any;
|
5
5
|
protected abstract clearCallbacks(): void;
|
6
6
|
}
|
@@ -1,93 +1,48 @@
|
|
1
1
|
import { NativeEventEmitter, type EmitterSubscription } from 'react-native';
|
2
2
|
import NativeWebSocketModule from 'react-native/Libraries/WebSocket/NativeWebSocketModule';
|
3
|
-
import type {
|
4
|
-
WebSocketCloseCallback,
|
5
|
-
WebSocketConnectCallback,
|
6
|
-
WebSocketOnCloseCallback,
|
7
|
-
WebSocketOnErrorCallback,
|
8
|
-
WebSocketOnMessageCallback,
|
9
|
-
WebSocketOnOpenCallback,
|
10
|
-
WebSocketSendCallback,
|
11
|
-
} from '../types';
|
3
|
+
import type { WebSocketHandlers } from '../types';
|
12
4
|
import { NetworkInterceptor } from './NetworkInterceptor';
|
5
|
+
import { frozen } from '../utils';
|
13
6
|
|
14
7
|
const originalWebSocketConnect = NativeWebSocketModule.connect;
|
15
8
|
const originalWebSocketSend = NativeWebSocketModule.send;
|
16
9
|
const originalWebSocketSendBinary = NativeWebSocketModule.sendBinary;
|
17
10
|
const originalWebSocketClose = NativeWebSocketModule.close;
|
18
11
|
|
19
|
-
export default class WebSocketInterceptor extends NetworkInterceptor {
|
12
|
+
export default class WebSocketInterceptor extends NetworkInterceptor<WebSocketHandlers> {
|
20
13
|
static readonly instance = new WebSocketInterceptor();
|
21
14
|
|
15
|
+
protected handlers: WebSocketHandlers = {
|
16
|
+
connect: null,
|
17
|
+
send: null,
|
18
|
+
close: null,
|
19
|
+
onOpen: null,
|
20
|
+
onMessage: null,
|
21
|
+
onError: null,
|
22
|
+
onClose: null,
|
23
|
+
};
|
24
|
+
|
22
25
|
private constructor() {
|
23
26
|
super();
|
24
27
|
}
|
25
28
|
|
26
|
-
private connectCallback: WebSocketConnectCallback = null;
|
27
|
-
private sendCallback: WebSocketSendCallback = null;
|
28
|
-
private closeCallback: WebSocketCloseCallback = null;
|
29
|
-
private onOpenCallback: WebSocketOnOpenCallback = null;
|
30
|
-
private onMessageCallback: WebSocketOnMessageCallback = null;
|
31
|
-
private onErrorCallback: WebSocketOnErrorCallback = null;
|
32
|
-
private onCloseCallback: WebSocketOnCloseCallback = null;
|
33
|
-
|
34
|
-
setConnectCallback(callback: typeof this.connectCallback) {
|
35
|
-
this.connectCallback = callback;
|
36
|
-
return this;
|
37
|
-
}
|
38
|
-
|
39
|
-
setSendCallback(callback: typeof this.sendCallback) {
|
40
|
-
this.sendCallback = callback;
|
41
|
-
return this;
|
42
|
-
}
|
43
|
-
|
44
|
-
setCloseCallback(callback: typeof this.closeCallback) {
|
45
|
-
this.closeCallback = callback;
|
46
|
-
return this;
|
47
|
-
}
|
48
|
-
|
49
|
-
setOnOpenCallback(callback: typeof this.onOpenCallback) {
|
50
|
-
this.onOpenCallback = callback;
|
51
|
-
return this;
|
52
|
-
}
|
53
|
-
|
54
|
-
setOnMessageCallback(callback: typeof this.onMessageCallback) {
|
55
|
-
this.onMessageCallback = callback;
|
56
|
-
return this;
|
57
|
-
}
|
58
|
-
|
59
|
-
setOnErrorCallback(callback: typeof this.onErrorCallback) {
|
60
|
-
this.onErrorCallback = callback;
|
61
|
-
return this;
|
62
|
-
}
|
63
|
-
|
64
|
-
setOnCloseCallback(callback: typeof this.onCloseCallback) {
|
65
|
-
this.onCloseCallback = callback;
|
66
|
-
return this;
|
67
|
-
}
|
68
|
-
|
69
29
|
protected getCallbacks() {
|
70
|
-
const
|
71
|
-
const
|
72
|
-
const
|
73
|
-
const arrayBufferToString = this.arrayBufferToString
|
74
|
-
|
75
|
-
return {
|
76
|
-
connectCallback,
|
77
|
-
sendCallback,
|
78
|
-
closeCallback,
|
79
|
-
arrayBufferToString,
|
80
|
-
};
|
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 };
|
81
36
|
}
|
82
37
|
|
83
38
|
protected clearCallbacks(): void {
|
84
|
-
this.
|
85
|
-
this.
|
86
|
-
this.
|
87
|
-
this.
|
88
|
-
this.
|
89
|
-
this.
|
90
|
-
this.
|
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;
|
91
46
|
}
|
92
47
|
|
93
48
|
private eventEmitter: NativeEventEmitter | null = null;
|
@@ -118,19 +73,19 @@ export default class WebSocketInterceptor extends NetworkInterceptor {
|
|
118
73
|
const duration = timeEnd - (timeStart ?? 0);
|
119
74
|
this.timeStart.delete(ev.id);
|
120
75
|
|
121
|
-
this.
|
76
|
+
this.handlers.onOpen?.(ev.id, duration);
|
122
77
|
}),
|
123
78
|
this.eventEmitter.addListener('websocketMessage', ev => {
|
124
|
-
this.
|
79
|
+
this.handlers.onMessage?.(
|
125
80
|
ev.id,
|
126
81
|
ev.type === 'binary' ? this.arrayBufferToString(ev.data) : ev.data,
|
127
82
|
);
|
128
83
|
}),
|
129
84
|
this.eventEmitter.addListener('websocketClosed', ev => {
|
130
|
-
this.
|
85
|
+
this.handlers.onClose?.(ev.id, { code: ev.code, reason: ev.reason });
|
131
86
|
}),
|
132
87
|
this.eventEmitter.addListener('websocketFailed', ev => {
|
133
|
-
this.
|
88
|
+
this.handlers.onError?.(ev.id, { message: ev.message });
|
134
89
|
}),
|
135
90
|
];
|
136
91
|
}
|
@@ -141,6 +96,7 @@ export default class WebSocketInterceptor extends NetworkInterceptor {
|
|
141
96
|
this.eventEmitter = null;
|
142
97
|
}
|
143
98
|
|
99
|
+
@frozen
|
144
100
|
enableInterception(): void {
|
145
101
|
if (this.isInterceptorEnabled) return;
|
146
102
|
|
@@ -148,12 +104,11 @@ export default class WebSocketInterceptor extends NetworkInterceptor {
|
|
148
104
|
|
149
105
|
this.registerEvents();
|
150
106
|
|
151
|
-
const {
|
152
|
-
this.getCallbacks();
|
107
|
+
const { connect, send, close, arrayBufferToString } = this.getCallbacks();
|
153
108
|
|
154
109
|
const timeStart = this.timeStart;
|
155
110
|
NativeWebSocketModule.connect = function (...args) {
|
156
|
-
|
111
|
+
connect?.(...args);
|
157
112
|
|
158
113
|
timeStart.set(args[3], Date.now());
|
159
114
|
|
@@ -161,19 +116,19 @@ export default class WebSocketInterceptor extends NetworkInterceptor {
|
|
161
116
|
};
|
162
117
|
|
163
118
|
NativeWebSocketModule.send = function (...args) {
|
164
|
-
|
119
|
+
send?.(...args);
|
165
120
|
|
166
121
|
originalWebSocketSend.call(this, ...args);
|
167
122
|
};
|
168
123
|
|
169
124
|
NativeWebSocketModule.sendBinary = function (base64String, socketId) {
|
170
|
-
|
125
|
+
send?.(arrayBufferToString(base64String), socketId);
|
171
126
|
|
172
127
|
originalWebSocketSendBinary.call(this, base64String, socketId);
|
173
128
|
};
|
174
129
|
|
175
130
|
NativeWebSocketModule.close = function (code, reason, socketId) {
|
176
|
-
|
131
|
+
close?.(code, reason, socketId);
|
177
132
|
|
178
133
|
originalWebSocketClose.call(this, code, reason, socketId);
|
179
134
|
};
|
@@ -181,6 +136,7 @@ export default class WebSocketInterceptor extends NetworkInterceptor {
|
|
181
136
|
this.isInterceptorEnabled = true;
|
182
137
|
}
|
183
138
|
|
139
|
+
@frozen
|
184
140
|
disableInterception(): void {
|
185
141
|
if (!this.isInterceptorEnabled) return;
|
186
142
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { NetworkType } from '../types';
|
2
|
-
import { getHttpInterceptorId } from '../utils';
|
2
|
+
import { frozen, getHttpInterceptorId } from '../utils';
|
3
3
|
import HttpInterceptor from './HttpInterceptor';
|
4
4
|
|
5
5
|
const originalXHROpen = XMLHttpRequest.prototype.open;
|
@@ -13,6 +13,7 @@ export default class XHRInterceptor extends HttpInterceptor {
|
|
13
13
|
super();
|
14
14
|
}
|
15
15
|
|
16
|
+
@frozen
|
16
17
|
enableInterception() {
|
17
18
|
if (this.isInterceptorEnabled) return;
|
18
19
|
|
@@ -52,12 +53,11 @@ export default class XHRInterceptor extends HttpInterceptor {
|
|
52
53
|
const contentTypeString = this.getResponseHeader('Content-Type');
|
53
54
|
const contentLengthString = this.getResponseHeader('Content-Length');
|
54
55
|
|
55
|
-
|
56
|
-
|
56
|
+
const responseContentType = contentTypeString
|
57
|
+
? contentTypeString.split(';')[0]
|
58
|
+
: undefined;
|
57
59
|
|
58
|
-
|
59
|
-
|
60
|
-
if (contentLengthString) responseSize = parseInt(contentLengthString, 10);
|
60
|
+
const responseSize = contentLengthString ? parseInt(contentLengthString, 10) : undefined;
|
61
61
|
|
62
62
|
headerReceivedCallback?.(
|
63
63
|
this._interceptionId,
|
@@ -89,6 +89,7 @@ export default class XHRInterceptor extends HttpInterceptor {
|
|
89
89
|
this.isInterceptorEnabled = true;
|
90
90
|
}
|
91
91
|
|
92
|
+
@frozen
|
92
93
|
disableInterception() {
|
93
94
|
if (!this.isInterceptorEnabled) return;
|
94
95
|
|
package/src/types/console.ts
CHANGED
package/src/types/http.ts
CHANGED
@@ -14,15 +14,15 @@ export interface HttpRequest extends NetworkRequest {
|
|
14
14
|
responseType?: string;
|
15
15
|
}
|
16
16
|
|
17
|
-
|
17
|
+
type HttpOpenCallback =
|
18
18
|
| ((id: ID, type: HttpRequest['type'], method: string, url: string) => void)
|
19
19
|
| null;
|
20
20
|
|
21
|
-
|
21
|
+
type HttpRequestHeaderCallback = ((id: ID, header: string, value: string) => void) | null;
|
22
22
|
|
23
|
-
|
23
|
+
type HttpSendCallback = ((id: ID, data?: any) => void) | null;
|
24
24
|
|
25
|
-
|
25
|
+
type HttpHeaderReceivedCallback =
|
26
26
|
| ((
|
27
27
|
id: ID,
|
28
28
|
responseContentType: string | undefined,
|
@@ -31,7 +31,7 @@ export type HttpHeaderReceivedCallback =
|
|
31
31
|
) => void)
|
32
32
|
| null;
|
33
33
|
|
34
|
-
|
34
|
+
type HttpResponseCallback =
|
35
35
|
| ((
|
36
36
|
id: ID,
|
37
37
|
status: number | undefined,
|
@@ -42,3 +42,11 @@ export type HttpResponseCallback =
|
|
42
42
|
responseType: string | undefined,
|
43
43
|
) => void)
|
44
44
|
| null;
|
45
|
+
|
46
|
+
export interface HttpHandlers {
|
47
|
+
open: HttpOpenCallback;
|
48
|
+
requestHeader: HttpRequestHeaderCallback;
|
49
|
+
send: HttpSendCallback;
|
50
|
+
headerReceived: HttpHeaderReceivedCallback;
|
51
|
+
response: HttpResponseCallback;
|
52
|
+
}
|