--- a/xmpp.go Tue Mar 26 10:54:44 2013 -0600
+++ b/xmpp.go Fri Aug 30 17:24:39 2013 -0600
@@ -19,7 +19,7 @@
const (
// Version of RFC 3920 that we implement.
- Version = "1.0"
+ XMPPVersion = "1.0"
// Various XML namespaces.
NsClient = "jabber:client"
@@ -36,24 +36,6 @@
clientSrv = "xmpp-client"
)
-// This channel may be used as a convenient way to generate a unique
-// id for an iq, message, or presence stanza.
-var Id <-chan string
-
-func init() {
- // Start the unique id generator.
- idCh := make(chan string)
- Id = idCh
- go func(ch chan<- string) {
- id := int64(1)
- for {
- str := fmt.Sprintf("id_%d", id)
- ch <- str
- id++
- }
- }(idCh)
-}
-
// Extensions can add stanza filters and/or new XML element types.
type Extension struct {
StanzaHandlers map[string]func(*xml.Name) interface{}
@@ -135,7 +117,7 @@
}
cl := new(Client)
- cl.Uid = <-Id
+ cl.Uid = NextId()
cl.password = password
cl.Jid = *jid
cl.socket = tcp
@@ -173,7 +155,7 @@
}
// Initial handshake.
- hsOut := &stream{To: jid.Domain, Version: Version}
+ hsOut := &stream{To: jid.Domain, Version: XMPPVersion}
cl.xmlOut <- hsOut
return cl, nil
@@ -267,7 +249,7 @@
// presence. The presence can be as simple as a newly-initialized
// Presence struct. See RFC 3921, Section 3.
func (cl *Client) StartSession(getRoster bool, pr *Presence) error {
- id := <-Id
+ id := NextId()
iq := &Iq{Header: Header{To: cl.Jid.Domain, Id: id, Type: "set",
Nested: []interface{}{Generic{XMLName: xml.Name{Space: NsSession, Local: "session"}}}}}
ch := make(chan error)