CleverProgrammers / nodejs-zoom-clone

847 stars 484 forks source link

TypeError: Cannot read property 'emit' of undefined #35

Open bakermanus opened 3 years ago

bakermanus commented 3 years ago

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

rhammock1 commented 3 years ago

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!

SOG-web commented 3 years ago

I

thanks it worked

SOG-web commented 3 years ago

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

GoodMan-04 commented 3 years ago

That didn't work for me but this one worked for me!

socket.broadcast.to(roomId).emit('user-connected', userId);

CoderZ90 commented 3 years ago

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

megasg commented 2 years ago

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...

Hug0P1res commented 2 years ago

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.

Suresh8000 commented 2 years ago

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......

anujmittal2308 commented 2 years ago

https://stackoverflow.com/questions/72003682/cant-fix-expresspeerserver-is-not-a-function-in-server-js

Monisankarnath commented 2 years ago

This works when you join on the same room(same roomId), socket.broadcast.to(roomId).emit('user-connected', userId);

yagyesh-bobde commented 1 year ago

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

anulmehta48 commented 1 year ago

finally it works, Thanks