laravel-echo-server尝试进行身份验证时获得HTTP状态404

时间:2019-02-09 14:32:41

标签: redis socket.io vuejs2 laravel-echo

我一直困扰着很多天……

我将Laravel-echo与socket.io一起使用,当我尝试使用公共频道时,效果很好,但是当我尝试使用私有或在线状态频道时,出现此错误:

“客户端无法通过身份验证,HTTP状态为404”

=> App \ Providers \ BroadcastServiceProvider :: class,已经取消注释

我的Vue页面:

 Echo.private('post').listen('comments', (e) => {

         this.messages.push(e[0]) ; 

     });

bootstrap.js

import Echo from 'laravel-echo'

window.io = require('socket.io-client');

window.Echo = new Echo({

     broadcaster: 'socket.io',

     host: window.location.hostname + ':6001' ,

 });

事件:

class comments implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    private  $comment , $receiverId ; 

    /**
    * Create a new event instance.
 *
 * @return void
 */
public function __construct($comment , $receiverId)
{
    $this->comment = $comment ;

    $this->$receiverId = $receiverId ; 
}

/**
 * Get the channels the event should broadcast on.
 *
 * @return \Illuminate\Broadcasting\Channel|array
 */
public function broadcastOn()
{
    //i try PrivateChannel('post.'+$this->receiverId ); ...

    return new PrivateChannel('post');
}


public function broadcastWith(){

    return [ $this->comment  ] ;
}

}

路线/通道:

 Broadcast::channel('post', function ($user , $id) {
     return true ; // i already  try this (int) $user->id !== null;
 });

BroadcastServiceProvider:

 public function boot()
  {
    require base_path('routes/channels.php');

    Broadcast::routes();

  }

我使用php artisan queue:为队列工作

对于Redis,我在计算机上安装了redis-server.exe

请帮助! !!!!

0 个答案:

没有答案