Multicast push the message to the filtered clients
(route string, v interface{}, filter SessionFilter)
| 87 | |
| 88 | // Multicast push the message to the filtered clients |
| 89 | func (c *Group) Multicast(route string, v interface{}, filter SessionFilter) error { |
| 90 | if c.isClosed() { |
| 91 | return ErrClosedGroup |
| 92 | } |
| 93 | |
| 94 | data, err := message.Serialize(v) |
| 95 | if err != nil { |
| 96 | return err |
| 97 | } |
| 98 | |
| 99 | if env.Debug { |
| 100 | log.Println(fmt.Sprintf("Multicast %s, Data=%+v", route, v)) |
| 101 | } |
| 102 | |
| 103 | c.mu.RLock() |
| 104 | defer c.mu.RUnlock() |
| 105 | |
| 106 | for _, s := range c.sessions { |
| 107 | if !filter(s) { |
| 108 | continue |
| 109 | } |
| 110 | if err = s.Push(route, data); err != nil { |
| 111 | log.Println(err.Error()) |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | return nil |
| 116 | } |
| 117 | |
| 118 | // Broadcast push the message(s) to all members |
| 119 | func (c *Group) Broadcast(route string, v interface{}) error { |