Skip to content

Commit

Permalink
[DevTools] Emit new event when DevTools connects in standalone app (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jstejada authored Dec 6, 2021
1 parent 3f9480f commit 12bffc7
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions packages/react-devtools-core/src/standalone.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,17 @@ import type {InspectedElement} from 'react-devtools-shared/src/devtools/views/Co

installHook(window);

export type StatusListener = (message: string) => void;
export type StatusTypes = 'server-connected' | 'devtools-connected' | 'error';
export type StatusListener = (message: string, status: StatusTypes) => void;
export type OnDisconnectedCallback = () => void;

let node: HTMLElement = ((null: any): HTMLElement);
let nodeWaitingToConnectHTML: string = '';
let projectRoots: Array<string> = [];
let statusListener: StatusListener = (message: string) => {};
let statusListener: StatusListener = (
message: string,
status?: StatusTypes,
) => {};
let disconnectedCallback: OnDisconnectedCallback = () => {};

// TODO (Webpack 5) Hopefully we can remove this prop after the Webpack 5 migration.
Expand Down Expand Up @@ -260,6 +264,7 @@ function initialize(socket: WebSocket) {
});

log('Connected');
statusListener('DevTools initialized.', 'devtools-connected');
reload();
}

Expand Down Expand Up @@ -372,12 +377,15 @@ function startServer(

httpServer.on('error', event => {
onError(event);
statusListener('Failed to start the server.');
statusListener('Failed to start the server.', 'error');
startServerTimeoutID = setTimeout(() => startServer(port), 1000);
});

httpServer.listen(port, () => {
statusListener('The server is listening on the port ' + port + '.');
statusListener(
'The server is listening on the port ' + port + '.',
'server-connected',
);
});

return {
Expand Down

0 comments on commit 12bffc7

Please sign in to comment.