From 0ded2b75991abc5b0d85eb8eb0f4d29c1b0aa495 Mon Sep 17 00:00:00 2001 From: Robbie Trencheny Date: Tue, 28 Mar 2017 14:17:41 -0700 Subject: [PATCH] Add convenience function to broadcast to multiple sessions --- melody.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/melody.go b/melody.go index 0822dee..a1745ed 100644 --- a/melody.go +++ b/melody.go @@ -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() {