2016-11-27 263 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)