Broadcast->toOthers() not working with Laravel Echo and Fetch API?
Hello there,
I am currently trying to get Laravels' toOthers-Feature to work with my events. My events get fired correctly. Channel authorization works. Listening to events on the client-side also works. The only thing which is not working:
Events are also received by the current user which is subscribed to the channel even if I use the toOthers-method.
I am using the fetch API on the client-side with Laravel Echo. This is how I instantiate Laravel Echo:
this.echo = new Echo({
authorizer: (channel, options) => {
return {
authorize: (socketId, callback) => {
const request = $fetch(config.public.baseUrl + '/broadcasting/auth', {
async onRequest({ request, options }) {
options.method = 'post'
options.body = {
socket_id: socketId,
channel_name: channel.name
}
options.headers = {
'X-XSRF-TOKEN': token,
'Accept': 'application/json',
'X-Socket-ID': socketId,
},
options.credentials = 'include'
},
})
request.then((response) => {
console.log(response)
callback(null, response)
})
}
};
},
broadcaster: 'pusher',
key: config.public.pusherAppKey,
cluster: 'mt1',
wsHost: config.public.pusherHost,
wsPort: config.public.pusherPort,
forceTLS: config.public.pusherTlsForce,
disableStats: true,
encrypted: true,
auth: {
headers: {
'X-XSRF-TOKEN': token,
'Accept': 'application/json',
},
},
enabledTransports: ['ws', 'wss'],
});
As you see I also add the X-Socket-ID-Header like described in the docs. I fire my event with:
broadcast(new MyEvent($myEventData))->toOthers();
The event is fired after my Backend receives a HTTP Call from an external Web Service.
But I still receive the event with the current logged in user if I listen to it like:
this.echo.private(this.channelName)
.listen('.my.event', (e) => {
console.log(e);
})
Can anybody give me hint what is missing?
Please or to participate in this conversation.