【发布时间】:2017-07-22 05:46:04
【问题描述】:
我正在尝试让 Pusher 与我的 Laravel 应用程序一起工作。我有一个私人频道,用户经过身份验证并连接到它。当我从 Pusher 调试控制台发送测试消息时,我会在客户端收到该条目。
我在从我的 L5 应用程序向推送者发送事件时遇到问题。该事件被触发,在我的 L5 日志中我看到以下内容:
[2017-03-02 13:07:23] local.INFO: Broadcasting [App\Events\xyz] on channels [private-xyz_35] with payload:
{
"message": {
"user": "35",
"code": "KKKK1111"
},
"socket": null
}
我的 .ENV 文件和广播配置都配置正确。当我触发事件时,我在 Pusher 调试控制台中看不到 API 消息。
谁能指出我在这里做错了什么?
这是我的活动:
<?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 xyz implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
/**
* Create a new event instance.
*
* @return void
*/
/**
* Only (!) Public members will be serialized to JSON and sent to Pusher
**/
public $message;
public function __construct($message)
{
$this->message = $message;
}
/**
* Get the channels the event should broadcast on.
*
* @return Channel|array
*/
public function broadcastOn()
{
return new PrivateChannel('xyz_' . $this->message['user']);
}
}
【问题讨论】: