我在Laravel Echo中使用推送通道时有一个问题。当我发起一个事件时,我从BroadcastException
得到500错误而没有响应主体,这对我来说很难调试。当我查看推送调试控制台时,推送器会监听在线状态事件。所以我认为我的事件从未被Pusher解雇过。这是我网络标签中的预览
我的控制员:
public function store() {
$user = auth()->user();
$message = $user->messages()->create([
'message' => request('message')
]);
event(new MessageReceived($message, $user));
return ['status' => 'OK'];
}
MessageReceived
类
namespace App\Events;
class MessageReceived implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $message;
public $user;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct(Message $message, User $user)
{
$this->message = $message;
$this->user = $user;
}
/**
* Get the channels the event should broadcast on.
*
* @return Channel|array
*/
public function broadcastOn()
{
return new PresenceChannel('chatroom');
}
}
这是我的vuejs
mounted() {
axios.get('/messages')
.then(response => {
this.messages = response.data
})
.catch(error => {
console.log(error)
})
Echo.join('chatroom')
.listen('MessageReceived', (e) => {
console.log(e) //never get into this
})
},
我找不到错误的位置。我使用群集ap1并在broadcasting.php
和我的bootstrap.js
中声明。有人可以帮帮我吗?
答案 0 :(得分:1)
这可能是由配置错误引起的。以下是一些要检查的事项:
.env
文件中,确保正确设置了推文ID,密钥和密码。.env
变量PUSHER_KEY
现在是PUSHER_APP_KEY
而PUSHER_SECRET
现在是PUSHER_APP_SECRET
config/broadcasting.php
中,确保群集设置正确。 如果您不使用HTTPS,则可能需要将“encrypted
密钥设置为false
'options' => [
'cluster' => 'ap1', // change this to your app's cluster
'encrypted' => false,
],