2017-09-09 12 views
0

私は最近Laravelアプリケーションをセットアップし、EchoがPusher Notificationsを受信するように設定しました。残念ながら、コールバック関数は、イベントが受信されても​​、データとともに受信されたとしても、トリガーされません。Laravel Echoがコールバックを起動しない

web.php

Route::get('/pusher', function() { 
    $location = ['lang' => 'langTets', 'lat' => 'latTest']; 
    event(new Freight\Events\LocationUpdated($location)); 
    return "Event has been sent!"; 
}); 

bootstrap.js

import Echo from 'laravel-echo' 

window.Pusher = require('pusher-js'); 
Pusher.logToConsole = true; 

window.Echo = new Echo({ 
    broadcaster: 'pusher', 
    key: 'iscorrect', 
    cluster: 'eu', 
    encrypted: true 
}); 

window.Echo.channel('location-updates') 
    .listen('.LocationUpdated', function(location) { 
     console.log("Test"); 
    }); 

私app.blade

<!DOCTYPE html> 
<html lang="{{ app()->getLocale() }}"> 
<head> 
    <meta charset="utf-8"> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 

    <!-- CSRF Token --> 
    <meta name="csrf-token" content="{{ csrf_token() }}"> 

    <title>Freight</title> 

    <!-- Styles --> 
    <link href="{{ asset('css/app.css') }}" rel="stylesheet"> 
    <!-- JS --> 
    <script src="{{ asset('js/app.js') }}"></script> 
</head> 
<body> 
... 

Iこれは、私のコンソールに表示されます:あなたは以下の私のコードを見つけることができますページを開きます:

app.js:32652 Pusher : State changed : initialized -> connecting 
app.js:32652 Pusher : Connecting : {"transport":"ws","url":"censoredstuff"} 
app.js:32652 Pusher : State changed : connecting -> connected with new socket ID morecensoredstuff 
app.js:32652 Pusher : Event sent : {"event":"pusher:subscribe","data":{"channel":"location-updates"}} 
app.js:32652 Pusher : Event recd : {"event":"pusher_internal:subscription_succeeded","data":{},"channel":"location-updates"} 
app.js:32652 Pusher : No callbacks on location-updates for pusher:subscription_succeeded 

は今、トリガイベント時に、これはコンソールに表示される内容です:

Pusher : Event recd : {"event":"Freight\\Events\\LocationUpdated","data":{"location":{"lang":"langTets","lat":"latTest"}},"channel":"location-updates"} 
app.js:32652 Pusher : No callbacks on location-updates for Freight\Events\LocationUpdated 

は理由にconsole.logが正常に動作していない、あなたが任意の手掛かりを持っていますか?それ以上の情報が必要な場合は、お気軽にお問い合わせください。

答えて

0

私はまだ問題の原因を突き止めませんでした。しかし、これは完全にそれを解決:

  • このようなあなたの場合には()メソッドbroadcastAsを実装します

broadcastAs(){ return 'myneweventname'; }

  • 変更に.jsファイルをあなたが聞いているように、新しく作成されたイベントエイリアス(先頭のピリオドなし)。
関連する問題