0

我在本机反应中使用带有推送器的 laravel echo 服务器。

当我创建一个没有 laravel echo 的新推送器时,它工作正常,我可以收听以下频道:

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);
  })

但是当我使用 laravel echo 并在频道上收听时,我得到了一个 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);
  })

在 Laravel 文档中,new Echo({client: Pusher})不包括上面的客户端选项,但如果我删除它,则会显示错误ReferenceError: Can't find variable Pusher

谢谢

4

0 回答 0