Skip to content

fix(preview-api): raise deviceLost event after timeout of 5 seconds #4150

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 21, 2018

Conversation

Fatme
Copy link
Contributor

@Fatme Fatme commented Nov 20, 2018

In case when some .js file is changed, preview app is restarted on device e.g preview app is stopped and started again. When the preview app is stopped, Pubnub reports the device as lost and when preview app is started, Pubnub reports the device as found. With this fix, we want to delay the emitting of deviceLost event. This way we'll give a chance to find the device before reporting it as lost.

PR Checklist

In case when some `.js` file is changed, preview app is restarted on device e.g preview app is stopped and started again. When the preview app is stopped, Pubnub reports the device as lost and when preview app is started, Pubnub reports the device as found. With this fix, we want to delay the emitting of deviceLost event. This way we'll give a chance to find the device before reporting it as lost.
@Fatme Fatme added this to the 5.0.2 milestone Nov 20, 2018
@Fatme Fatme self-assigned this Nov 20, 2018
@@ -4,6 +4,7 @@ import { DeviceDiscoveryEventNames, DEVICE_LOG_EVENT_NAME } from "../../../../co

export class PreviewDevicesService extends EventEmitter implements IPreviewDevicesService {
private connectedDevices: Device[] = [];
private deviceTimers: IDictionary<NodeJS.Timer> = {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deviceTimers -> deviceLostTimers

if (this.deviceTimers[device.id]) {
clearTimeout(this.deviceTimers[device.id]);
}

this.emit(DeviceDiscoveryEventNames.DEVICE_FOUND, device);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be in else (we could also add a test for such case)?

@Fatme Fatme merged commit 8248829 into release Nov 21, 2018
@Fatme Fatme deleted the fatme/device-lost-after-timeout branch November 21, 2018 08:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants