tlaverdure / laravel-echo-server

Socket.io server for Laravel Echo
MIT License
2.65k stars 511 forks source link

Cannot set property 'socketId' of undefined #169

Closed AlexanderKharchenko closed 6 years ago

AlexanderKharchenko commented 7 years ago

laravel-echo-server - Version 1.2.8

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

(node:11090) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot set property 'socketId' of undefined

window.Echo.join('notify');

luchaos commented 7 years ago

i get an additional error. not sure if it's related.

2:49:36 AM] - MKk2gJOtCESsswR_AAAJ left channel: presence-feed (transport close)
(node:9765) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 8): TypeError: Cannot convert undefined or null to object
[2:49:38 AM] - cmRyqsny50ZHLyqTAAAK authenticated for: presence-feed
[2:49:38 AM] - cmRyqsny50ZHLyqTAAAK joined channel: presence-feed
(node:9765) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 9): TypeError: Cannot set property 'socketId' of undefined

it's happening when connecting successfully to a presence channel on each reload of the page.

tlaverdure commented 7 years ago

Which version are you running?

worldtrade1101 commented 7 years ago

Hi, I got the same problem with a presence channel. Running on laravel-echo-server 1.2.29 and laravel-echo 1.3. I tested on laravel 5.3 and 5.4 and I got the same error. When you join the channel for the first time in the console I receive the exception luchaos said and a DeprecationWarning. The presence channel doesn't work. If you need more info let me know.

luchaos commented 7 years ago

i recently updated several libraries within the node stack and the stack itself - i will have a look if this is still the case as well and provide all running version numbers while at it. maybe i can find more detailed information on why this is happening

Yahav commented 7 years ago

I get the same issues with my setup: [3:09:10 PM] - 3lxAZQ8fgsh50njcAAAD authenticated for: presence-chat [3:09:10 PM] - 3lxAZQ8fgsh50njcAAAD joined channel: presence-chat (node:18508) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 5): TypeError: Cannot set property 'socketId' of undefined

Echo Server v1.3.0 Echo v1.3.2

abetwothree commented 7 years ago

For anyone else running into this, I figured out the issue and comment the solution on this here: https://github.com/tlaverdure/laravel-echo-server/issues/202#issuecomment-323249811

lilian21 commented 7 years ago

I have the same issue, I'm using this package to broadcast events from an API to an angular app. Authentication works, even joining works but something else is not working well

[12:31:32 AM] - mYBcuPMgMp4v6RqvAAAY left channel: presence-chat.ZPgLCxY6 (transport close) (node:13265) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 11): Type Error: Cannot convert undefined or null to object (node:13265) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 12): Type Error: Cannot convert undefined or null to object [12:32:01 AM] - ILArCPOdNHlgywZaAAAZ authenticated for: private-chat.ZPgLCxY6 [12:32:01 AM] - ILArCPOdNHlgywZaAAAZ joined channel: private-chat.ZPgLCxY6 [12:32:01 AM] - ILArCPOdNHlgywZaAAAZ authenticated for: presence-chat.ZPgLCxY6 [12:32:01 AM] - ILArCPOdNHlgywZaAAAZ joined channel: presence-chat.ZPgLCxY6 (node:13265) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 13): Type Error: Cannot set property 'socketId' of undefined

I already tried what @skatetdieu suggested but it never reached that Broadcast::channel method (I left a log there). I don't know what to do anymore, pls help me. Thanks

abetwothree commented 7 years ago

@lilian21 , are you sure you're using the Laravel Auth system, or least hooking into to it when a user logs in into Laravel?

If you don't use the Laravel Auth system then it won't return a user to the Echo server. This is why the Echo server gets nothing and says that it cannot set the socketId to undefined.

lilian21 commented 7 years ago

Thank you for your response. Indeed, I'm not using Laravel Auth system, I am using JWT token auth. How can I hook into it to make it recognize users based on JWT tokens?

lilian21 commented 7 years ago

Never mind, I switched to laravel passport, looks like it works. Thank you!

tlaverdure commented 6 years ago

Please ensure that the user is authenticated and an array of user data is being returned in the Authorization Callback