summaryrefslogtreecommitdiff
path: root/sample-apps/angular-chat/src/app/app.component.ts
blob: 02a1f9e9da57f0adceec520332e134aa22bc5ead (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { Component } from '@angular/core'

import { Observable } from 'rxjs'

import { MessagingService } from './messaging.service'
import { ChatMessage } from './chat-message.model'

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {
  userId: string = ''
  chatRoomId: string
  messages$: Observable<ChatMessage[]>
  directory$: Observable<string[]>
  messageBuff: string
  constructor(private messaging: MessagingService) {}

  ngOnInit() {
    this.messaging.init()
    this.directory$ = this.messaging.getDirectory()
  }

  sendMessage() {
    this.messaging.sendMessage(this.userId, this.chatRoomId, this.messageBuff)
  }

  async makeChatRoom() {
    this.chatRoomId = await this.messaging.makeChatRoom()
    this.messages$ = this.messaging.getChatRoom(this.chatRoomId)
  }
}