func (k *Kite) sockjsHandler(session sockjs.Session) { defer session.Close(0, "") // This Client also handles the connected client. // Since both sides can send/receive messages the client code is reused here. c := k.NewClient("") c.session = session go c.sendHub() c.wg.Add(1) // with sendHub we added a new listener k.callOnConnectHandlers(c) // Run after methods are registered and delegate is set c.readLoop() c.callOnDisconnectHandlers() k.callOnDisconnectHandlers(c) }
// sockJSHandler called when new client connection comes to SockJS endpoint. func (app *Application) sockJSHandler(s sockjs.Session) { c, err := newClient(app, s) if err != nil { logger.ERROR.Println(err) return } defer c.clean() logger.INFO.Printf("new SockJS session established with uid %s\n", c.uid()) for { if msg, err := s.Recv(); err == nil { err = c.message([]byte(msg)) if err != nil { logger.ERROR.Println(err) s.Close(CloseStatus, "error handling message") break } continue } break } }
func closeHandler(conn sockjs.Session) { conn.Close(3000, "Go away!") }
func accessDenied(s sockjs.Session) error { return s.Close(http.StatusForbidden, http.StatusText(http.StatusForbidden)) }