return observable;
}
+ unlisten(): void {
+ this.closeChannel();
+ this.channelUri = 'UNKNOWN';
+ this.channel = new Subscriber<Message>();
+ }
+
// Creates SSE event source, handles SSE events
private openChannel(): void {
-import { Component, OnInit, NgZone } from '@angular/core';
+import { Component, OnInit, NgZone, OnDestroy } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { ChatroomService } from "../chatroom.service";
import { UserService } from "../user.service";
templateUrl: './chatroom.component.html',
styleUrls: ['./chatroom.component.less']
})
-export class ChatroomComponent implements OnInit {
+export class ChatroomComponent implements OnInit, OnDestroy {
chatroom: Chatroom = { id: 'FOO', name: 'BAR'};
messages: Message[] = [];
this.userService.assertUserisKnown(() => this.getChatroom());
}
+ ngOnDestroy() {
+ this.chatroomsService.unlisten();
+ this.chatroom = { id: 'FOO', name: 'BAR' };
+ }
+
getChatroom(): void {
const id: string | null = this.route.snapshot.paramMap.get('id');
if (id === null) {