adonis-websocket
adonis-websocket copied to clipboard
Fix cluster broadcast when emitting only to specified ids
Proposed changes
When I was playing with the cluster to implement PM2 support I realized that when using Socket.emitTo method, payload is sent to specified socket ids on current worker, but then broadcasted to other cluster workers and sent to all sockets - filtering of ids is not preserved. So I added these arguments to message broacasted by ClusterHop. Also I added an ability to specify ids ommited by broadcast. Examle:
// broacast to all sockets except the current one (socket.id)
socket.broadcast('event', 'data')
// broadcast to all except sockets with ids "id1" and "id2"
socket.broadcast('event', 'data', ['id1', 'id2'])
// also when using channel
channel.topic('topic').broadcast('event', 'data', ['id1', 'id2'])
Types of changes
- [x] Bugfix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
Checklist
- [x] I have read the CONTRIBUTING doc
- [x] Lint and unit tests pass locally with my changes
- [ ] I have added tests that prove my fix is effective or that my feature works.
- [ ] I have added necessary documentation (if appropriate)
Further comments
I will add tests just tell me if you are OK with the changes made. Thank you.