disconnect client instead of removing it
Summary: When an Android device disconnects, the device is marked as offline. In this diff, we want to make sure the client for the disconnected apps is not removed, but converted into a "disconnected" client. This makes sure plugins are still shown for the disconnected app. Reviewed By: passy Differential Revision: D15985424 fbshipit-source-id: 650ef1344b8be4411794b0344805cb75ceae4a83
This commit is contained in:
committed by
Facebook Github Bot
parent
7d4bd4e1f3
commit
718939cd6b
@@ -11,6 +11,7 @@ import type {Store} from '../reducers/index.js';
|
||||
import type {Logger} from '../fb-interfaces/Logger.js';
|
||||
import type Client from '../Client.js';
|
||||
import type {UninitializedClient} from '../UninitializedClient';
|
||||
import type BaseDevice from '../devices/BaseDevice';
|
||||
|
||||
export default (store: Store, logger: Logger) => {
|
||||
const server = new Server(logger, store);
|
||||
@@ -31,6 +32,31 @@ export default (store: Store, logger: Logger) => {
|
||||
});
|
||||
|
||||
server.addListener('removed-client', (id: string) => {
|
||||
const client: ?Client = store
|
||||
.getState()
|
||||
.connections.clients.find((client: Client) => client.id === id);
|
||||
if (client) {
|
||||
const device: ?BaseDevice = store
|
||||
.getState()
|
||||
.connections.devices.find(
|
||||
(device: BaseDevice) => device.serial === client.query.device_id,
|
||||
);
|
||||
|
||||
if (device && !device.isArchived && device.os === 'Android') {
|
||||
client.connected = false;
|
||||
client.connection = null;
|
||||
// find all plugins for this client that store data in persistedState
|
||||
client.plugins = Object.keys(store.getState().pluginStates)
|
||||
.filter(key => key.startsWith(id))
|
||||
.map(key => key.split('#').pop());
|
||||
|
||||
// don't remove client if it still has plugins
|
||||
if (client.plugins.length > 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
store.dispatch({
|
||||
type: 'CLIENT_REMOVED',
|
||||
payload: id,
|
||||
|
||||
Reference in New Issue
Block a user