Add convenience function to broadcast to multiple sessions

This commit is contained in:
Robbie Trencheny
2017-03-28 14:17:41 -07:00
parent 3e26c38d4c
commit 0ded2b7599
+10
View File
@@ -232,6 +232,16 @@ func (m *Melody) BroadcastOthers(msg []byte, s *Session) error {
})
}
// BroadcastMultiple broadcasts a text message to multiple sessions given in the sessions slice.
func (m *Melody) BroadcastMultiple(msg []byte, sessions []*Session) error {
return m.BroadcastFilter(msg, func(q *Session) bool {
for _, sess := range sessions {
return sess == q
}
return false
})
}
// BroadcastBinary broadcasts a binary message to all sessions.
func (m *Melody) BroadcastBinary(msg []byte) error {
if m.hub.closed() {