【问题标题】:pusher can't listen callback events, it throw BroadcastExceptionpusher 无法监听回调事件,它抛出 BroadcastException
【发布时间】:2020-05-20 01:17:27
【问题描述】:

我尝试用我的应用程序测试推送器,连接设置成功但推送器无法监听我的应用程序事件。

我正在使用 laravel 7

广播.php

'pusher' => [
        'driver' => 'pusher',
        'key' => env('PUSHER_APP_KEY'),
        'secret' => env('PUSHER_APP_SECRET'),
        'app_id' => env('PUSHER_APP_ID'),
        'options' => [
            'cluster' => 'ap2',
            'encrypted' => true,
            'useTLS' => true,
        //     'curl_options' => [
        //     CURLOPT_SSL_VERIFYHOST => 0,
        //     CURLOPT_SSL_VERIFYPEER => 0,
        // ],
        ],
    ],

.env 文件

 APP_URL=http://localhost
 DB_HOST=localhost
 BROADCAST_DRIVER=pusher
 PUSHER_APP_ID=XXXXX
 PUSHER_APP_KEY=XXXXX
 PUSHER_APP_SECRET=XXXXX
 PUSHER_APP_CLUSTER=ap2

事件类

class LikeEvent implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;

public $id;
public $type;

public function __construct($id,$type)
{
    $this->id = $id;
    $this->type = $type;
}

public function broadcastOn()
{
    //return new PrivateChannel('likeChannel'); //I try both
    return new Channel('likeChannel');
}

public function broadcastAs()
{
    return 'LikeEvent';
}
}

channels.php

Broadcast::channel('likeChannel', function () {
return true;
});

我尝试通过

调用控制器中的事件
broadcast(new LikeEvent($reply->id,1))->toOthers();
//broadcast(new LikeEvent($reply->id,1));
//broadcast(new TestEvent("hello pusher"));
//event(new LikeEvent($reply->id,1));

它总是抛出 BroadcastException

 "message": "",
"exception": "Illuminate\\Broadcasting\\BroadcastException",
"file": "C:\\wamp64\\www\\rtforum.test\\vendor\\laravel\\framework\\src\\Illuminate\\Broadcasting\\Broadcasters\\PusherBroadcaster.php",
"line": 121,

【问题讨论】:

    标签: laravel pusher


    【解决方案1】:

    我通过将加密设为假来解决我的问题

    'options' => [
            'cluster' => 'ap2',
            'encrypted' => false,
            ]
    

    【讨论】:

      猜你喜欢
      • 2014-12-06
      • 1970-01-01
      • 2018-06-08
      • 2021-06-17
      • 2021-08-19
      • 1970-01-01
      • 1970-01-01
      • 2021-06-12
      • 2018-07-07
      相关资源
      最近更新 更多