forked from jshiffer/go-xmpp
Fix import and test
This commit is contained in:
parent
2d95ca9384
commit
6fc12e9779
24
component.go
24
component.go
@ -9,8 +9,6 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gosrc.io/xmpp"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const componentStreamOpen = "<?xml version='1.0'?><stream:stream to='%s' xmlns='%s' xmlns:stream='%s'>"
|
const componentStreamOpen = "<?xml version='1.0'?><stream:stream to='%s' xmlns='%s' xmlns:stream='%s'>"
|
||||||
@ -140,11 +138,11 @@ func (c *Component) recv() (err error) {
|
|||||||
close(c.RecvChannel)
|
close(c.RecvChannel)
|
||||||
c.streamError(p.Error.Local, p.Text)
|
c.streamError(p.Error.Local, p.Text)
|
||||||
return errors.New("stream error: " + p.Error.Local)
|
return errors.New("stream error: " + p.Error.Local)
|
||||||
case xmpp.IQ:
|
case IQ:
|
||||||
switch inner := p.Payload[0].(type) {
|
switch inner := p.Payload[0].(type) {
|
||||||
// Our component module handle disco info but can let component implementation
|
// Our component module handle disco info but can let component implementation
|
||||||
// handle disco items queries
|
// handle disco items queries
|
||||||
case *xmpp.DiscoInfo:
|
case *DiscoInfo:
|
||||||
if p.Type == "get" {
|
if p.Type == "get" {
|
||||||
c.discoResult(p.PacketAttrs, inner)
|
c.discoResult(p.PacketAttrs, inner)
|
||||||
}
|
}
|
||||||
@ -223,25 +221,25 @@ func (handshakeDecoder) decode(p *xml.Decoder, se xml.StartElement) (Handshake,
|
|||||||
|
|
||||||
// Service discovery
|
// Service discovery
|
||||||
|
|
||||||
func (c *Component) discoResult(attrs xmpp.PacketAttrs, info *xmpp.DiscoInfo) {
|
func (c *Component) discoResult(attrs PacketAttrs, info *DiscoInfo) {
|
||||||
iq := xmpp.NewIQ("result", attrs.To, attrs.From, attrs.Id, "en")
|
iq := NewIQ("result", attrs.To, attrs.From, attrs.Id, "en")
|
||||||
var identity xmpp.Identity
|
var identity Identity
|
||||||
if info.Node == "" {
|
if info.Node == "" {
|
||||||
identity = xmpp.Identity{
|
identity = Identity{
|
||||||
Name: c.Name,
|
Name: c.Name,
|
||||||
Category: c.Category,
|
Category: c.Category,
|
||||||
Type: c.Type,
|
Type: c.Type,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
payload := xmpp.DiscoInfo{
|
payload := DiscoInfo{
|
||||||
Identity: identity,
|
Identity: identity,
|
||||||
Features: []xmpp.Feature{
|
Features: []Feature{
|
||||||
{Var: xmpp.NSDiscoInfo},
|
{Var: NSDiscoInfo},
|
||||||
{Var: xmpp.NSDiscoItems},
|
{Var: NSDiscoItems},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
iq.AddPayload(&payload)
|
iq.AddPayload(&payload)
|
||||||
|
|
||||||
_ = c.xmpp.Send(iq)
|
_ = c.Send(iq)
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,11 @@ package xmpp // import "gosrc.io/xmpp"
|
|||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
func TestHandshake(t *testing.T) {
|
func TestHandshake(t *testing.T) {
|
||||||
c := Component{
|
opts := ComponentOptions{
|
||||||
Host: "test.localhost",
|
Domain: "test.localhost",
|
||||||
Secret: "mypass",
|
Secret: "mypass",
|
||||||
}
|
}
|
||||||
|
c := Component{ComponentOptions: opts}
|
||||||
|
|
||||||
streamID := "1263952298440005243"
|
streamID := "1263952298440005243"
|
||||||
expected := "c77e2ef0109fbbc5161e83b51629cd1353495332"
|
expected := "c77e2ef0109fbbc5161e83b51629cd1353495332"
|
||||||
|
Loading…
Reference in New Issue
Block a user