我想測試一個基本的推者觸發事件,它給了我一個簡單的警報和一個控制檯日誌,但它不會工作。響應是從推進器控制檯調試收到的,但沒有警報。我正在使用laravel 5.3及其路線和對此的看法。以下是我的代碼。我審查了敏感信息。推者不回電
路由文件web.php
Route::get('/bridge', function() {
error_reporting(E_ALL);
$options = array(
'cluster' => 'ap1',
'encrypted' => true
);
$pusher = new Pusher(
'key censored',
'secret censored',
'app id censore',
$options
);
$data['message'] = 'hello world';
$pusher->trigger('test_channel', 'my_event', $data);
return view('pusher');
});
,並查看pusher.blade.php
<!DOCTYPE html>
<head>
<title>Pusher Test</title>
<script src="https://js.pusher.com/3.2/pusher.min.js"></script>
<script>
// Enable pusher logging - don't include this in production
Pusher.logToConsole = true;
var pusher = new Pusher('e5bbf707214a6223d044', {
cluster: 'ap1',
encrypted: true
});
var channel = pusher.subscribe('test_channel');
channel.bind('my_event', function(data) {
alert(data);
console.log(data);
});
</script>
</head>
鉻控制檯給了我下面的日誌。
Pusher : State changed : initialized -> connecting
Pusher : Connecting : {"transport":"ws","url":"wss://ws-ap1.pusher.com:443/app/censored key?protocol=7&client=js&version=3.2.2&flash=false"}
Pusher : State changed : connecting -> connected with new socket ID 5034.8700909
Pusher : Event sent : {"event":"pusher:subscribe","data":{"channel":"test_channel"}}
Pusher : Event recd : {"event":"pusher_internal:subscription_succeeded","data":{},"channel":"test_channel"}
Pusher : No callbacks on test_channel for pusher:subscription_succeeded
但是當你有這樣的應用程序與控制檯打開運行....在另一個選項卡登錄到推杆網站的創建一個新的通知,那麼其他選項卡上,應該體現在console.log上...你做了那個測試嗎? – Hackerman
我做到了。兩個標籤,並重新加載一個 –