[Global] Preliminary debug ws implementation
This commit is contained in:
parent
b4f5bdc996
commit
daf0357d60
6 changed files with 117 additions and 6 deletions
31
src/lib/debug.ts
Normal file
31
src/lib/debug.ts
Normal file
|
@ -0,0 +1,31 @@
|
|||
import { after } from "spitroast";
|
||||
import logger from "./logger";
|
||||
export let socket: WebSocket;
|
||||
|
||||
let iLoveBundlers = eval;
|
||||
|
||||
export function connectToDebugWS(url: string) {
|
||||
if (socket !== undefined && socket.readyState !== WebSocket.CLOSED) {
|
||||
socket.close();
|
||||
}
|
||||
|
||||
socket = new WebSocket(`ws://${url}`);
|
||||
|
||||
socket.addEventListener("message", (message: any) => {
|
||||
try {
|
||||
console.log(iLoveBundlers(message.data));
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function patchLogHook() {
|
||||
after("nativeLoggingHook", globalThis, (args, ret) => {
|
||||
if (socket?.readyState === WebSocket.OPEN) {
|
||||
socket.send(JSON.stringify({ message: args[0], level: args[1] }));
|
||||
}
|
||||
|
||||
logger.log(args[0]);
|
||||
});
|
||||
}
|
|
@ -7,4 +7,7 @@ export const i18n = findByProps("Messages");
|
|||
|
||||
// React
|
||||
export const React = findByProps("createElement") as typeof import("react");
|
||||
export const ReactNative = findByProps("Text", "Image") as typeof import("react-native");
|
||||
export const ReactNative = findByProps("Text", "Image") as typeof import("react-native");
|
||||
|
||||
// AsyncStorage
|
||||
export const AsyncStorage = findByProps("setItem") as typeof import("@react-native-async-storage/async-storage").default;
|
Loading…
Add table
Add a link
Reference in a new issue