question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Echo.socketId() undefined

See original GitHub issue

I’m trying to setup a toOthers() broadcast for a Dropzone

I’ve tried to add the X-Socket-ID to Dropzone but when I do Echo.socketId() it is undefined.

My setup of Echo is

window.Echo = new Echo({
    broadcaster: 'pusher',
    key: 'key',
    cluster: 'eu',
    encrypted: true
})
console.log(Echo.socketId()) // undefined

Within my package.json I have laravel-echo 1.2.5

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7

github_iconTop GitHub Comments

14reactions
ppiseckycommented, Sep 7, 2019

I scanned through Echo source and Pusher docs and here’s a solution:

window.Echo.connector.pusher.connection.bind('connected', function () {
    window.axios.defaults.headers.common['X-Socket-Id'] = window.Echo.socketId();
});

Though I have to say that I’m not a massive fan.

1reaction
JGdijkcommented, Mar 26, 2017

I had the same problem. What happens is that your console.log fires before the connection has been instantiated (because it happens async) and therefore socketId() will fire undefined. You will see that if you put a timeout on your console.log() you will be able to receive the socketId.

I have been looking for an event that fires when the connection has been made to hook in to it but have not found it. (i am using socket.io, i actually have seen somebody find this hook using pusher but can’t find the post anymore)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Laravel Echo - Echo.socketId() undefined - Laracasts
I'm trying to setup a toOthers() broadcast for a Dropzone. I've tried to add the X-Socket-ID to Dropzone but when I do Echo.socketId()...
Read more >
Laravel Echo callback - Stack Overflow
const socket = io('http://localhost'); console.log(socket.id); // undefined socket.on('connect', () => { console.
Read more >
How to use the laravel-echo function in laravel-echo - Snyk
To help you get started, we've selected a few laravel-echo examples, based on popular ... Echo.socketId() return config }, error => Promise.reject(error) ...
Read more >
Laravel Websockets with Nuxt - Introduction and demo
hi, I am using laravel echo with nuxt auth 5 to add private channels to my ... echo.socketId() if (socketId) { config.headers.common['X-Socket-ID'] ...
Read more >
Pusher Channels Docs | How to exclude event recipients
socketId = pusher.connection.socket_id; });. Once the socket_id has been accessed it can be used when triggering an event on the server by passing...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found