davidstump / SwiftPhoenixClient

Connect your Phoenix and iOS applications through WebSockets!
MIT License
506 stars 146 forks source link

How to configure heartbeat? #213

Closed jsmestad closed 2 years ago

jsmestad commented 2 years ago

@davidstump @dsrees thanks for the library. This may be a foolish question, but how do you configure the heartbeat? I am setting socket.heartbeatInterval = 1000 but it does not appear to do anything in practice. Reading through the code, I cannot see where socket.heartbeatTimer is getting initialized. The only place I can find the heartbeat being set is in resetHeartbeat(). I have to be missing it, could you point me in the right direction?

dsrees commented 2 years ago

@jsmestad thanks for the question. Are you just trying to change the frequency of the heartbeat?

jsmestad commented 2 years ago

I am getting a bunch of phx_close events from the client to the server, so in an effort to debug I started to look to see if Heartbeat was even getting sent from the connection. As I started tracing through the Socket initialize methods, I cannot find a test or any code that makes me think the heartbeat timer ever starts.

I must be totally missing it... 🙃

dsrees commented 2 years ago

The heartbeat timer gets recreated once the connection has been opened using the heartbeatInterval. If you're changing that interval after the connection is opened then it won't affect the heartbeat.

Which client version are you using?

Also have you provided a logging closure to the socket? That will print out everything that is happening client side.

    socket.logger = { msg in print("LOG:", msg) }
jsmestad commented 2 years ago

@dsrees ah there it is! I was going crazy thinking it had to exist.

I am using master at the moment