Request to subscribe to a topic
(msg *ClientComMessage)
| 210 | |
| 211 | // Request to subscribe to a topic |
| 212 | func (s *Session) subscribe(msg *ClientComMessage) { |
| 213 | log.Printf("Sub to '%s' from '%s'", msg.Sub.Topic, msg.from) |
| 214 | |
| 215 | var topic, expanded string |
| 216 | |
| 217 | if msg.Sub.Topic == "new" { |
| 218 | // Request to create a new named topic |
| 219 | topic = msg.Sub.Topic |
| 220 | expanded = genTopicName() |
| 221 | } else { |
| 222 | var err *ServerComMessage |
| 223 | topic, expanded, err = s.validateTopicName(msg.Sub.Id, msg.Sub.Topic, msg.timestamp) |
| 224 | if err != nil { |
| 225 | s.QueueOut(err) |
| 226 | return |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | if _, ok := s.subs[expanded]; ok { |
| 231 | log.Printf("sess.subscribe: already subscribed to '%s'", expanded) |
| 232 | s.QueueOut(InfoAlreadySubscribed(msg.Sub.Id, msg.Sub.Topic, msg.timestamp)) |
| 233 | return |
| 234 | } |
| 235 | |
| 236 | log.Printf("Sub to '%s' (%s) from '%s' as '%s' -- OK!", expanded, msg.Sub.Topic, msg.from, topic) |
| 237 | globals.hub.reg <- &sessionJoin{topic: expanded, pkt: msg.Sub, sess: s} |
| 238 | // Hub will send Ctrl success/failure packets back to session |
| 239 | } |
| 240 | |
| 241 | // Leave/Unsubscribe a topic |
| 242 | func (s *Session) leave(msg *ClientComMessage) { |
no test coverage detected