Skip to content

Commit 6f81d1d

Browse files
committed
fix(debug-socket): convert message to string
+ feat: `process.env.DEBUG_DEVTOOLS_SOCKETS` driven debug logs.
1 parent ebc9cc3 commit 6f81d1d

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

lib/device-sockets/ios/app-debug-socket-proxy-factory.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import { ITempService } from "../../definitions/temp-service";
1010

1111
export class AppDebugSocketProxyFactory
1212
extends EventEmitter
13-
implements IAppDebugSocketProxyFactory {
13+
implements IAppDebugSocketProxyFactory
14+
{
1415
private deviceWebServers: IDictionary<ws.Server> = {};
1516
private deviceTcpServers: IDictionary<net.Server> = {};
1617

@@ -113,9 +114,8 @@ export class AppDebugSocketProxyFactory
113114
projectName: string,
114115
projectDir: string
115116
): Promise<ws.Server> {
116-
const existingWebProxy = this.deviceWebServers[
117-
`${device.deviceInfo.identifier}-${appId}`
118-
];
117+
const existingWebProxy =
118+
this.deviceWebServers[`${device.deviceInfo.identifier}-${appId}`];
119119
const result =
120120
existingWebProxy ||
121121
(await this.addWebSocketProxy(device, appId, projectName, projectDir));
@@ -218,6 +218,11 @@ export class AppDebugSocketProxyFactory
218218
packets.on("data", (buffer: Buffer) => {
219219
const message = buffer.toString(encoding);
220220
if (webSocket.readyState === webSocket.OPEN) {
221+
if (process.env.DEBUG_DEVTOOLS_SOCKETS) {
222+
console.log({
223+
msgFromRuntime: JSON.parse(message),
224+
});
225+
}
221226
webSocket.send(message);
222227
} else {
223228
this.$logger.trace(
@@ -234,23 +239,29 @@ export class AppDebugSocketProxyFactory
234239
this.$logger.trace("Error on debugger deviceSocket", err);
235240
});
236241

237-
webSocket.on("message", (message: string) => {
238-
const length = Buffer.byteLength(message, encoding);
242+
webSocket.on("message", (message) => {
243+
const msg = message.toString();
244+
if (process.env.DEBUG_DEVTOOLS_SOCKETS) {
245+
console.log({
246+
msgFromDevtools: JSON.parse(msg),
247+
});
248+
}
249+
const length = Buffer.byteLength(msg, encoding);
239250
const payload = Buffer.allocUnsafe(length + 4);
240251
payload.writeInt32BE(length, 0);
241-
payload.write(message, 4, length, encoding);
252+
payload.write(msg, 4, length, encoding);
242253
appDebugSocket.write(payload);
243254
});
244255

245256
appDebugSocket.on("close", () => {
246257
currentAppSocket = null;
247-
this.$logger.info("Backend socket closed!");
258+
this.$logger.trace("Backend socket closed!");
248259
webSocket.close();
249260
});
250261

251262
webSocket.on("close", async () => {
252263
currentWebSocket = null;
253-
this.$logger.info("Frontend socket closed!");
264+
this.$logger.trace("Frontend socket closed!");
254265
appDebugSocket.unpipe(packets);
255266
packets.destroy();
256267
await device.destroyDebugSocket(appId);

0 commit comments

Comments
 (0)