Compare commits

..

3 commits

3 changed files with 22 additions and 16 deletions

View file

@ -21,6 +21,7 @@ type DiscoInfo struct {
Identity []Identity `xml:"identity"`
Features []Feature `xml:"feature"`
ResultSet *ResultSet `xml:"set,omitempty"`
Form *Form `xml:"x,omitempty"`
}
// Namespace lets DiscoInfo implement the IQPayload interface

View file

@ -16,6 +16,7 @@ func TestDiscoInfo_Builder(t *testing.T) {
disco := iq.DiscoInfo()
disco.AddIdentity("Test Component", "gateway", "service")
disco.AddFeatures(stanza.NSDiscoInfo, stanza.NSDiscoItems, "jabber:iq:version", "urn:xmpp:delegation:1")
disco.Form = stanza.NewForm([]*stanza.Field{}, "result")
parsedIQ, err := checkMarshalling(t, iq)
if err != nil {
@ -48,6 +49,15 @@ func TestDiscoInfo_Builder(t *testing.T) {
t.Errorf("Incorrect identity name: %#v", pp.Identity[0].Name)
}
}
// Check form
if pp.Form == nil {
t.Errorf("Form is nil")
} else {
if len(pp.Form.Fields) != 0 {
t.Errorf("Form fields length mismatch: %#v", pp.Form.Fields)
}
}
}
// Implements XEP-0030 example 17

View file

@ -114,23 +114,18 @@ func (sm *StreamManager) Stop() {
func (sm *StreamManager) connect() error {
if sm.client != nil {
var scs *SyncConnState
if client, ok := sm.client.(*Client); ok {
scs = &client.CurrentState
}
if component, ok := sm.client.(*Component); ok {
scs = &component.CurrentState
}
if scs != nil && scs.getState() == StateDisconnected {
sm.Metrics = initMetrics()
err := sm.client.Connect()
if err != nil {
return err
if c, ok := sm.client.(*Client); ok {
if c.CurrentState.getState() == StateDisconnected {
sm.Metrics = initMetrics()
err := c.Connect()
if err != nil {
return err
}
if sm.PostConnect != nil {
sm.PostConnect(sm.client)
}
return nil
}
if sm.PostConnect != nil {
sm.PostConnect(sm.client)
}
return nil
}
}
return errors.New("client is not disconnected")