0

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

Sohaib
  • 1,972
  • 3
  • 9
  • 19
  • You are not subscribing correctly. See - https://laravel.com/docs/7.x/broadcasting#listening-for-events – levi May 31 '20 at 15:42
  • @levi Do you mean it should be like: `echo.channel('orders.9')`, I tried it and the same error – Sohaib May 31 '20 at 16:11
  • i believe the correct keyword is "echo.subscribed()", not "echo.subscribe" – fudu Jul 17 '23 at 09:46

0 Answers0