2016-11-27 183 views
0

我试图通过Laravel Echo使用Vue 2和laravel-echo-server接收广播事件,但它不起作用。我已经把laravel-echo-server也放入开发模式,并且可以看到我进入了频道,但是同时离开了?如果这是问题,我该如何阻止这种情况发生并留在频道中?我还可以看到广播正在被解雇,因为我正在运行php artisan queue:work redis,并且每次发送活动请求时,我都会得到Processed: Illuminate\Broadcasting\BroadcastEvent,所以我知道这也适用。为什么这不工作?我真的很生气。laravel回声未收到广播

这里是我的bootstrap.js:

window._ = require('lodash'); 

window.$ = window.jQuery = require('jquery'); 
require('bootstrap-sass'); 

window.Vue = require('vue'); 
require('vue-resource'); 

Vue.http.interceptors.push((request, next) => { 
    request.headers.set('X-CSRF-TOKEN', Laravel.csrfToken); 

    next(); 
}); 

import Echo from "laravel-echo" 

window.Echo = new Echo({ 
    broadcaster: 'socket.io', 
    host: 'http://test.dev:6001' 
}); 

我app.js:

require('./bootstrap'); 

Vue.component('alert', require('./components/Alert.vue')); 

const app = new Vue({ 
    el: '#app', 
    data: { 
     users: [] 
    }, 
    created: function() { 
     window.Echo.channel('test-channel') 
      .listen('UserSignedUp', (e) => { 
       console.log(e); 
       console.log('test'); 
      }); 
    } 
}); 

我的事件:

<?php 

namespace App\Events; 

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 UserSignedUp implements ShouldBroadcast 
{ 
    use InteractsWithSockets, SerializesModels; 

    public $username; 

    public function __construct($username) 
    { 
     $this->username = $username; 
    } 

    public function broadcastOn() 
    { 
     return new Channel('test-channel'); 
    } 
} 

,最后,我laravel回声服务器。 json:

{ 
    "appKey": "somekey", 
    "authHost": "http://test.dev", 
    "authEndpoint": "/broadcasting/auth", 
    "database": "redis", 
    "databaseConfig": { 
     "redis": { 
      "port": "6379", 
      "host": "localhost" 
     }, 
     "sqlite": { 
      "databasePath": "/database/laravel-echo-server.sqlite" 
     } 
    }, 
    "devMode": true, 
    "host": "localhost", 
    "port": "6001", 
    "referrers": [], 
    "socketio": {}, 
    "sslCertPath": "", 
    "sslKeyPath": "" 
} 

我不会在任何地方发现任何错误,并且看起来我的活动正在被解雇和处理,但Echo并未收到活动。正如前面提到的,每个事件被触发时,我得到这个从控制台(laravel回声服务器端接头):

[TIME] - KEY joined channel: test-channel 
[TIME] - KEY left channel: test-channel 

回答

4

呀由于某种原因,我在我的.ENV文件BROADCAST_DRIVER设置为log。聪明我(y)