Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/dev-middleware/src/inspector-proxy/InspectorProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ export default class InspectorProxy implements InspectorProxyQueries {
webSocketDebuggerUrl,
vm: page.vm,
deviceName: device.getName(),
reactNative: {
logicalDeviceId: deviceId,
},
};
}

Expand Down
4 changes: 4 additions & 0 deletions packages/dev-middleware/src/inspector-proxy/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ export type PageDescription = {
devtoolsFrontendUrl: string,
type: string,
webSocketDebuggerUrl: string,
// Metadata specific to React Native
reactNative: {
logicalDeviceId: string,
},
...
};
export type JsonPagesListResponse = Array<PageDescription>;
Expand Down
24 changes: 18 additions & 6 deletions packages/dev-middleware/src/middleware/openDebuggerMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default function openDebuggerMiddleware({
(experiments.enableOpenDebuggerRedirect && req.method === 'GET')
) {
const {query} = url.parse(req.url, true);
const {appId} = query;
const {appId, device}: {appId?: string, device?: string, ...} = query;

const targets = inspectorProxy.getPageDescriptions().filter(
// Only use targets with better reloading support
Expand All @@ -69,12 +69,19 @@ export default function openDebuggerMiddleware({
const launchType: 'launch' | 'redirect' =
req.method === 'POST' ? 'launch' : 'redirect';

if (typeof appId === 'string') {
if (typeof appId === 'string' || typeof device === 'string') {
logger?.info(
(launchType === 'launch' ? 'Launching' : 'Redirecting to') +
' JS debugger (experimental)...',
);
target = targets.find(_target => _target.description === appId);
if (typeof device === 'string') {
target = targets.find(
_target => _target.reactNative.logicalDeviceId === device,
);
}
if (!target && typeof appId === 'string') {
target = targets.find(_target => _target.description === appId);
}
} else {
logger?.info(
(launchType === 'launch' ? 'Launching' : 'Redirecting to') +
Expand All @@ -101,9 +108,13 @@ export default function openDebuggerMiddleware({
try {
switch (launchType) {
case 'launch':
await debuggerInstances.get(appId)?.kill();
const frontendInstanceId =
device != null
? 'device:' + device
: 'app:' + (appId ?? '<null>');
await debuggerInstances.get(frontendInstanceId)?.kill();
debuggerInstances.set(
appId,
frontendInstanceId,
await browserLauncher.launchDebuggerAppWindow(
getDevToolsFrontendUrl(
target.webSocketDebuggerUrl,
Expand All @@ -130,7 +141,8 @@ export default function openDebuggerMiddleware({
type: 'launch_debugger_frontend',
launchType,
status: 'success',
appId,
appId: appId ?? null,
deviceId: device ?? null,
});
return;
} catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion packages/dev-middleware/src/types/EventReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export type ReportableEvent =
type: 'launch_debugger_frontend',
launchType: 'launch' | 'redirect',
...
| SuccessResult<{appId: string}>
| SuccessResult<{appId: string | null, deviceId: string | null}>
| ErrorResult<mixed>
| CodedErrorResult<'NO_APPS_FOUND'>,
}
Expand Down