DEV: Ensure presence beforeunload event listener is cleaned up

In production, services are singletons. This logic will only affect the test environment
This commit is contained in:
David Taylor 2021-10-26 16:44:20 +01:00
parent 54ca7a9618
commit d43b77b56b
1 changed files with 8 additions and 3 deletions

View File

@ -227,9 +227,14 @@ export default class PresenceService extends Service {
this._presentProxies = {};
this._subscribedProxies = {};
this._initialDataRequests = {};
window.addEventListener("beforeunload", () => {
this._beaconLeaveAll();
});
this._beforeUnloadCallback = () => this._beaconLeaveAll();
window.addEventListener("beforeunload", this._beforeUnloadCallback);
}
willDestroy() {
super.willDestroy(...arguments);
window.removeEventListener("beforeunload", this._beforeUnloadCallback);
}
// Get a PresenceChannel object representing a single channel