Does anyone know how to handle the connected, disconnected, reconnecting and etc on Laravel Echo?
I'm using VueJS btw
Does anyone know how to handle the connected, disconnected, reconnecting and etc on Laravel Echo?
I'm using VueJS btw
to connect you do this:
import Echo from 'laravel-echo'
in your function or on load you then do this:
window.Echo = new Echo({
broadcaster: 'socket.io',
host: socketServerURL, //whatever url you need
auth: {headers: {Authorization: 'Bearer ' + Vue.auth.getToken() }}
});
window.Echo.connector.socket.on('connect', function(){
this.isConnected = true
})
window.Echo.connector.socket.on('disconnect', function(){
this.isConnected = false
})
window.Echo.private('contacts').listen('ContactUpdated', event => {
console.log(event)
})
Late to the party but I tried the selected answer with no success. I suppose maybe laravel echo updated some stuff since this was answered. I've found the correct and updated answer here:
© 2022 - 2024 — McMap. All rights reserved.