Skip to content

reconnectTime will be canceled #22

Open

Description

@volkerrichert

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

Activity

  1. volkerrichert commented on Dec 16, 2022

    @volkerrichert
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions