square/SocketRocket — pull request #184 by cbrauchli (2014-07-10 03:19:19+00:00)
Title: Add ability to specify a heartbeat interval and timeout

Similar to #58 (and others), this lets the client add ping/pong logic to their connection to check that it's open. However, rather than exposing a `-sendPing` method, this abstracts it away into the concept of a "heartbeat."

I added two properties:
- `heartbeatInterval`: specifies how long (in seconds) to wait after no messages have been sent/received before sending a _ping_ message. Defaults to zero, which means no heartbeat, which keeps existing behavior and also is probably the right choice for most users who can control ping/pong messages on the server.
- `heartbeatTimeout`: specifies how long to wait after sending a _ping_ frame for any message to arrive. If the response takes too long, disconnects.

If this is approved, I'm happy to add another (optional) delegate method `- (void)webSocket:heartbeatWasAcknowledgedAfter:(NTTimeInterval)roundTripTimeInSeconds`. Also, maybe adding a specific close code for connections closed by a heartbeat timeout would be a good idea (for use in the `webSocket:didCloseWithCode:...` delegate method).