I am using laravel echo server with pusher in react native.
When I create a new pusher without laravel echo it works fine and I can listen on channels like:
import Pusher from 'pusher-js/react-native';
const pusher = new Pusher('edf0436fe**********', {
cluster: 'eu',
forceTLS: true,
encrypted: true,
})
pusher.subscribe('order.9')
.bind('OrderStatus', (e) => {
console.log('event: ', e);
})
but when I use laravel echo and listen on a channel I got a TypeError: echo.subscribe is not a function like:
import Echo from 'laravel-echo/dist/echo';
import Pusher from 'pusher-js/react-native';
const echo = new Echo({
broadcaster: 'pusher',
key: 'edf0436fe**********',
client: Pusher,
cluster: 'eu',
forceTLS: true,
authEndpoint: '/broadcasting/auth',
host: 'http://localhost:6001', // is it important to add the laravel-echo-server host?
auth: {
headers: {
'Authorization': 'Bearer 7ebee00f74965d**********',
},
},
});
echo.subscribe('order.9')
.bind('OrderStatus', (e) => {
console.log('event: ', e);
})
In Laravel Documentation, client option like above new Echo({client: Pusher})
is not included but if I remove it an error shows ReferenceError: Can't find variable Pusher
.
Thank you