Looks tricky. Based on Stackoverflow and many other sources, this is the solution:
connection.onclose(e => {
fetch('http://localhost:7198/api/v1/Leaving?Id=' + Id, {
headers: { Authorization: 'Bearer ' + token }
});
But of course, there is no chance of this solution work. I will be closing the browser or the computer rebooted or something. I need to find a way to notify my backend when I leave a session no matter was the reason.
Aparently the solution above works good in classical mode, not in Azure Function Serverless
Any clue ?