我的应用程序有一个非常不寻常的广播问题,我已将它同步到Dropbox和我的笔记本电脑上我可以运行它并将事件发送到推送服务器,但是,在我的桌面上它没有。我使用相同版本的XAMPP服务器,相同的迁移等任何人都可以提出任何建议?代码如下。
<?php
namespace App\Events;
use App\Models\Todo;
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 TodoCreated extends Event implements ShouldBroadcast
{
use InteractsWithSockets, SerializesModels;
public $todo;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct(Todo $todo)
{
$this->todo = $todo;
}
/*public function broadcastWith()
{
}*/
/**
* Get the channels the event should broadcast on.
*
* @return Channel|array
*/
public function broadcastOn()
{
return ['team.' . $this->todo->team_id . '.todos'];
}
}
'connections' => [
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_KEY'),
'secret' => env('PUSHER_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'cluster' => 'eu',
'encrypted' => true
],
],
BROADCAST_DRIVER=pusher
...
PUSHER_APP_ID=<app_id>
PUSHER_KEY=<key>
PUSHER_SECRET=<secret>
event(new App\Events\TodoCreate($todo))
点击活动,其中$todo
是App\Models\Todo
php artisan queue:work --timeout=0
并看到事件已注册并成功运行但我的推送调试面板上没有收到任何内容答案 0 :(得分:2)
我编码测试推送器广播发送事件,没关系。我使用Laravel 5.1。请查看以下代码
<强> 1。文件配置(或配置文件.env)broadcasting.php
'default' => env('BROADCAST_DRIVER', 'pusher'),
'connections' => [
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_KEY','xxxxxxxxxxxxxxxxx'),
'secret' => env('PUSHER_SECRET','xxxxxxxxxxxxxxxxx'),
'app_id' => env('PUSHER_APP_ID','xxxxxx'),
'options' => [
//
],
],
<强> 2。路由器强>
Route::get('/', function () {
return view('welcome');
});
Route::get('/broadcast', function() {
event(new \App\Events\TestEvent('Broadcasting in Laravel using Pusher!'));
});
3。的 TestEvent.php 强>
namespace App\Events;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
class TestEvent implements ShouldBroadcast
{
public $text;
public function __construct($text)
{
$this->text = $text;
}
public function broadcastOn()
{
return ['test-channel'];
}
}
<强> 4。作曲家强>
"require": {...,"pusher/pusher-php-server": "^2.2",}
5。的 welcome.blade.php 强>
<!DOCTYPE html>
<html>
<head>
<title>Laravel</title>
<link href="https://fonts.googleapis.com/css?family=Lato:100" rel="stylesheet" type="text/css">
<style>
html, body {
height: 100%;
}
body {
margin: 0;
padding: 0;
width: 100%;
display: table;
font-weight: 100;
font-family: 'Lato';
}
.container {
text-align: center;
display: table-cell;
vertical-align: middle;
}
.content {
text-align: center;
display: inline-block;
}
.title {
font-size: 96px;
}
</style>
</head>
<body>
<div class="container">
<div class="content">
<div class="title">Laravel 5</div>
</div>
</div>
</body>
<script src="//js.pusher.com/3.0/pusher.min.js"></script>
<script>
var pusher = new Pusher("xxxxxxxxxxxxxxxxxxxxxxxxxx")
var channel = pusher.subscribe('test-channel');
channel.bind('App\\Events\\TestEvent', function(data) {
console.log(data.text);
});
</script>
</html>
我希望帮助你!