Laravel 5.3不向推动者发送事件

时间:2016-09-18 10:39:06

标签: javascript laravel pusher laravel-events

我在我的网站上使用laravel 5.3。我需要为我的应用添加实时功能,所以我使用了推送器。但问题是当事件被触发时没有发生任何事情并且没有事件被发送到推动者。

我在broadcast.php文件中的推送配置:

 'pusher' => [
        'driver' => 'pusher',
        'key' => env('PUSHER_KEY'),
        'secret' => env('PUSHER_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\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

 class ChatEvent implements ShouldBroadcast
  {
   use InteractsWithSockets, SerializesModels;

public $data;

/**
 * Create a new event instance.
 *
 * @return void
 */
public function __construct($data)
{
    $this->data = $data;

}

/**
 * Get the channels the event should broadcast on.
 *
 * @return Channel|array
 */
public function broadcastOn()
{

    // return new PrivateChannel('test-channel');
    return ['test-channel'];
}

和我推送的javascript代码:

 Pusher.logToConsole = true;

var pusher = new Pusher('pusher_id', {
  cluster:'eu',
  encrypted: true
});

var channel = pusher.subscribe('test-channel');
channel.bind('App\\Events\\ChatEvent', function(data) {
    console.log(data);
  alert(data);
});

1 个答案:

答案 0 :(得分:0)

.env文件中检查您的Pusher凭据。

PUSHER_KEY should be PUSHER_APP_KEY
PUSHER_SECRET should be PUSHER_APP_SECRET