TypeError: Cannot read property 'emit' of undefined
bakermanus opened this issue · 12 comments
Hi,
I'm getting the following errors on glitch server
socket.to(roomId).broadcast.emit('user-connected', userId);
^
TypeError: Cannot read property 'emit' of undefined
at Socket.socket.on (/app/server.js:29:32)
at Socket.emit (events.js:198:13)
at Socket.emitUntyped (/rbd/pnpm-volume/44505554-16f9-45c7-831e-72017cc1084c/node_modules/socket.io/dist/typed-events.js:69:22)
at process.nextTick (/rbd/pnpm-volume/44505554-16f9-45c7-831e-72017cc1084c/node_modules/socket.io/dist/socket.js:428:39)
at process._tickCallback (internal/process/next_tick.js:61:11)
Any idea?
Thanks
I had to remove the broadcast call in order for it to work. So I had socket.io(roomId).emit('user-connected', userId);
Hope this helps!
I
thanks it worked
I had to remove the broadcast call in order for it to work. So I had socket.io(roomId).emit('user-connected', userId);
Hope this helps!
thanks, it worked
That didn't work for me but this one worked for me!
socket.broadcast.to(roomId).emit('user-connected', userId);
Guys i saw Cleverprogrammer Zoom video in that when a new user joined it showed up in the console but @GoodMan-04 when i replaced your code it not console.log the user will it still work ?. Please help
I had to remove the broadcast call in order for it to work. So I had socket.io(roomId).emit('user-connected', userId); Hope this helps!
Thank you so much... This really helpeddd...
That didn't work for me but this one worked for me!
socket.broadcast.to(roomId).emit('user-connected', userId);
This is what worked for me. Thanks for sharing.
That didn't work for me but this one worked for me!
socket.broadcast.to(roomId).emit('user-connected', userId);
Thanks for sharing bro, this worked for me......
This works when you join on the same room(same roomId),
socket.broadcast.to(roomId).emit('user-connected', userId);
I had to remove the broadcast call in order for it to work. So I had socket.io(roomId).emit('user-connected', userId); Hope this helps!
It worked for me. Thanks
finally it works, Thanks