I am trying to test a basic pusher trigger event that gives me a simple alert and a console log, but it wont work. The response is received from the pusher console debug but there are no alerts. I am using laravel 5.3 and its routes and a view for this. Below is my code. I have censored the sensitive information.
route file 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');
});
and view 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>
chrome console gives me the following logs.
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
You created a binding for the my_event
event. This error is complaining that you don't have a callback for the pusher:subscription_succeeded
event. If you want to catch that and handle it, you need to create a binding.
https://pusher.com/docs/client_api_guide/client_presence_channels#pusher-subscription-succeeded
channel.bind('pusher:subscription_succeeded', function(members) {
alert('successfully subscribed!');
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With