// HandlerWS function is handling WebSocket connections
HandlerWS function is handling WebSocket connections
// HandlerWS function is handling WebSocket connections
func (s *Server) handlerWS(w http.ResponseWriter, r *http.Request) {
	c, e := s.upgrader.Upgrade(w, r, nil)
	if e != nil {
		return
	}
	defer c.Close()
	i := s.createWS()
	go func() {
		ch := s.getWriteWS(i)
		for {
			data := <-ch
			msg := s.wsDataToByte(data)
			e := c.WriteMessage(websocket.TextMessage, msg)
			if e != nil {
				break
			}
		}
	}()
	ch := s.getReadWS(i)
	for {
		_, msg, e := c.ReadMessage()
		if e != nil {
			break
		}
		data := s.byteToWsData(msg)
		ch <- data
	}
}
func ( s * Server ) handlerWS ( w http . ResponseWriter , r * http . Request ) { c , e := s . upgrader . Upgrade ( w , r , nil ) if e != nil { return } defer c . Close ( ) i := s . createWS ( ) go func ( ) { ch := s . getWriteWS ( i ) for { data := <- ch msg := s . wsDataToByte ( data ) e := c . WriteMessage ( websocket . TextMessage , msg ) if e != nil { break } } } ( ) ch := s . getReadWS ( i ) for { _ , msg , e := c . ReadMessage ( ) if e != nil { break } data := s . byteToWsData ( msg ) ch <- data } }
HandlerWS function is handling WebSocket connections
HandlerWS function is handling WebSocket connections