Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can subscribe, but callback isn't triggered on event. #55

Closed
cedricve opened this issue Oct 7, 2016 · 15 comments
Closed

Can subscribe, but callback isn't triggered on event. #55

cedricve opened this issue Oct 7, 2016 · 15 comments

Comments

@cedricve
Copy link

cedricve commented Oct 7, 2016

I've managed to setup and install Laravel-echo correctly however the callback isn't triggered when an event is send from the debug tool. I see the client connecting succesfully. Can someone help?

screen shot 2016-10-07 at 10 54 46

screen shot 2016-10-07 at 10 54 56

@fourstacks
Copy link

I'm having the exact same problem. First I went through the docs and got my events talking to pusher just fine but my client side code doesn't trigger any callback on the listen method.

To be on the safe side I did a bare bones example following along with Matt Stauffers blogs post:

https://mattstauffer.co/blog/introducing-laravel-echo

Same outcome though. Works just fine for sending the event to pusher but the JS echo aspect just doesn't fire the callback.

I switched out laravel echo for the regular pusher library and code and the event is picked up in the browser just fine so I think it's probably an echo issue rather than anything to do with pusher per se.

import Echo from "laravel-echo"

// Init Echo
window.Echo = new Echo({
    broadcaster: 'pusher',
    key : 'pusher-key-redacted',
    encrypted: true,
    cluster: 'mt1'
});

window.Echo.channel('chat-room.1')
.listen('ChatMessageWasReceived', (e) => {
     console.log('here');
     console.log(e.test);
});

For reference the 'test' in the listen callback is the public property on my event class

@fourstacks
Copy link

@cedricve - I'm guessing you're not getting any other error messages in the console either right?

What sort of app are you building? Mine's a single page application built using vue js, vue router and vuex. Not sure that should make any difference but figured it was worth seeing if there are any similarities/differences in our use cases

@cedricve
Copy link
Author

cedricve commented Oct 7, 2016

Well, it's just a proof-of-concept the code is in the bootstrap.js file, as recommended by the documentation. I was really hoping to get this work.. I think I'll move to the official library as wel. Thanks for the help

@fourstacks
Copy link

Yeah, bit frustrating as Echo has some features that look pretty neat so I'd like to get it working if possible. If anyone else has any ideas or is having the same issue then I'd be happy to provide more info on my own usage

@fourstacks
Copy link

Just as a further update, I've just created a bare-bones test in a new laravel install and I've hit the same wall. Events get pushed to pusher just fine and/or if I create a test event in pusher I can see that my app subscribes in the pusher debug console but the callback just doesn't fire.

@cedricve
Copy link
Author

cedricve commented Oct 7, 2016

I just use the pusher-js library directly. I just need to fetch the events and run my own functions.
Why should you use Laravel-echo?

@fourstacks
Copy link

It has a ton of conveniences that basically I'd rather not have to write from scratch. I realise I can do everything with the pusher-js library I'd just rather get Echo working than reinvent the wheel...

@cedricve
Copy link
Author

cedricve commented Oct 7, 2016

Well it looks like we will need to wait a little bit longer.. @taylorotwell

@tlaverdure
Copy link
Contributor

While using pusher's debug tool your namespace will be off unless you change it from the default Laravel setup. See here for how to configure: https://laravel.com/docs/5.3/broadcasting#namespaces

@fourstacks
Copy link

Aaahhh...got it! Man, that seems so obvious now on a secon read through but totally missed the significance/implications of the namespacing when using the debug tool. Once I prefixed the event name with a ' . ' it started working like a charm. (so for anyone using the pusher test example in the debug tool your echo listener should look like:

window.Echo.listen('test_channel', '.my_event', (e) => {
    console.log(e.name);
    console.log(e.message);
});

Thanks for the response on this one @tlaverdure - you've saved me a ton of time next week!

@Chathula
Copy link

@fourstacks Can you post your event code please...

@rap2hpoutre
Copy link

I posted a similar problem on SO just before finding this issue. Anyway, it did not work for me even with the namespace (\App\Events\..., don't know why). So I had to name my events, then use a dot on front side.

@abdullahessam
Copy link

@fourstacks thank you man

@midoDiv
Copy link

midoDiv commented Aug 27, 2021

Aaahhh...got it! Man, that seems so obvious now on a secon read through but totally missed the significance/implications of the namespacing when using the debug tool. Once I prefixed the event name with a ' . ' it started working like a charm. (so for anyone using the pusher test example in the debug tool your echo listener should look like:

window.Echo.listen('test_channel', '.my_event', (e) => {
    console.log(e.name);
    console.log(e.message);
});

Thanks for the response on this one @tlaverdure - you've saved me a ton of time next week!

@midoDiv
Copy link

midoDiv commented Aug 27, 2021

ohhh mean you saved me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants