2
0
mirror of https://github.com/FluuxIO/go-xmpp synced 2024-11-03 15:40:13 +00:00

Keeps component connection open

This commit is contained in:
Mickael Remond 2018-01-12 19:08:47 +01:00
parent b21fee420f
commit 24ac2c0526
No known key found for this signature in database
GPG Key ID: E6F6045D79965AA3
4 changed files with 21 additions and 2 deletions

View File

@ -128,7 +128,7 @@ func (c *Client) Recv() <-chan interface{} {
// Send sends message text.
func (c *Client) Send(packet string) error {
fmt.Fprintf(c.Session.socketProxy, packet)
fmt.Fprintf(c.Session.socketProxy, packet) // TODO handle errors
return nil
}

View File

@ -1,8 +1,20 @@
package main
import "fluux.io/xmpp"
import (
"fmt"
"fluux.io/xmpp"
)
func main() {
component := xmpp.Component{Host: "mqtt.localhost", Secret: "mypass"}
component.Connect("localhost:8888")
for {
_, packet, err := component.ReadPacket()
if err != nil {
return
}
fmt.Println("Packet received: ", packet)
}
}

View File

@ -88,6 +88,12 @@ func (c *Component) Connect(connStr string) error {
panic("unreachable")
}
// ReadPacket reads next incoming XMPP packet
// TODO use defined interface Packet
func (c *Component) ReadPacket() (xml.Name, interface{}, error) {
return next(c.decoder)
}
// ============================================================================
// XMPP packets struct

View File

@ -63,6 +63,7 @@ func nextStart(p *xml.Decoder) (xml.StartElement, error) {
// Scan XML token stream for next element and save into val.
// If val == nil, allocate new element based on proto map.
// Either way, return val.
// TODO Use an interface to return packets interface xmppDecoder
func next(p *xml.Decoder) (xml.Name, interface{}, error) {
// Read start element to find out what type we want.
se, err := nextStart(p)