1

The code below works on any browser actually. This website is also an Angular app. This code is part of a component. Again it works when I close the browser or close the component (Although there is no way of leaving the component unless the user closes the tab) on desktop. I tried not using beforeunload and I'm still having problems. It also seems the only way to test any solution would be to upload the changes to my website, wait, and then open the website on my phone and see if it worked. Any helpful suggestions would be great!

  ngOnDestroy() {
    this.onDestroy();
  }

  @HostListener('window:beforeunload')
  onDestroy() {
    this.chatService.leaveChat('User left');
    this.profileService.newProfileObj.subscribe(data => {
      this.chatService.updateChatListRemove(data.username);
    });
  }

EDIT:

It seems based off this documentation:

https://developer.mozilla.org/en-US/docs/Web/Events/beforeunload

that chrome browser on android shouldn't be a problem. Doesn't state anything for chrome on iPhone.

Nov
  • 99
  • 1
  • 11

1 Answers1

0

Solved this about 6-7 weeks ago. Instead of using window:beforeunload as a trigger to notify the backend (node.js w/ socket.io), I simply only use the backend. Doesn't make sense to have the front end notify the backend when a user has disconnected.

Nov
  • 99
  • 1
  • 11