【发布时间】:2018-02-17 04:24:53
【问题描述】:
所以我正在使用 Laravel 设置推送器,但我无法让它发送消息。推送器调试控制台中未收到它们,因此错误必须在发送它们时出现。以下是您可能需要的任何信息来帮助我发现错误,因为我花了数小时试图修复它,但现在无法进一步了解。
我的 .env 文件中的相关信息:
BROADCAST_DRIVER=pusher
QUEUE_DRIVER=sync
PUSHER_APP_ID=iscorrect
PUSHER_APP_KEY=iscorrect
PUSHER_APP_SECRET=iscorrect
我的广播.php
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'cluster' => 'eu',
'encrypted'=>true
],
],
应该触发消息的事件
<?php
namespace App\Events;
use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
class HelloPusherEvent implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
/**
* Only (!) Public members will be serialized to JSON and sent to Pusher
**/
public $message;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct($message)
{
$this->message = $message;
}
/**
* Get the channels the event should be broadcast on.
*
* @return array
*/
public function broadcastOn()
{
return ['my-channel'];
}
}
最后是我应该触发事件的路线:
Route::get('/pusher', function() {
event(new App\Events\HelloPusherEvent('Hi there Pusher!'));
return "Event has been sent!";
});
我在访问 /pusher 时没有收到任何错误,但不幸的是我的 Pusher 调试控制台正在“等待事件”..
【问题讨论】: