L
L
Lucius Mooning2019-02-19 14:43:55
Vue.js
Lucius Mooning, 2019-02-19 14:43:55

How to implement listening and receiving a message from a channel on Centrifugo?

Good afternoon!
Implementing chat using VueJs and Centrifugo.
Initially implemented on Pusher. Everything is working.
Now there is a desire to do it on Centrifugo.
I see connections in the Centrifugo console and sending messages.
Question how to receive new messages on the client.
What does the function of listening to the channel for receiving messages look like. The processing server is on Centrifugo.
I see something like this.
But where in the Vuejs file should it be added?

centrifuge.subscribe("chatroom",  function (message)
            {
                console.log('before subscribe');
                console.log(message);
                // console.log(message.data.message);

                    this.messages.push({
                        message: message.data.message
                    }
                );

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question