Files
lislgosms/gateway/internal/inbound/server.go
T

39 lines
902 B
Go

package inbound
import (
cmpp "github.com/bigwhite/gocmpp"
"io"
"log"
"net/http"
"time"
)
const defaultHTTPTimeout = 10 * time.Second
type Server struct {
Addr string
APIBaseURL string
SecurityEventToken string
HTTPClient *http.Client
LogWriter io.Writer
PendingFlushInterval time.Duration
PresenceStore PresenceStore
RecoveryStore RecoveryStore
GatewayInstanceID string
}
func (s Server) ListenAndServe() error {
addr := s.Addr
if addr == "" {
addr = ":17890"
}
s.logRecoveryCandidates(log.Default())
go s.recoverPendingCandidates(log.Default())
go s.runPendingFlusher(log.Default())
return cmpp.ListenAndServeWithClose(addr, cmpp.V30, 30*time.Second, 3, s.LogWriter, s.handleConnectionClosed,
cmpp.HandlerFunc(s.handleLogin),
cmpp.HandlerFunc(s.handleSubmit),
cmpp.HandlerFunc(s.handleActivity),
)
}