diff options
author | dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> | 2022-01-18 20:24:14 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-18 20:24:14 +0100 |
commit | aad60c882e16cd2c8769a49e6d9f87a040590d62 (patch) | |
tree | 3bfe1f8953b40f9beb39c69db3a7647ea6de54d2 /vendor/github.com/mattermost/mattermost-server/v6/model/websocket_client.go | |
parent | fecca575078a21dedb0cab213dde7fd97161c0fa (diff) | |
download | matterbridge-msglm-aad60c882e16cd2c8769a49e6d9f87a040590d62.tar.gz matterbridge-msglm-aad60c882e16cd2c8769a49e6d9f87a040590d62.tar.bz2 matterbridge-msglm-aad60c882e16cd2c8769a49e6d9f87a040590d62.zip |
Bump github.com/mattermost/mattermost-server/v6 from 6.1.0 to 6.3.0 (#1686)
Bumps [github.com/mattermost/mattermost-server/v6](https://github.com/mattermost/mattermost-server) from 6.1.0 to 6.3.0.
- [Release notes](https://github.com/mattermost/mattermost-server/releases)
- [Changelog](https://github.com/mattermost/mattermost-server/blob/master/CHANGELOG.md)
- [Commits](https://github.com/mattermost/mattermost-server/compare/v6.1.0...v6.3.0)
---
updated-dependencies:
- dependency-name: github.com/mattermost/mattermost-server/v6
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Diffstat (limited to 'vendor/github.com/mattermost/mattermost-server/v6/model/websocket_client.go')
-rw-r--r-- | vendor/github.com/mattermost/mattermost-server/v6/model/websocket_client.go | 47 |
1 files changed, 45 insertions, 2 deletions
diff --git a/vendor/github.com/mattermost/mattermost-server/v6/model/websocket_client.go b/vendor/github.com/mattermost/mattermost-server/v6/model/websocket_client.go index 2bd8a3b7..b80d4777 100644 --- a/vendor/github.com/mattermost/mattermost-server/v6/model/websocket_client.go +++ b/vendor/github.com/mattermost/mattermost-server/v6/model/websocket_client.go @@ -6,6 +6,7 @@ package model import ( "bytes" "encoding/json" + "fmt" "net/http" "sync/atomic" "time" @@ -13,6 +14,7 @@ import ( "github.com/mattermost/mattermost-server/v6/shared/mlog" "github.com/gorilla/websocket" + "github.com/vmihailenco/msgpack/v5" ) const ( @@ -25,6 +27,7 @@ type msgType int const ( msgTypeJSON msgType = iota + 1 msgTypePong + msgTypeBinary ) type writeMessage struct { @@ -65,10 +68,26 @@ func NewWebSocketClient(url, authToken string) (*WebSocketClient, error) { return NewWebSocketClientWithDialer(websocket.DefaultDialer, url, authToken) } +func NewReliableWebSocketClientWithDialer(dialer *websocket.Dialer, url, authToken, connID string, seqNo int, withAuthHeader bool) (*WebSocketClient, error) { + connectURL := url + APIURLSuffix + "/websocket" + fmt.Sprintf("?connection_id=%s&sequence_number=%d", connID, seqNo) + var header http.Header + if withAuthHeader { + header = http.Header{ + "Authorization": []string{"Bearer " + authToken}, + } + } + + return makeClient(dialer, url, connectURL, authToken, header) +} + // NewWebSocketClientWithDialer constructs a new WebSocket client with convenience // methods for talking to the server using a custom dialer. func NewWebSocketClientWithDialer(dialer *websocket.Dialer, url, authToken string) (*WebSocketClient, error) { - conn, _, err := dialer.Dial(url+APIURLSuffix+"/websocket", nil) + return makeClient(dialer, url, url+APIURLSuffix+"/websocket", authToken, nil) +} + +func makeClient(dialer *websocket.Dialer, url, connectURL, authToken string, header http.Header) (*WebSocketClient, error) { + conn, _, err := dialer.Dial(connectURL, header) if err != nil { return nil, NewAppError("NewWebSocketClient", "model.websocket_client.connect_fail.app_error", nil, err.Error(), http.StatusInternalServerError) } @@ -76,7 +95,7 @@ func NewWebSocketClientWithDialer(dialer *websocket.Dialer, url, authToken strin client := &WebSocketClient{ URL: url, APIURL: url + APIURLSuffix, - ConnectURL: url + APIURLSuffix + "/websocket", + ConnectURL: connectURL, Conn: conn, AuthToken: authToken, Sequence: 1, @@ -165,6 +184,10 @@ func (wsc *WebSocketClient) writer() { switch msg.msgType { case msgTypeJSON: wsc.Conn.WriteJSON(msg.data) + case msgTypeBinary: + if data, ok := msg.data.([]byte); ok { + wsc.Conn.WriteMessage(websocket.BinaryMessage, data) + } case msgTypePong: wsc.Conn.WriteMessage(websocket.PongMessage, []byte{}) } @@ -258,6 +281,26 @@ func (wsc *WebSocketClient) SendMessage(action string, data map[string]interface } } +func (wsc *WebSocketClient) SendBinaryMessage(action string, data map[string]interface{}) error { + req := &WebSocketRequest{} + req.Seq = wsc.Sequence + req.Action = action + req.Data = data + + binaryData, err := msgpack.Marshal(req) + if err != nil { + return fmt.Errorf("failed to marshal request to msgpack: %w", err) + } + + wsc.Sequence++ + wsc.writeChan <- writeMessage{ + msgType: msgTypeBinary, + data: binaryData, + } + + return nil +} + // UserTyping will push a user_typing event out to all connected users // who are in the specified channel func (wsc *WebSocketClient) UserTyping(channelId, parentId string) { |