Phoenix.Socket.Transport heartbeat payload

Hi all,

We decided to reimplement our websockets on Phoenix.
And we have the same ‘heartbeat’ functionality (ping-pong events) with some additional info in payload (like server time, etc).
But, currently, phoenix generates empty payload in heartbeat replies.
I believe more people implement a parallel heartbeat just for that.
So, reusing the phoenix heartbeat to transport some info could be very useful.
What do you think?

IME most apps don’t have need for such additional information that would make sense to send in every heartbeat, but having an optional call-back function that could provide heartbeat payload could be interesting for those that do … but is the savings really significant enough to justify the added complexity / variability between applications, rather than just sending periodic messages with the required payload?

You could always try submitting a PR :slight_smile: The relevant Elixir code appears to be in Phoenix.Socket.Transport in the dispatch method which pattern matches on “heartbeat”, though it would also require some support in the Javascript livrary.

If I’m understanding you correctly, you should be able to make a slight modification to this:

to send data in the heartbeat reply.