Fredi
Fredi

Reputation: 35

Pusher: Difference between channel binding and Laravel echo

I recently worked on a notification system using Pusher and Laravel. unfortunately can't make it work this way:

 import Echo from 'laravel-echo'

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

Pusher.logToConsole = true;

 window.Echo = new Echo({
     broadcaster: 'pusher',
    key: 'WORKING KEY ..',
     cluster : "mt1",
     encrypted: true

 });

and

window.Echo.channel('post')
    .listen('ArticleEvent', function (e) {

    console.log(e);

});

While messages was sent to client console, but Listen didn't worked at all... and nothing logged.

anyway I used this way and it worked:

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

var pusher = new Pusher('WORKING KEY ..', {
    encrypted: true,
    cluster: 'mt1',
});

var channel = pusher.subscribe('post');

channel.bind('ArticleEvent', function(e) {
    alert(JSON.stringify(e['message']));
});

What is deference between 2 ways and which must be preferred?

Upvotes: 2

Views: 644

Answers (1)

doydoy
doydoy

Reputation: 4091

You need to include namespace information in the Listen method.

Please try using (note the . character):

window.Echo.channel('post')
    .listen('.ArticleEvent', function (e) {

    console.log(e);

});

Upvotes: 1

Related Questions