Browse Source

melody instance channels

master
tooooommy 5 years ago
parent
commit
1333d0784c
  1. 1
      examples/broadcast/main.go
  2. 12
      melody.go

1
examples/broadcast/main.go

@ -35,7 +35,6 @@ func main() {
return false return false
}) })
} }
}) })
m.HandleSentMessage(func(session *melody.Session, bytes []byte) { m.HandleSentMessage(func(session *melody.Session, bytes []byte) {

12
melody.go

@ -317,6 +317,18 @@ func FormatCloseMessage(closeCode int, text string) []byte {
} }
// extends // extends
func (m *Melody) Channels() map[string]*Channel {
return m.hub.channels
}
func (m *Melody)Channel(name string) *Channel {
if ch, ok := m.hub.channels[name]; ok {
return ch
}
return nil
}
func (m *Melody) Subscribe(s *Session, c string) error { func (m *Melody) Subscribe(s *Session, c string) error {
if m.hub.closed() { if m.hub.closed() {
return errors.New("melody instance is already closed") return errors.New("melody instance is already closed")

Loading…
Cancel
Save