Compare commits

..

2 commits

Author SHA1 Message Date
Bohdan Horbeshko e55463fc98 Fix passing Component to StreamManager
0a4acd12c3, which fixes #160, introduced
a regression as it assumed only Client may implement StreamClient, and
passing a component triggers an unconditional "client is not
disconnected" error.
2021-12-18 10:55:35 -05:00
bodqhrohro 5f99e1cd06 Support partial JIDs in Bare/Full methods 2021-12-14 12:01:36 +01:00
3 changed files with 16 additions and 22 deletions

View file

@ -21,7 +21,6 @@ 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,7 +16,6 @@ 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 {
@ -49,15 +48,6 @@ 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,18 +114,23 @@ func (sm *StreamManager) Stop() {
func (sm *StreamManager) connect() error {
if sm.client != nil {
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
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 sm.PostConnect != nil {
sm.PostConnect(sm.client)
}
return nil
}
}
return errors.New("client is not disconnected")