Fix XMPP logger consistency

- Rename socketProxy to StreamLogger
- Ensure client send traffic through the logger
This commit is contained in:
Mickael Remond
2019-06-29 10:45:25 +02:00
committed by Mickaël Rémond
parent 318e5e8a50
commit 5992cc2231
6 changed files with 32 additions and 28 deletions

View File

@@ -133,7 +133,7 @@ func (c *Client) Connect() error {
//fmt.Fprintf(client.conn, "<presence xml:lang='en'><show>%s</show><status>%s</status></presence>", "chat", "Online")
// TODO: Do we always want to send initial presence automatically ?
// Do we need an option to avoid that or do we rely on client to send the presence itself ?
fmt.Fprintf(c.Session.socketProxy, "<presence/>")
fmt.Fprintf(c.Session.streamLogger, "<presence/>")
// Start the keepalive go routine
keepaliveQuit := make(chan struct{})
@@ -166,10 +166,7 @@ func (c *Client) Send(packet stanza.Packet) error {
return errors.New("cannot marshal packet " + err.Error())
}
if _, err := fmt.Fprintf(conn, string(data)); err != nil {
return errors.New("cannot send packet " + err.Error())
}
return nil
return c.sendWithLogger(string(data))
}
// SendRaw sends an XMPP stanza as a string to the server.
@@ -182,8 +179,12 @@ func (c *Client) SendRaw(packet string) error {
return errors.New("client is not connected")
}
return c.sendWithLogger(packet)
}
func (c *Client) sendWithLogger(packet string) error {
var err error
_, err = fmt.Fprintf(conn, packet)
_, err = fmt.Fprintf(c.Session.streamLogger, packet)
return err
}