aboutsummaryrefslogtreecommitdiff
path: root/src/components/chat/chat.js
blob: 3b84bd3d2db9c811c561858f66342b854a58086b (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
const chat = {
  data () {
    return {
      messages: [],
      currentMessage: '',
      socket: this.$store.state.users.socket,
      channel: null
    }
  },
  created () {
    this.channel = this.socket.channel('chat:public')
    this.channel.on('new_msg', (msg) => {
      this.messages.push(msg)
      this.messages = this.messages.slice(-19, 20)
    })
    this.channel.join()
  },
  methods: {
    submit(message) {
      this.channel.push('new_msg', {text: message}, 10000)
      this.currentMessage = '';
    }
  }
}

export default chat;