diff --git a/src/app/components/creator/room-creator-page/room-creator-page.component.ts b/src/app/components/creator/room-creator-page/room-creator-page.component.ts index d6e7dc84c9ffecc39b9e2276ff3c7d5b58546a5c..c501669a01b016a34562cbd8e882c8a1a70097d9 100644 --- a/src/app/components/creator/room-creator-page/room-creator-page.component.ts +++ b/src/app/components/creator/room-creator-page/room-creator-page.component.ts @@ -37,8 +37,6 @@ export class RoomCreatorPageComponent extends RoomPageComponent implements OnIni moderatorCommentCounter: number; urlToCopy = 'https://frag.jetzt/participant/room/'; - listenerFn: () => void; - constructor(protected roomService: RoomService, protected notification: NotificationService, protected route: ActivatedRoute, @@ -51,7 +49,7 @@ export class RoomCreatorPageComponent extends RoomPageComponent implements OnIni private liveAnnouncer: LiveAnnouncer, private _r: Renderer2, public eventService: EventService) { - super(roomService, route, location, wsCommentService, commentService); + super(roomService, route, location, wsCommentService, commentService, eventService); langService.langEmitter.subscribe(lang => translateService.use(lang)); } @@ -89,11 +87,6 @@ export class RoomCreatorPageComponent extends RoomPageComponent implements OnIni }); } - ngOnDestroy() { - this.listenerFn(); - this.eventService.makeFocusOnInputFalse(); - } - public announce() { this.liveAnnouncer.clear(); this.liveAnnouncer.announce('Du befindest dich in der von dir erstellten Sitzung. ' + diff --git a/src/app/components/moderator/room-moderator-page/room-moderator-page.component.ts b/src/app/components/moderator/room-moderator-page/room-moderator-page.component.ts index 5449ff2679b7656b8a47d591023d955d0e0c52da..9825e7ec4dd74fac5d7ebcefc47e4a5176308f7b 100644 --- a/src/app/components/moderator/room-moderator-page/room-moderator-page.component.ts +++ b/src/app/components/moderator/room-moderator-page/room-moderator-page.component.ts @@ -28,8 +28,6 @@ export class RoomModeratorPageComponent extends RoomPageComponent implements OnI moderatorCommentCounter: number; viewModuleCount = 1; - listenerFn: () => void; - constructor(protected location: Location, protected roomService: RoomService, protected route: ActivatedRoute, @@ -41,7 +39,7 @@ export class RoomModeratorPageComponent extends RoomPageComponent implements OnI public eventService: EventService, private liveAnnouncer: LiveAnnouncer, private _r: Renderer2) { - super(roomService, route, location, wsCommentService, commentService); + super(roomService, route, location, wsCommentService, commentService, eventService); langService.langEmitter.subscribe(lang => translateService.use(lang)); } @@ -123,11 +121,6 @@ export class RoomModeratorPageComponent extends RoomPageComponent implements OnI }); } - ngOnDestroy() { - this.listenerFn(); - this.eventService.makeFocusOnInputFalse(); - } - public announce() { this.liveAnnouncer.announce('Du befindest dich in der Sitzung in der du als Moderator gewählt wurdest. ' + 'Drücke die Taste 1 um auf die Fragen-Übersicht zu gelangen, ' + diff --git a/src/app/components/participant/room-participant-page/room-participant-page.component.ts b/src/app/components/participant/room-participant-page/room-participant-page.component.ts index 78912bb65fc2a34105a7f2ed6f3193e0ebdbb8a5..366754f684a98e901dad04529afcea5e69fd55ac 100644 --- a/src/app/components/participant/room-participant-page/room-participant-page.component.ts +++ b/src/app/components/participant/room-participant-page/room-participant-page.component.ts @@ -28,8 +28,6 @@ export class RoomParticipantPageComponent extends RoomPageComponent implements O deviceType = localStorage.getItem('deviceType'); user: User; - listenerFn: () => void; - constructor(protected location: Location, protected roomService: RoomService, protected route: ActivatedRoute, @@ -41,7 +39,7 @@ export class RoomParticipantPageComponent extends RoomPageComponent implements O private liveAnnouncer: LiveAnnouncer, private _r: Renderer2, public eventService: EventService) { - super(roomService, route, location, wsCommentService, commentService); + super(roomService, route, location, wsCommentService, commentService, eventService); langService.langEmitter.subscribe(lang => translateService.use(lang)); } @@ -74,11 +72,6 @@ export class RoomParticipantPageComponent extends RoomPageComponent implements O }); } - ngOnDestroy() { - this.listenerFn(); - this.eventService.makeFocusOnInputFalse(); - } - public announce() { this.liveAnnouncer.clear(); this.liveAnnouncer.announce('Du befindest dich in der Sitzung mit dem von dir eingegebenen Sitzungs-Code. ' + diff --git a/src/app/components/shared/comment-list/comment-list.component.ts b/src/app/components/shared/comment-list/comment-list.component.ts index 877fe379399bdaaec935124a0d2358e7c2850c37..702c642f32ea40ca31069afde91721cc60b31daa 100644 --- a/src/app/components/shared/comment-list/comment-list.component.ts +++ b/src/app/components/shared/comment-list/comment-list.component.ts @@ -1,4 +1,4 @@ -import { Component, ElementRef, Input, OnInit, ViewChild } from '@angular/core'; +import { Component, ElementRef, Input, OnInit, OnDestroy, ViewChild } from '@angular/core'; import { Comment } from '../../../models/comment'; import { CommentService } from '../../../services/http/comment.service'; import { TranslateService } from '@ngx-translate/core'; @@ -26,7 +26,7 @@ import { Router } from '@angular/router'; templateUrl: './comment-list.component.html', styleUrls: ['./comment-list.component.scss'] }) -export class CommentListComponent implements OnInit { +export class CommentListComponent implements OnInit, OnDestroy { @ViewChild('searchBox') searchField: ElementRef; @Input() user: User; @Input() roomId: string; @@ -114,6 +114,12 @@ export class CommentListComponent implements OnInit { }); } + ngOnDestroy() { + if (!this.freeze) { + this.commentStream.unsubscribe(); + } + } + checkScroll(): void { const currentScroll = document.documentElement.scrollTop; this.scroll = currentScroll >= 65; diff --git a/src/app/components/shared/room-page/room-page.component.ts b/src/app/components/shared/room-page/room-page.component.ts index 94d5605f83bc65cf96305babc970080997ae872b..14f9944c4e32f921a94a6829948d7ef83cac5d8e 100644 --- a/src/app/components/shared/room-page/room-page.component.ts +++ b/src/app/components/shared/room-page/room-page.component.ts @@ -1,28 +1,33 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, OnInit, OnDestroy } from '@angular/core'; import { Room } from '../../../models/room'; import { RoomService } from '../../../services/http/room.service'; import { ActivatedRoute } from '@angular/router'; import { Location } from '@angular/common'; import { WsCommentServiceService } from '../../../services/websockets/ws-comment-service.service'; import { CommentService } from '../../../services/http/comment.service'; +import { EventService } from '../../../services/util/event.service'; import { Message } from '@stomp/stompjs'; +import { Subscription } from 'rxjs'; @Component({ selector: 'app-room-page', templateUrl: './room-page.component.html', styleUrls: ['./room-page.component.scss'] }) -export class RoomPageComponent implements OnInit { +export class RoomPageComponent implements OnInit, OnDestroy { room: Room = null; isLoading = true; commentCounter: number; protected moderationEnabled = false; + protected sub: Subscription; + protected listenerFn: () => void; constructor(protected roomService: RoomService, protected route: ActivatedRoute, protected location: Location, protected wsCommentService: WsCommentServiceService, - protected commentService: CommentService + protected commentService: CommentService, + protected eventService: EventService ) { } @@ -32,6 +37,14 @@ export class RoomPageComponent implements OnInit { }); } + ngOnDestroy() { + this.listenerFn(); + this.eventService.makeFocusOnInputFalse(); + if (this.sub) { + this.sub.unsubscribe(); + } + } + protected afterRoomLoadHook() { } @@ -51,7 +64,7 @@ export class RoomPageComponent implements OnInit { .subscribe(commentCounter => { this.commentCounter = commentCounter; }); - this.wsCommentService.getCommentStream(this.room.id).subscribe((message: Message) => { + this.sub = this.wsCommentService.getCommentStream(this.room.id).subscribe((message: Message) => { const msg = JSON.parse(message.body); const payload = msg.payload; if (msg.type === 'CommentCreated') {