Files
flipper/src/dispatcher/server.js
Daniel Büchele 1f977f4844 Store use selected plugin after reconnect
Summary:
Deselect plugin when app disconnects, but store the information that the users had the app selected. When the app conencts again, restore the user's selection.
This also stores the device seleced by the user and reselects the device if it connects.

Reviewed By: xiphirx

Differential Revision: D8833948

fbshipit-source-id: ad3ef54681550ae674bdd4e695d677aea5c14588
2018-07-31 07:58:33 -07:00

46 lines
1.1 KiB
JavaScript

/**
* Copyright 2018-present Facebook.
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* @format
*/
import Server from '../server.js';
import type {Store} from '../reducers/index.js';
import type Logger from '../fb-stubs/Logger.js';
import type Client from '../Client.js';
export default (store: Store, logger: Logger) => {
const server = new Server(logger);
server.addListener('new-client', (client: Client) => {
store.dispatch({
type: 'NEW_CLIENT',
payload: client,
});
});
server.addListener('removed-client', (id: string) => {
store.dispatch({
type: 'CLIENT_REMOVED',
payload: id,
});
});
server.addListener('error', err => {
const payload: string =
err.code === 'EADDRINUSE'
? "Couldn't start websocket server. Looks like you have multiple copies of Sonar running."
: err.message || 'Unknown error';
store.dispatch({
type: 'SERVER_ERROR',
payload,
});
});
window.addEventListener('beforeunload', () => {
server.close();
});
};