试图使用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将不胜感激,如果有人可以帮助我,因为我找不到解决方案几天