fix reconnecting clients
Summary: When an archived device reconnected, the clients from the architved device weren't removed and a new client was added. This caused a client to be shown multiple times after reconnecting a device. In this diff, all clients and pluginStates from an archived device are removed once the device reconnects. Reviewed By: passy Differential Revision: D16075349 fbshipit-source-id: 1d0e6ce17c89bb75dd993466bca6bd64e2c63338
This commit is contained in:
committed by
Facebook Github Bot
parent
28d4e6409d
commit
f2c8fe0205
@@ -10,6 +10,7 @@ import child_process from 'child_process';
|
||||
import type {Store} from '../reducers/index.js';
|
||||
import type BaseDevice from '../devices/BaseDevice';
|
||||
import type {Logger} from '../fb-interfaces/Logger.js';
|
||||
import type Client from '../Client.js';
|
||||
import {registerDeviceCallbackOnPlugins} from '../utils/onRegisterDevice.js';
|
||||
import {getAdbClient} from '../utils/adbClient';
|
||||
import {default as which} from 'which';
|
||||
@@ -160,7 +161,7 @@ export default (store: Store, logger: Logger) => {
|
||||
});
|
||||
|
||||
// remove offline devices with same serial as the connected.
|
||||
const reconnectedDevices = store
|
||||
const reconnectedDevices: Array<string> = store
|
||||
.getState()
|
||||
.connections.devices.filter(
|
||||
(device: BaseDevice) =>
|
||||
@@ -168,10 +169,32 @@ export default (store: Store, logger: Logger) => {
|
||||
)
|
||||
.map(device => device.serial);
|
||||
|
||||
store.dispatch({
|
||||
type: 'UNREGISTER_DEVICES',
|
||||
payload: new Set(reconnectedDevices),
|
||||
});
|
||||
if (reconnectedDevices.length > 0) {
|
||||
reconnectedDevices.forEach((device: string) => {
|
||||
// remove all disconnected clients for the reconnected device
|
||||
store
|
||||
.getState()
|
||||
.connections.clients.filter(
|
||||
(client: Client) => client.query.device_id === device,
|
||||
)
|
||||
.forEach((client: Client) => {
|
||||
store.dispatch({
|
||||
type: 'CLIENT_REMOVED',
|
||||
payload: client.id,
|
||||
});
|
||||
store.dispatch({
|
||||
type: 'CLEAR_CLIENT_PLUGINS',
|
||||
payload: client.id,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// remove archived devices of previously connected devices
|
||||
store.dispatch({
|
||||
type: 'UNREGISTER_DEVICES',
|
||||
payload: new Set(reconnectedDevices),
|
||||
});
|
||||
}
|
||||
|
||||
store.dispatch({
|
||||
type: 'REGISTER_DEVICE',
|
||||
|
||||
Reference in New Issue
Block a user