示例#1
0
// Connect connects to the server and starts the main threads
func (s *session) Connect(password string) error {
	if !s.IsDisconnected() {
		return nil
	}

	s.setStatus(CONNECTING)

	if s.connectionLogger == nil {
		s.connectionLogger = newLogger()
	}

	conf := s.GetConfig()
	policy := config.ConnectionPolicy{
		Logger:     s.connectionLogger,
		XMPPLogger: s.xmppLogger,
	}

	conn, err := policy.Connect(password, conf)
	if err != nil {
		s.alert(err.Error())
		s.setStatus(DISCONNECTED)

		return err
	}

	s.conn = conn
	s.setStatus(CONNECTED)

	s.conn.SignalPresence("")
	go s.watchRoster()
	go s.watchTimeout()
	go s.watchStanzas()

	return nil
}
示例#2
0
文件: session.go 项目: twstrike/coyim
// Connect connects to the server and starts the main threads
func (s *session) Connect(password string, verifier tls.Verifier) error {
	if !s.IsDisconnected() {
		return nil
	}

	s.setStatus(CONNECTING)

	conf := s.GetConfig()
	policy := config.ConnectionPolicy{
		Logger:        s.connectionLogger,
		XMPPLogger:    s.xmppLogger,
		DialerFactory: s.dialerFactory,
	}

	conn, err := policy.Connect(password, conf, verifier)
	if err != nil {
		s.setStatus(DISCONNECTED)

		return err
	}

	if s.connStatus == CONNECTING {
		s.conn = conn
		s.setStatus(CONNECTED)

		conn.SignalPresence("")
		go s.watchRoster()
		go s.getVCard()
		go s.watchTimeout()
		go s.watchStanzas()
	} else {
		if s.conn != nil {
			s.conn.Close()
		}
	}

	return nil
}