| 48 | } |
| 49 | |
| 50 | func newClient(conn *websocket.Conn, req *http.Request, read chan ClientMessage, authenticatedUser string, authenticated, trustProxy bool) *Client { |
| 51 | ip := conn.RemoteAddr().(*net.TCPAddr).IP |
| 52 | if realIP := req.Header.Get("X-Real-IP"); trustProxy && realIP != "" { |
| 53 | ip = net.ParseIP(realIP) |
| 54 | } |
| 55 | |
| 56 | client := &Client{ |
| 57 | conn: conn, |
| 58 | info: ClientInfo{ |
| 59 | Authenticated: authenticated, |
| 60 | AuthenticatedUser: authenticatedUser, |
| 61 | ID: xid.New(), |
| 62 | Addr: ip, |
| 63 | Write: make(chan outgoing.Message, 1), |
| 64 | }, |
| 65 | read: read, |
| 66 | } |
| 67 | client.debug().Msg("WebSocket New Connection") |
| 68 | return client |
| 69 | } |
| 70 | |
| 71 | // CloseOnError closes the connection. |
| 72 | func (c *Client) CloseOnError(code int, reason string) { |