There's actually a free Joomla! extension that will do just this. It's called Session Keeper and you can view it in the JED here:
It worked for my site when I utilized it, so hopefully it works for you as well! It allows you to set session lengths and display modal pop-ups when sessions start to expire. Hope it works for you!
Regarding why your session was not expiring, if you were on a page that had a Joomla login module, the session would never time out.
The Joomla login module enables keepalive for all pages where it appears.