laravel / echo

Laravel Echo library for beautiful Pusher and Ably integration.
https://laravel.com/docs/broadcasting#client-side-installation
MIT License
1.19k stars 185 forks source link

any plan to support triggering client events? #47

Closed wanghanlin closed 7 years ago

wanghanlin commented 8 years ago

any plan to support triggering client events?

morloderex commented 8 years ago

Create a pr for it and see :)

tlaverdure commented 8 years ago

I may have something in the works in the next week or so.

Shigeki1120 commented 8 years ago

nice one

luizpvas commented 8 years ago

This would be really helpful. There are actions that don't need to go through Laravel, such as "user is typing..." in a chat, for example. This is just a simple broadcast to a channel.

woganmay commented 8 years ago

Any news on this? I've got Echo working for receiving messages to the client, but sending stuff back from the client would be very helpful.

lukepolo commented 8 years ago

if your using pusher you can just use their native event triggers :

https://pusher.com/docs/client_api_guide/client_events#trigger-events

woganmay commented 8 years ago

@lukepolo Thanks for the link! I'm using socket.io for now, but to be honest, looking at Pusher's pricing I can probably afford it for the app I plan on building.

lukepolo commented 8 years ago

@woganmay Gotcha, i dont think it would be terribly difficult to implement, but I do not have the time currently. But will need it for my app soon. So hopefully work will pay me to implement this soon!

Shigeki1120 commented 7 years ago

The workaround for this is just make another instance of a channel and use "trigger" method right?If you are using Pusher.

Does Echo have a method like it?

tillkruss commented 7 years ago
var channel = Echo.join('foobar');

channel.here((users) => {
    // `here()` is a callback when the `pusher:subscription_succeeded` event occurred,
    // until then you can't send client events on private or presence channels 
    channel.pusher.channels.channels[channel.name].trigger('client-customEventName', { foo: 'bar' });

channel.on('client-customEventName', function (data) {
    // this will only occur on other clients, because custom events are
    // not sent to the sending client.
    console.log(data);
});
wanghanlin commented 7 years ago

Closing the issue, the whisper method and listenForWhisper method is available now. See also #79

brunoinds commented 1 year ago

Whisper does not solve the problem. It will be good to implement in the Laravel Echo library some way to trigger Events on the server. I know is not possible because Laravel does not listen for WS, but the JS under the hood could send a Post request....