33 lines
928 B
TypeScript
33 lines
928 B
TypeScript
|
|
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
|
||
|
|
import {Subscription} from 'rxjs';
|
||
|
|
import {ChatService} from '@pages/altitude/chat/service/chat.service';
|
||
|
|
|
||
|
|
@Component({
|
||
|
|
selector: 'app-chat',
|
||
|
|
imports: [],
|
||
|
|
templateUrl: './chat.component.html',
|
||
|
|
styleUrl: './chat.component.scss'
|
||
|
|
})
|
||
|
|
export class ChatComponent implements OnInit, OnDestroy {
|
||
|
|
private sub?: Subscription;
|
||
|
|
private readonly liveEvents: ChatService = inject(ChatService)
|
||
|
|
|
||
|
|
ngOnInit(): void {
|
||
|
|
this.liveEvents.connect();
|
||
|
|
|
||
|
|
this.sub = this.liveEvents.onEvent().subscribe(event => {
|
||
|
|
//TODO enums for event types
|
||
|
|
if (event.type === 'chat') {
|
||
|
|
console.log(event.data)
|
||
|
|
} else if (event.type === 'connect') {
|
||
|
|
console.log(event.data)
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
ngOnDestroy(): void {
|
||
|
|
this.sub?.unsubscribe();
|
||
|
|
this.liveEvents.disconnect(); // triggers onCompletion server-side, cleans up the emitter
|
||
|
|
}
|
||
|
|
}
|