mirror of
https://github.com/FluuxIO/go-xmpp.git
synced 2024-11-21 10:02:00 -08:00
parent
6a3833b27d
commit
f41177775a
10
client.go
10
client.go
@ -108,6 +108,9 @@ Setting up the client / Checking the parameters
|
|||||||
// If host is not specified, the DNS SRV should be used to find the host from the domainpart of the JID.
|
// If host is not specified, the DNS SRV should be used to find the host from the domainpart of the JID.
|
||||||
// Default the port to 5222.
|
// Default the port to 5222.
|
||||||
func NewClient(config Config, r *Router) (c *Client, err error) {
|
func NewClient(config Config, r *Router) (c *Client, err error) {
|
||||||
|
if config.KeepaliveInterval == 0 {
|
||||||
|
config.KeepaliveInterval = time.Second * 30
|
||||||
|
}
|
||||||
// Parse JID
|
// Parse JID
|
||||||
if config.parsedJid, err = NewJid(config.Jid); err != nil {
|
if config.parsedJid, err = NewJid(config.Jid); err != nil {
|
||||||
err = errors.New("missing jid")
|
err = errors.New("missing jid")
|
||||||
@ -185,7 +188,7 @@ func (c *Client) Resume(state SMState) error {
|
|||||||
|
|
||||||
// Start the keepalive go routine
|
// Start the keepalive go routine
|
||||||
keepaliveQuit := make(chan struct{})
|
keepaliveQuit := make(chan struct{})
|
||||||
go keepalive(c.transport, keepaliveQuit)
|
go keepalive(c.transport, c.config.KeepaliveInterval, keepaliveQuit)
|
||||||
// Start the receiver go routine
|
// Start the receiver go routine
|
||||||
state = c.Session.SMState
|
state = c.Session.SMState
|
||||||
// Leaving this channel here for later. Not used atm. We should return this instead of an error because right
|
// Leaving this channel here for later. Not used atm. We should return this instead of an error because right
|
||||||
@ -312,9 +315,8 @@ func (c *Client) recv(state SMState, keepaliveQuit chan<- struct{}, errChan chan
|
|||||||
// Loop: send whitespace keepalive to server
|
// Loop: send whitespace keepalive to server
|
||||||
// This is use to keep the connection open, but also to detect connection loss
|
// This is use to keep the connection open, but also to detect connection loss
|
||||||
// and trigger proper client connection shutdown.
|
// and trigger proper client connection shutdown.
|
||||||
func keepalive(transport Transport, quit <-chan struct{}) {
|
func keepalive(transport Transport, interval time.Duration, quit <-chan struct{}) {
|
||||||
// TODO: Make keepalive interval configurable
|
ticker := time.NewTicker(interval)
|
||||||
ticker := time.NewTicker(30 * time.Second)
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
|
14
config.go
14
config.go
@ -2,6 +2,7 @@ package xmpp
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Config & TransportConfiguration must not be modified after having been passed to NewClient. Any
|
// Config & TransportConfiguration must not be modified after having been passed to NewClient. Any
|
||||||
@ -9,12 +10,13 @@ import (
|
|||||||
type Config struct {
|
type Config struct {
|
||||||
TransportConfiguration
|
TransportConfiguration
|
||||||
|
|
||||||
Jid string
|
Jid string
|
||||||
parsedJid *Jid // For easier manipulation
|
parsedJid *Jid // For easier manipulation
|
||||||
Credential Credential
|
Credential Credential
|
||||||
StreamLogger *os.File // Used for debugging
|
StreamLogger *os.File // Used for debugging
|
||||||
Lang string // TODO: should default to 'en'
|
Lang string // TODO: should default to 'en'
|
||||||
ConnectTimeout int // Client timeout in seconds. Default to 15
|
KeepaliveInterval time.Duration // Interval between keepalive packets
|
||||||
|
ConnectTimeout int // Client timeout in seconds. Default to 15
|
||||||
// Insecure can be set to true to allow to open a session without TLS. If TLS
|
// Insecure can be set to true to allow to open a session without TLS. If TLS
|
||||||
// is supported on the server, we will still try to use it.
|
// is supported on the server, we will still try to use it.
|
||||||
Insecure bool
|
Insecure bool
|
||||||
|
Loading…
Reference in New Issue
Block a user