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)
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With