From 8b299ef5d5783d2628b0f914c3eb28b044275cf4 Mon Sep 17 00:00:00 2001 From: Chrystian Huot Date: Wed, 10 Jul 2019 13:02:08 -0400 Subject: [PATCH] Prevent navigating away if live feed is on --- client/imports/app/app.module.ts | 4 ++-- client/imports/app/radio/radio.component.ts | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/client/imports/app/app.module.ts b/client/imports/app/app.module.ts index 648f94d..0b5bfa4 100644 --- a/client/imports/app/app.module.ts +++ b/client/imports/app/app.module.ts @@ -22,8 +22,8 @@ import { AppSharedModule } from './shared/shared.module'; path: '**', pathMatch: 'full', redirectTo: '', - } - ]) + }, + ]), ], }) export class AppModule { } diff --git a/client/imports/app/radio/radio.component.ts b/client/imports/app/radio/radio.component.ts index 7dba923..5b311bc 100644 --- a/client/imports/app/radio/radio.component.ts +++ b/client/imports/app/radio/radio.component.ts @@ -1,4 +1,4 @@ -import { Component, OnDestroy, OnInit } from '@angular/core'; +import { Component, HostListener, OnDestroy, OnInit } from '@angular/core'; import { Subscription } from 'rxjs'; import { RadioEvent } from './radio'; import { AppRadioService } from './radio.service'; @@ -27,6 +27,14 @@ export class AppRadioComponent implements OnDestroy, OnInit { this._unsubscribe(); } + @HostListener('window:beforeunload', ['$event']) + private _exitNotification(event: BeforeUnloadEvent): void { + if (this.appRadioService.live) { + event.preventDefault(); + event.returnValue = false; + } + } + private _subscribe(): void { this._subscriptions.push( this.appRadioService.event.subscribe((event: RadioEvent) => {