forked from jshiffer/go-xmpp
Move address into transport config
This makes it possible to use a factory function to create a transport of the right type and not having to repeat the address when calling Transport.Connect()
This commit is contained in:
committed by
Mickaël Rémond
parent
f8d0e99696
commit
7fa4b06705
@@ -11,21 +11,22 @@ import (
|
||||
)
|
||||
|
||||
type WebsocketTransport struct {
|
||||
Config TransportConfiguration
|
||||
wsConn *websocket.Conn
|
||||
netConn net.Conn
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
func (t *WebsocketTransport) Connect(address string, c Config) error {
|
||||
func (t *WebsocketTransport) Connect() error {
|
||||
t.ctx = context.Background()
|
||||
|
||||
ctx, cancel := context.WithTimeout(t.ctx, time.Duration(c.ConnectTimeout)*time.Second)
|
||||
ctx, cancel := context.WithTimeout(t.ctx, time.Duration(t.Config.ConnectTimeout)*time.Second)
|
||||
defer cancel()
|
||||
|
||||
if !c.Insecure && strings.HasPrefix(address, "wss:") {
|
||||
return errors.New("Websocket address is not secure")
|
||||
}
|
||||
wsConn, _, err := websocket.Dial(ctx, address, nil)
|
||||
wsConn, _, err := websocket.Dial(ctx, t.Config.Address, nil)
|
||||
if err != nil {
|
||||
t.wsConn = wsConn
|
||||
t.netConn = websocket.NetConn(t.ctx, t.wsConn, websocket.MessageText)
|
||||
|
||||
Reference in New Issue
Block a user