Wait 2s before checking for matching devices for connected clients
Summary: Currently when a client connects, if there's no matching device we know of, it emits an error. The problem is that there's a race between clients connecting and devices being detected, if the client connects first, then we'll emit this error, even though the device is displayed shortly afterwards. Fixing this by waiting 2 seconds after a client connects, and then if it's still connected, checking for a matching device. This should be enough time to make this error more reliable. Reviewed By: passy Differential Revision: D14126315 fbshipit-source-id: c81b2c6d9a6e0639a656d1a4d7a8f999f715bfbf
This commit is contained in:
committed by
Facebook Github Bot
parent
77c77b5eb3
commit
6bdbb4f763
@@ -21,6 +21,13 @@ export default (store: Store, logger: Logger) => {
|
|||||||
type: 'NEW_CLIENT',
|
type: 'NEW_CLIENT',
|
||||||
payload: client,
|
payload: client,
|
||||||
});
|
});
|
||||||
|
// Wait 2 seconds, and then trigger another event so we can check it's displayed
|
||||||
|
setTimeout(() => {
|
||||||
|
store.dispatch({
|
||||||
|
type: 'NEW_CLIENT_SANITY_CHECK',
|
||||||
|
payload: client,
|
||||||
|
});
|
||||||
|
}, 2000);
|
||||||
});
|
});
|
||||||
|
|
||||||
server.addListener('removed-client', (id: string) => {
|
server.addListener('removed-client', (id: string) => {
|
||||||
|
|||||||
@@ -70,6 +70,10 @@ export type Action =
|
|||||||
type: 'NEW_CLIENT',
|
type: 'NEW_CLIENT',
|
||||||
payload: Client,
|
payload: Client,
|
||||||
}
|
}
|
||||||
|
| {
|
||||||
|
type: 'NEW_CLIENT_SANITY_CHECK',
|
||||||
|
payload: Client,
|
||||||
|
}
|
||||||
| {
|
| {
|
||||||
type: 'CLIENT_REMOVED',
|
type: 'CLIENT_REMOVED',
|
||||||
payload: string,
|
payload: string,
|
||||||
@@ -237,16 +241,6 @@ export default function reducer(
|
|||||||
selectedPlugin = userPreferredPlugin;
|
selectedPlugin = userPreferredPlugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
const matchingDeviceForClient = state.devices.filter(
|
|
||||||
device => payload.query.device_id === device.serial,
|
|
||||||
);
|
|
||||||
if (matchingDeviceForClient.length === 0) {
|
|
||||||
console.error(
|
|
||||||
new RecurringError(`Client initialised for non-displayed device`),
|
|
||||||
payload.id,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
clients: state.clients.concat(payload),
|
clients: state.clients.concat(payload),
|
||||||
@@ -260,6 +254,26 @@ export default function reducer(
|
|||||||
selectedPlugin,
|
selectedPlugin,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
case 'NEW_CLIENT_SANITY_CHECK': {
|
||||||
|
const {payload} = action;
|
||||||
|
// Check for clients initialised when there is no matching device
|
||||||
|
const clientIsStillConnected = state.clients.filter(
|
||||||
|
client => client.id == payload.query.device_id,
|
||||||
|
);
|
||||||
|
if (clientIsStillConnected) {
|
||||||
|
const matchingDeviceForClient = state.devices.filter(
|
||||||
|
device => payload.query.device_id === device.serial,
|
||||||
|
);
|
||||||
|
if (matchingDeviceForClient.length === 0) {
|
||||||
|
console.error(
|
||||||
|
new RecurringError(`Client initialised for non-displayed device`),
|
||||||
|
payload.id,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return state;
|
||||||
|
}
|
||||||
case 'CLIENT_REMOVED': {
|
case 'CLIENT_REMOVED': {
|
||||||
const {payload} = action;
|
const {payload} = action;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user