Laravel Echo SPA Module
A library to simplify the integration of Laravel Echo with your SPA/PWA
Setup
yarn add laravel-echo-spa-plugin
Define env variables for your application
env: ECHO_AUTH_ENDPOINT: '/api/broadcasting/auth' ECHO_HOST: 'http://echo-demo.test'
Usage
const $echo = // load 'socket.io.js' dynamically if 'window.io' is not defined// no PROMISE is returned!// register your callbacks using $echo.onEchoReady$echo $echo // add token if you need private channels$echo // connect, this method will wait for the setup method to completes$echo // you can access the echo instance directly$echoecho ... // shutdown the echo instance$echo// you can reconnect later$echo
Nuxt.js Example
// ~/plugins/echo.js { const $echo = Vueprototype$echo = app$echo = $echo // Support broadcasting to others for axios if $axios } // nuxt.config.js env: ECHO_AUTH_ENDPOINT: '/api/broadcasting/auth' ECHO_HOST: 'http://echo-demo.test' plugins: '~/plugins/echo'