Add heartbeats to prevent session expiry.

The details of this pull request are in the `TODO.org` file, under the `TODO Heartbeat` heading.