0

事件是:

public $chat ;
public function __construct($chat)
{
        $this->chat = $chat;
}
 public function broadcastOn()
{
    //        return new Channel('recieve-chat');
    return new PrivateChannel('recieve-chat' );
}

routes/channels.php 是:

Broadcast::channel('recieve-chat', function ($user ) {
        return true;
//    return $user->id === $reciever_id;
});

在刀片文件中:

<script>
    window.addEventListener('DOMContentLoaded' , function () {
         Echo.private('recieve-chat')
                .listen('ChatBroad', (e) => {
                    window.livewire.emit('recieve:' + e.chat.bid_id , e.chat);
                    $(chatScrollDown('.chat'+ e.chat.bid_id ));
                });
        });

</script>

广播频道正常工作。但在 PrivateChannel 中不起作用。并且在控制台中没有显示任何错误

我使用 laravel echo 和 pusher

4

1 回答 1

0

在 App\Providers\BroadcastServiceProvider.php

public function boot()
{
    Broadcast::routes();

    require base_path('routes/channels.php');
}

必须喜欢代码。在 Broadcast::routes() 我们不需要任何中间件。

于 2021-03-15T19:42:34.363 回答