試圖使用Laravel 5.3與推杆,但它似乎不能在我的代碼中正確工作。Pusher和Laravel 5.3事件廣播
我.ENV是正確的
PUSHER_APP_ID= myappid
PUSHER_KEY= mykey
PUSHER_SECRET= mysecret
這是broadcasting.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 ProposalEvent 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 ['test-channel'];
// return new PrivateChannel('test-channel');
// return new PresenceChannel('test-channel');
}
}
我javascript
Pusher.logToConsole = true;
var pusher = new Pusher("mykey", {
cluster: 'eu',
encrypted: true
});
var channel = pusher.subscribe('test-channel');
channel.bind('App\\Events\\ProposalEvent', function(data) {
alert(data);
});
終於在我看來
event(new App\Events\ProposalEvent('some data'));
不幸的是,這是不是爲我工作,但是當我使用pusher->觸發這個樣子,沒有事件,它做工精細,和我看到在推進調試控制檯
消息$options = array(
'cluster' => 'eu',
'encrypted' => true
);
$pusher = new Pusher(
'mykey',
'mysecret',
'myid',
$options
);
$data['message'] = 'some data';
$pusher->trigger('test-channel', 'my-event', $data);
我在Laravel文檔和其他資源中搜索解決方案。在stackoverflow有問題,但沒有response.I將不勝感激,如果有人可以幫助我,因爲我找不到解決方案几天