mirror of
https://github.com/FluuxIO/go-xmpp.git
synced 2024-11-24 11:32:00 -08:00
Negotiate xmpp websocket subprotocol
This commit is contained in:
parent
36e153f981
commit
25fd476328
@ -2,6 +2,7 @@ package xmpp
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"net"
|
"net"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -11,6 +12,8 @@ import (
|
|||||||
|
|
||||||
const pingTimeout = time.Duration(5) * time.Second
|
const pingTimeout = time.Duration(5) * time.Second
|
||||||
|
|
||||||
|
var ServerDoesNotSupportXmppOverWebsocket = errors.New("The websocket server does not support the xmpp subprotocol")
|
||||||
|
|
||||||
type WebsocketTransport struct {
|
type WebsocketTransport struct {
|
||||||
Config TransportConfiguration
|
Config TransportConfiguration
|
||||||
wsConn *websocket.Conn
|
wsConn *websocket.Conn
|
||||||
@ -27,10 +30,15 @@ func (t *WebsocketTransport) Connect() error {
|
|||||||
defer cancel()
|
defer cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
wsConn, _, err := websocket.Dial(t.ctx, t.Config.Address, nil)
|
wsConn, response, err := websocket.Dial(t.ctx, t.Config.Address, &websocket.DialOptions{
|
||||||
|
Subprotocols: []string{"xmpp"},
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return NewConnError(err, true)
|
return NewConnError(err, true)
|
||||||
}
|
}
|
||||||
|
if response.Header.Get("Sec-WebSocket-Protocol") != "xmpp" {
|
||||||
|
return ServerDoesNotSupportXmppOverWebsocket
|
||||||
|
}
|
||||||
t.wsConn = wsConn
|
t.wsConn = wsConn
|
||||||
t.netConn = websocket.NetConn(t.ctx, t.wsConn, websocket.MessageText)
|
t.netConn = websocket.NetConn(t.ctx, t.wsConn, websocket.MessageText)
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user