title: How can I instantly detect browser tab close and tab reload during an webrtc call in javascript?
body: <p>I have a calling system using <strong>node.js</strong> &amp; <strong>socket.io</strong> with kurento server where users can reload their page during the call but when an user closes their tab i want to terminate the call instantly. </p>
  
  <p>I'm searching the whole internet for a perfect solution but nothing is accurate as far as I have seen. I have implemented a timer based solution that is, if someone closes tab then after a particular time (30 seconds) the call is terminated, but in case of reload they join again before that particular time and therefore that timer is canceled.</p>
  
  <p>But that is not an optimal solution, how can i check instantly whether an user reloaded or closed their tab?</p>
  
  <p>The main problem arises when an user initiates a call and closes tab before others answer the call, in that case the call is still ringing although the initiator closed the tab, others get a feedback after the specified time of 30 seconds and it's causing issues in the system. </p>