diff --git a/model/websocket_client.go b/model/websocket_client.go index 8d9a8330e8..c0235793a6 100644 --- a/model/websocket_client.go +++ b/model/websocket_client.go @@ -17,17 +17,19 @@ const ( PING_TIMEOUT_BUFFER_SECONDS = 5 ) +// WebSocketClient stores the necessary information required to +// communicate with a WebSocket endpoint. type WebSocketClient struct { - Url string // The location of the server like "ws://localhost:8065" - ApiUrl string // The api location of the server like "ws://localhost:8065/api/v3" - ConnectUrl string // The websocket URL to connect to like "ws://localhost:8065/api/v3/path/to/websocket" - Conn *websocket.Conn // The WebSocket connection - AuthToken string // The token used to open the WebSocket - Sequence int64 // The ever-incrementing sequence attached to each WebSocket action - PingTimeoutChannel chan bool // The channel used to signal ping timeouts - EventChannel chan *WebSocketEvent - ResponseChannel chan *WebSocketResponse - ListenError *AppError + Url string // The location of the server like "ws://localhost:8065" + ApiUrl string // The API location of the server like "ws://localhost:8065/api/v3" + ConnectUrl string // The WebSocket URL to connect to like "ws://localhost:8065/api/v3/path/to/websocket" + Conn *websocket.Conn // The WebSocket connection + AuthToken string // The token used to open the WebSocket connection + Sequence int64 // The ever-incrementing sequence attached to each WebSocket action + PingTimeoutChannel chan bool // The channel used to signal ping timeouts + EventChannel chan *WebSocketEvent // The channel used to receive various events pushed from the server. For example: typing, posted + ResponseChannel chan *WebSocketResponse // The channel used to receive responses for requests made to the server + ListenError *AppError // A field that is set if there was an abnormal closure of the WebSocket connection pingTimeoutTimer *time.Timer } diff --git a/model/websocket_message.go b/model/websocket_message.go index bcf0f62775..cd2720a5fa 100644 --- a/model/websocket_message.go +++ b/model/websocket_message.go @@ -199,11 +199,14 @@ func WebSocketEventFromJson(data io.Reader) *WebSocketEvent { return &ev } +// WebSocketResponse represents a response received through the WebSocket +// for a request made to the server. This is available through the ResponseChannel +// channel in WebSocketClient. type WebSocketResponse struct { - Status string `json:"status"` - SeqReply int64 `json:"seq_reply,omitempty"` - Data map[string]interface{} `json:"data,omitempty"` - Error *AppError `json:"error,omitempty"` + Status string `json:"status"` // The status of the response. For example: OK, FAIL. + SeqReply int64 `json:"seq_reply,omitempty"` // A counter which is incremented for every response sent. + Data map[string]interface{} `json:"data,omitempty"` // The data contained in the response. + Error *AppError `json:"error,omitempty"` // A field that is set if any error has occurred. } func (m *WebSocketResponse) Add(key string, value interface{}) { diff --git a/model/websocket_request.go b/model/websocket_request.go index 2186209a0d..6628a5c90b 100644 --- a/model/websocket_request.go +++ b/model/websocket_request.go @@ -10,11 +10,12 @@ import ( goi18n "github.com/mattermost/go-i18n/i18n" ) +// WebSocketRequest represents a request made to the server through a websocket. type WebSocketRequest struct { // Client-provided fields - Seq int64 `json:"seq"` - Action string `json:"action"` - Data map[string]interface{} `json:"data"` + Seq int64 `json:"seq"` // A counter which is incremented for every request made. + Action string `json:"action"` // The action to perform for a request. For example: get_statuses, user_typing. + Data map[string]interface{} `json:"data"` // The metadata for an action. // Server-provided fields Session Session `json:"-"`