7 log "github.com/sirupsen/logrus"
9 "github.com/bytom/vapor/net/websocket"
12 // timeZeroVal is simply the zero value for a time.Time and is used to avoid
13 // creating multiple instances.
14 var timeZeroVal time.Time
16 // WebsocketHandler handles connections and requests from websocket client
17 func (a *API) websocketHandler(w http.ResponseWriter, r *http.Request) {
18 log.WithField("remoteAddress", r.RemoteAddr).Info("New websocket client")
20 client, err := websocket.NewWebsocketClient(w, r, a.notificationMgr)
22 log.WithField("error", err).Error("Failed to new websocket client")
23 http.Error(w, "400 Bad Request.", http.StatusBadRequest)
27 a.notificationMgr.AddClient(client)
29 client.WaitForShutdown()
30 a.notificationMgr.RemoveClient(client)
31 log.WithField("address", r.RemoteAddr).Infoln("Disconnected websocket client")