Lakritzator / harmony

C# library for connecting to and controlling the Logitech Harmony Hub.
MIT License
5 stars 0 forks source link

Timeout after 60 seconds #19

Closed damonbrodie closed 5 years ago

damonbrodie commented 7 years ago

I have a client that listens for the OnActivityChanged event. If no communication happens for 60 seconds though, the connection seems to timeout. It seems from looking around at other projects that a periodic ping from the client is required to maintain the connection.

Is this something that can be added to this code base - or is there something else I should be doing?

Lakritzator commented 7 years ago

I don't think it will be hard to add this, but I will need to check if this is indeed needed. Right now I don't have time, but later this week I can probably check it.

If you can comment the other projects you saw how have this, it will make it easier.

damonbrodie commented 7 years ago

Actually I see it is something that Slion has dealt with on their fork of the code:

https://github.com/Slion/harmony/tree/340011d83c83a245868dd3fa7c4bf26fa19a1dac

Lakritzator commented 7 years ago

you beat me to it, I found something here: https://github.com/nfarina/homebridge/issues/215a you can also use slions version, which bases on my initial code (with a lot of changes I don't agree with)

damonbrodie commented 7 years ago

I'll keep an eye on your fork! Thanks!

damonbrodie commented 7 years ago

So at the very least adding this to HarmonyClient in HarmonyClient.cs will cause the xmpp client to send a keepalive every 40 seconds (Harmony disconnects after 60):

            KeepAlive = true,
            KeepAliveInterval = 40

It now looks like this:

    private HarmonyClient(string host, string token, int port = 5222)
    {
        Token = token;
        _xmpp = new XmppClientConnection(host, port)
        {
            UseStartTLS = false,
            UseSSL = false,
            UseCompression = false,
            AutoResolveConnectServer = false,
            AutoAgents = false,
            AutoPresence = true,
            AutoRoster = true,
            KeepAlive = true,
            KeepAliveInterval = 40
        };
        // Configure Sasl not to use auto and PLAIN for authentication
        _xmpp.OnSaslStart += SaslStartHandler;
        _xmpp.OnLogin += OnLoginHandler;
        _xmpp.OnIq += OnIqResponseHandler;
        _xmpp.OnMessage += OnMessage;
        _xmpp.OnSocketError += ErrorHandler;
        // Open the connection, do the login
        _xmpp.Open($"{token}@x.com", token);
    }
damonbrodie commented 7 years ago

The other piece that would be useful is to expose a connection closed event so that the client application can decide what to do (reopen the connection if desired).

Lakritzator commented 7 years ago

Thanks for the thorough information, made the suggested changes.

damonbrodie commented 5 years ago

Closing