Closed damonbrodie closed 5 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.
Actually I see it is something that Slion has dealt with on their fork of the code:
https://github.com/Slion/harmony/tree/340011d83c83a245868dd3fa7c4bf26fa19a1dac
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)
I'll keep an eye on your fork! Thanks!
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);
}
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).
Thanks for the thorough information, made the suggested changes.
Closing
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?