subCommonReply generates a response to a subscription request
(h *Hub, sess *Session, pkt *MsgClientSub, sendInfo bool, created bool)
| 334 | |
| 335 | // subCommonReply generates a response to a subscription request |
| 336 | func (t *Topic) subCommonReply(h *Hub, sess *Session, pkt *MsgClientSub, sendInfo bool, created bool) error { |
| 337 | log.Println("subCommonReply ", t.name) |
| 338 | now := time.Now().UTC().Round(time.Millisecond) |
| 339 | |
| 340 | // The topic t is already initialized by the Hub |
| 341 | |
| 342 | var info, private interface{} |
| 343 | var mode string |
| 344 | |
| 345 | if pkt.Sub != nil { |
| 346 | if pkt.Sub.User != "" { |
| 347 | log.Println("subCommonReply: msg.Sub.Sub.User is ", pkt.Sub.User) |
| 348 | simpleByteSender(sess.send, ErrMalformed(pkt.Id, t.original, now)) |
| 349 | return errors.New("user id must not be specified") |
| 350 | } |
| 351 | |
| 352 | info = pkt.Sub.Info |
| 353 | mode = pkt.Sub.Mode |
| 354 | } |
| 355 | |
| 356 | if pkt.Init != nil { |
| 357 | private = pkt.Init.Private |
| 358 | } |
| 359 | |
| 360 | if err := t.requestSub(h, sess, pkt.Id, mode, info, private); err != nil { |
| 361 | return err |
| 362 | } |
| 363 | |
| 364 | simpleByteSender(sess.send, NoErr(pkt.Id, t.original, now)) |
| 365 | |
| 366 | if sendInfo { |
| 367 | t.replyGetInfo(sess, pkt.Id, created) |
| 368 | } |
| 369 | |
| 370 | return nil |
| 371 | } |
| 372 | |
| 373 | // User requests or updates a self-subscription to a topic |
| 374 | // h - hub |
no test coverage detected