Handling before close page event to close ws connection