|
|
|
@ -3,6 +3,7 @@ package xmpp
|
|
|
|
|
import (
|
|
|
|
|
"crypto/tls"
|
|
|
|
|
"errors"
|
|
|
|
|
"strings"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var TLSNotSupported = errors.New("Transport does not support StartTLS")
|
|
|
|
@ -29,7 +30,14 @@ type Transport interface {
|
|
|
|
|
Close() error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NewTransport creates a new Transport instance.
|
|
|
|
|
// The type of transport is determined by the address in the configuration:
|
|
|
|
|
// - if the address is a URL with the `ws` or `wss` scheme WebsocketTransport is used
|
|
|
|
|
// - in all other cases a XMPPTransport is used
|
|
|
|
|
// For XMPPTransport it is mandatory for the address to have a port specified.
|
|
|
|
|
func NewTransport(config TransportConfiguration) Transport {
|
|
|
|
|
if strings.HasPrefix(config.Address, "ws:") || strings.HasPrefix(config.Address, "wss:") {
|
|
|
|
|
return &WebsocketTransport{Config: config}
|
|
|
|
|
}
|
|
|
|
|
return &XMPPTransport{Config: config}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|