1đ
Itâs quite unclear what youâre trying to do, but if i understand correctly, you want the âcreatedâ event to be emitted to all sockets, after one socket triggers the âcreateâ event. If so:
socket.on('create',(name)=> {
io.of('/').emit('created', {name})
})
Problem is, that for some reason youâre registering the âconnectionâ event within some âcreateâ function, which doesnât seem to make much sense. Your io.on(âconnectionâ) needs to be registered once, in some high level module, and within its scope you need to register all specific events for the connecting socket. I donât have your full code, so i canât say, but this is something you need to look at.
- [Vuejs]-Vuex state is sometimes empty (undefined), especially when I refresh the page and sometimes it works
- [Vuejs]-Does vue download all page in client side?
0đ
I found the answer myself. The problem is that i was using
**socket.emit('postVoted', {updatedPost})**
Where socket.emit Means that the updated data its comming to the user who created that action, but changing that event to:
**io.sockets.emit**
This way every use gets the updated data.
Clearly im not expert with socketio,any good course about sockets? thanks
NOTE : I have seriues doubts about using 2 .on(âconnectionâ) methods, any advice on how to module this?