Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Event being broadcasted but client wont pick up on it #187

Closed
thorlucas opened this issue Jul 18, 2017 · 6 comments
Closed

Event being broadcasted but client wont pick up on it #187

thorlucas opened this issue Jul 18, 2017 · 6 comments

Comments

@thorlucas
Copy link

thorlucas commented Jul 18, 2017

I'm trying to broadcast a simple event using Redis, Laravel Echo, Laravel Echo Server, and socket.io.
I've got everything in place on the client side. The message is indeed being broadcasted and laravel echo server is picking up on it.

On chat.dev/ I have the client joining. On chat.dev/new I have the event being broadcast.

[5:14:31 PM] - HvEq_a12YnQFJGFiAAAE joined channel: chat
Channel: chat
Event: message.created
CHANNEL chat

So it seems like everything is working. On the client side, I'm including socket.io and it is finding it.

<script src="//{{ Request::getHost() }}:6001/socket.io/socket.io.js"></script>

Then I'm running

import Echo from 'laravel-echo'

window.Echo = new Echo({
    broadcaster: 'socket.io',
    host: window.location.hostname + ':6001'
});


window.Echo.channel('chat')
    .listen('.message.created', (e) => {
        console.log("Got message");
    });

But nothing is being logged to the console. Why?

@thorlucas
Copy link
Author

After a lot of fiddling, the frame is now being received by the client. BUT .listen isn't picking up on it!

42["message.created", "chat", {,…}]
0
:
"message.created"
1
:
"chat"
2
:
{,…}
message
:
{id: 23, body: "Modified", created_at: "2017-07-19 01:11:18", updated_at: "2017-07-19 01:11:18"}
socket
:
null

@enzonotario
Copy link

enzonotario commented Jul 20, 2017

Hi! I think that your problem is that, by default, Echo Client listens to an event with namespace App\Events. But your event seems to be message.create, without namespace.

See https://laravel.com/docs/5.4/broadcasting#namespaces

@thorlucas
Copy link
Author

Nope. That's not it. I'm using the prefix "." syntax to escape the namespace.

@thorlucas
Copy link
Author

Plus the frame that's being received only says "messages.created" without any namespace

@enzonotario
Copy link

laravel/echo#132

@tlaverdure
Copy link
Owner

This looks like a client configuration issue. Closing

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

No branches or pull requests

3 participants