Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

metro-inspector-proxy

Package Overview
Dependencies
Maintainers
2
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

metro-inspector-proxy - npm Package Compare versions

Comparing version 0.53.1 to 0.54.0

4

package.json
{
"name": "metro-inspector-proxy",
"version": "0.53.1",
"version": "0.54.0",
"description": "metro-inspector-proxy",

@@ -20,4 +20,4 @@ "main": "src/index.js",

"dependencies": {
"chalk": "^2.4.1",
"connect": "^3.6.5",
"debug": "^2.2.0",
"rxjs": "^5.4.3",

@@ -24,0 +24,0 @@ "ws": "^1.1.5",

@@ -21,4 +21,4 @@ /**

type: "number",
default: 8082
default: 8081
});
runInspectorProxy(yargs.argv.port);

@@ -22,3 +22,6 @@ /**

const chalk = require("chalk");
const debug = require("debug")("Metro:InspectorProxy"); // Android's stock emulator and other emulators such as genymotion use a standard localhost alias.
const EMULATOR_LOCALHOST_ADDRESSES = ["10.0.2.2", "10.0.3.2"];
/**

@@ -28,3 +31,2 @@ * Device class represents single device connection to Inspector Proxy. Each device

*/
class Device {

@@ -36,3 +38,3 @@ // ID of the device.

// Stores last list of device's pages.
// Maps Page ID to debugger websocket connection for the pages that are currently
// Maps Page ID to debugger information for the pages that are currently
// debugged.

@@ -44,3 +46,3 @@ constructor(id, name, app, socket) {

this._pages = [];
this._debuggerSockets = new Map();
this._debuggerConnections = new Map();
this._deviceSocket = socket;

@@ -52,4 +54,3 @@

if (parsedMessage.event !== "getPages") {
// eslint-disable-next-line no-console
console.log(chalk.yellow("<- From device: " + message));
debug("<- From device: " + message);
}

@@ -62,5 +63,6 @@

// Device disconnected - close all debugger connections.
Array.from(this._debuggerSockets.values()).forEach(socket =>
socket.close()
);
Array.from(this._debuggerConnections.values()).forEach(_ref => {
let WS = _ref.socket;
return socket.close();
});
});

@@ -83,8 +85,10 @@

handleDebuggerConnection(socket, pageId) {
this._debuggerSockets.set(pageId, socket); // eslint-disable-next-line no-console
const debuggerInfo = {
socket
};
console.log(
`Got new debugger connection for page ${pageId} of ${this._name}`
);
this._debuggerConnections.set(pageId, debuggerInfo);
debug(`Got new debugger connection for page ${pageId} of ${this._name}`);
this._sendMessageToDevice({

@@ -98,5 +102,7 @@ event: "connect",

socket.on("message", message => {
// eslint-disable-next-line no-console
console.log(chalk.green("<- From debugger: " + message));
debug("<- From debugger: " + message);
const parsedMessage = JSON.parse(message);
this._processMessageFromDebugger(parsedMessage, debuggerInfo);
this._sendMessageToDevice({

@@ -106,3 +112,3 @@ event: "wrappedEvent",

pageId,
wrappedEvent: message
wrappedEvent: JSON.stringify(parsedMessage)
}

@@ -112,6 +118,3 @@ });

socket.on("close", () => {
// eslint-disable-next-line no-console
console.log(
`Debugger for page ${pageId} and ${this._name} disconnected.`
);
debug(`Debugger for page ${pageId} and ${this._name} disconnected.`);

@@ -136,16 +139,42 @@ this._sendMessageToDevice({

this._pages = message.payload;
} else if (message.event === "disconnect") {
// Device sends disconnect events only when page is reloaded or
// if debugger socket was disconnected.
const pageId = message.payload.pageId;
const debuggerInfo = this._debuggerConnections.get(pageId);
const debuggerSocket = debuggerInfo ? debuggerInfo.socket : null;
if (debuggerSocket && debuggerSocket.readyState == _ws.default.OPEN) {
debug(`Page ${pageId} is reloading.`);
debuggerSocket.send(
JSON.stringify({
method: "reload"
})
);
}
} else if (message.event === "wrappedEvent") {
const pageId = message.payload.pageId;
const debuggerSocket = this._debuggerSockets.get(pageId);
const debuggerInfo = this._debuggerConnections.get(pageId);
if (debuggerInfo == null) {
return;
}
const debuggerSocket = debuggerInfo.socket;
if (debuggerSocket == null) {
// TODO(hypuk): Send error back to device?
return;
} // eslint-disable-next-line no-console
}
console.log(
chalk.green("-> To debugger: " + message.payload.wrappedEvent)
);
debuggerSocket.send(message.payload.wrappedEvent);
const parsedPayload = JSON.parse(message.payload.wrappedEvent);
this._processMessageFromDevice(parsedPayload, debuggerInfo);
const messageToSend = JSON.stringify(parsedPayload);
debug("-> To debugger: " + messageToSend);
debuggerSocket.send(messageToSend);
}

@@ -157,4 +186,3 @@ } // Sends single message to device.

if (message.event !== "getPages") {
// eslint-disable-next-line no-console
console.log(chalk.yellow("-> To device" + JSON.stringify(message)));
debug("-> To device" + JSON.stringify(message));
}

@@ -172,2 +200,60 @@

);
} // Allows to make changes in incoming message from device.
// eslint-disable-next-line lint/no-unclear-flowtypes
_processMessageFromDevice(payload, debuggerInfo) {
// Replace Android addresses for scriptParsed event.
if (payload.method === "Debugger.scriptParsed") {
const params = payload.params || {};
if ("sourceMapURL" in params) {
for (let i = 0; i < EMULATOR_LOCALHOST_ADDRESSES.length; ++i) {
const address = EMULATOR_LOCALHOST_ADDRESSES[i];
if (params.sourceMapURL.indexOf(address) >= 0) {
payload.params.sourceMapURL = params.sourceMapURL.replace(
address,
"localhost"
);
debuggerInfo.originalSourceURLAddress = address;
}
}
}
if ("url" in params) {
for (let i = 0; i < EMULATOR_LOCALHOST_ADDRESSES.length; ++i) {
const address = EMULATOR_LOCALHOST_ADDRESSES[i];
if (params.url.indexOf(address) >= 0) {
payload.params.url = params.url.replace(address, "localhost");
debuggerInfo.originalSourceURLAddress = address;
}
}
}
}
} // Allows to make changes in incoming messages from debugger.
// eslint-disable-next-line lint/no-unclear-flowtypes
_processMessageFromDebugger(payload, debuggerInfo) {
// If we replaced Android emulator's address to localhost we need to change it back.
if (
payload.method === "Debugger.setBreakpointByUrl" &&
debuggerInfo.originalSourceURLAddress
) {
const params = payload.params || {};
if ("url" in params) {
payload.params.url = params.url.replace(
"localhost",
debuggerInfo.originalSourceURLAddress
);
}
if ("urlRegex" in params) {
payload.params.urlRegex = params.urlRegex.replace(
"localhost",
debuggerInfo.originalSourceURLAddress
);
}
}
}

@@ -174,0 +260,0 @@ }

@@ -103,2 +103,4 @@ /**

const debug = require("debug")("Metro:InspectorProxy");
const url = require("url");

@@ -119,3 +121,3 @@

// Internal counter for device IDs -- just gets incremented for each new device.
// We store server's address with port (like '127.0.0.1:8082') to be able to build URLs
// We store server's address with port (like '127.0.0.1:8081') to be able to build URLs
// (devtoolsFrontendUrl and webSocketDebuggerUrl) for page descriptions. These URLs are used

@@ -165,5 +167,12 @@ // by debugger to know where to connect.

addWebSocketListener(server) {
this._serverAddressWithPort =
server.address().address + ":" + server.address().port;
const _server$address = server.address(),
address = _server$address.address,
port = _server$address.port;
if (server.address().family === "IPv6") {
this._serverAddressWithPort = `[${address}]:${port}`;
} else {
this._serverAddressWithPort = `${address}:${port}`;
}
this._addDeviceConnectionHandler(server);

@@ -185,3 +194,3 @@

id: `${deviceId}-${page.id}`,
description: page.title,
description: page.app,
title: page.title,

@@ -191,3 +200,4 @@ faviconUrl: "https://reactjs.org/favicon.ico",

type: "node",
webSocketDebuggerUrl
webSocketDebuggerUrl,
vm: page.vm
};

@@ -235,11 +245,9 @@ } // Sends object as response to HTTP request.

new Device(deviceId, deviceName, appName, socket)
); // eslint-disable-next-line no-console
);
console.log(
`Got new connection: device=${deviceName}, app=${appName}`
);
debug(`Got new connection: device=${deviceName}, app=${appName}`);
socket.on("close", () => {
_this._devices.delete(deviceId); // eslint-disable-next-line no-console
_this._devices.delete(deviceId);
console.log(`Device ${deviceName} disconnected.`);
debug(`Device ${deviceName} disconnected.`);
});

@@ -246,0 +254,0 @@ } catch (e) {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc