Skip to content
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

reconnectTime will be canceled #22

Open
volkerrichert opened this issue Dec 16, 2022 · 1 comment
Open

reconnectTime will be canceled #22

volkerrichert opened this issue Dec 16, 2022 · 1 comment

Comments

@volkerrichert
Copy link

If you switch off a device and wait until ping will mark the device as disconnected, sockerConnected(false) will be called twice becaus of:

        socket.on('close', () => {
            this.socketConnected = false;
        })
        socket.on('end', () => {
            this.socketConnected = false;
        })

This will result in stop the reconnectTimer in the second call, which has just been started by the first one (if there is a little time cap). This will stop the device to be reconnected.

Move the clearTimerout inside the if like so

        if (this._socketConnected !== value) {
            clearTimeout(this.reconnectTimeout);

see: https://github.com/Nafaya/esphome-native-api/blob/main/lib/connection.js#L110-L115

@volkerrichert
Copy link
Author

One small annotation. It will not be called twice by "close" & "end" but "error" and "close"

        socket.on('error', error => {
            this.emit('error', error);
            **this.socketConnected = false;**
        })

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

No branches or pull requests

1 participant