adonis-websocket icon indicating copy to clipboard operation
adonis-websocket copied to clipboard

Fix cluster broadcast when emitting only to specified ids

Open Ruby184 opened this issue 7 years ago • 1 comments

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.

Ruby184 avatar Jul 23 '18 07:07 Ruby184

Coverage Status

Coverage decreased (-0.2%) to 93.484% when pulling 14d86968ecb3c1b5e5af7ecafb2c5d788ab7cf24 on Ruby184:broadcast-fix into 27143fdf833b06d565330b2f83c1ce0c46a11f0d on adonisjs:develop.

coveralls avatar Jul 23 '18 07:07 coveralls