Comments (15)
When you post to your laravel application with the X-Socket-Id, ensure that it matches the socketID that is being broadcasted to Redis. Maybe try a dd in your broadcasting event.
Here is the relevant code on laravel-echo-server.
https://github.com/tlaverdure/laravel-echo-server/blob/master/src/echo-server.ts#L148-L165
from laravel-echo-server.
It is indeed exactly the same.
Here's showing the post request that triggers the event, and I've dd'd the event and you can see the socket id is apart of the event object.
Then in the tooltip you can see it is the same as the current socket id but I'm still getting the event. I looked at the code you said and it does seem as it would look thru connected sockets for the X-Socket-Id record, and then passes that socket to the toOthers()
I just don't see how toOthers()
would send it all but that socket, thru that socket. But I admit I'm extremely unaware how socket.io works, especially on nodejs I'm just trying to learn it lol.
from laravel-echo-server.
@tlaverdure any ideas?
Just pushed all my latest code to staging env and it is still duplicating events to current user. And I made sure again that the X-Socket-Id
header is being correctly sent, and set on the event. The code doesn't seem to filter it out though.
from laravel-echo-server.
Think you may be implementing this wrong on the Laravel side. If both socket ids match on both laravel and laravel echo server then you should be good to go.
When the message is broadcasted to redis is should contain the socket id. With that in hand laravel echo server can broadcast a message as that socket:
socket.broadcast.to(channel).emit(message.event, channel, message.data);
I believe $this->dontBroadcastToCurrentUser();
was depreciated and you need to use ->toOthers()
on your broadcast()
method.
Example from docs:
https://laravel.com/docs/5.3/broadcasting#only-to-others
broadcast(new ShippingStatusUpdated($update))->toOthers();
Hope that helps.
from laravel-echo-server.
Well, I just reread the documentation and I still feel is functioning incorrectly.
The point as I can read is that ->toOthers()
is to not broadcast to the current users socket vs broadcasting specifically on that socket like it looks like your code does. And from what you just said, "contain the socket id. With that in hand laravel echo server can broadcast a message as that socket."
Wouldn't broadcasting a message as "that socket" mean only the current user would get it?
from laravel-echo-server.
I do understand I could be understanding how socket.io works.
from laravel-echo-server.
toOthers()
just runs dontBroadcastToCurrentUser()
haha I'm so confused now..
from laravel-echo-server.
@jonnywilliamson perhaps you could shine some light on this for me.
from laravel-echo-server.
@tlaverdure so looking through the socket.io
client library I see that by using .broadcast()
on a socket
instance it broadcasts to all other sockets, except the one sending it. Odd usage for it but I see it is indeed not an issue with your package.
Although I still don't know why events are going to the current user as well.
from laravel-echo-server.
@pfeiferchristopher I've exactly the same issue with Laravel 5.5 and Vue / Axios You found a solution ?
from laravel-echo-server.
Sorry, haven't worked on this project since a few weeks after my last comment.
from laravel-echo-server.
You have to use the trait InteractsWithSockets. Than the call of dontBroadcastToCurrentUser() method makes sense.
from laravel-echo-server.
incase someone is having the same issue,
- follow the docs https://laravel.com/docs/5.6/broadcasting#only-to-others
- for laravel defaults to work you have to register
echo
afteraxios
or add the headers manually
from laravel-echo-server.
Same problem for me.
All socket authentication, broadcast and others are working for me, except for "toOthers()". Somehow, it still broadcast the content to the sender. Let's say the event triggered is by API, how should we link the API to use their X-Socket-ID?
a) Client side
bootstrap.js
import Echo from "laravel-echo"
window.io = require('socket.io-client');
// Have this in case you stop running your laravel echo server
if (typeof io !== 'undefined') {
window.Echo = new Echo({
broadcaster: 'socket.io',
host: 'http://mysite.test:6001',
encrypted: true
});
}
welcome.blade.php
window.Echo.connector.options.auth.headers['Authorization'] = 'Bearer ' + 'xxxxxxxxxxxxx';
var channel = '5c36ca48fa6f3f2f280030bf';
console.log('Joining channel: ' + channel + '...');
console.log('Listening to ConversationActivity...');
window.Echo.private(channel)
.listen('ConversationActivity', (e) => {
console.log('New Conversation: ' + e.data.message);
});
b) Server side
............
use Illuminate\Broadcasting\InteractsWithSockets;
..........
class ConversationService
{
......
use InteractsWithSockets;
broadcast(new ConversationActivity($conversation))->toOthers();
......
}
from laravel-echo-server.
Just solved my problem by attaching X-Socket-Id in API calls. So it can track back who is the sender based on socket perspective. 👍
from laravel-echo-server.
Related Issues (20)
- Is the package compromised? HOT 6
- Laravel-echo-server events listeners custom callbacks
- Redis6 ACL Support HOT 1
- 运行一会,就会中断,提示截图显示的错误 HOT 2
- Cannot find module '../dist/cli' - supervisord
- Redis 6 ACL config HOT 1
- Connection refused on docker
- Laravel Echo Server work and client side error only at server HOT 2
- Is there ways to emit data from client (socket.io-client) to laravel-echo-server? HOT 2
- Laravel Echo PresenceChannel vs listen events doesn't work HOT 2
- 使用Laravel 5.8 广播系统,本地研发没有事情,上线后握手阶段,第一次OK,第二次报502,第三次报session id unknown,现在不知道是那个地方出问题了?求帮助 HOT 1
- Is `tlaverdure/laravel-echo-server` abandoned? HOT 6
- Is the cors configuration even working? HOT 1
- echo server socket.io.js error
- support redis cluster
- Redis TTL key is store forever
- CSRF token mismatch after session timeout
- npx laravel-echo-server start HOT 1
- Unable to join channel. Member data for presence channel missing HOT 1
- Is this project compatible with Socket.io v4? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-echo-server.