Implements send / send raw

This commit is contained in:
Mickael Remond
2018-01-26 09:55:39 +01:00
parent 2cd8eed765
commit ad6e09a0f6
4 changed files with 39 additions and 8 deletions

View File

@@ -126,9 +126,24 @@ func (c *Client) Recv() <-chan interface{} {
return ch
}
// Send sends message text.
// TODO Move to Go XML Marshaller
func (c *Client) Send(packet string) error {
// Send marshalls XMPP stanza and sends it to the server.
func (c *Client) Send(packet Packet) error {
data, err := xml.Marshal(packet)
if err != nil {
return errors.New("cannot marshal packet " + err.Error())
}
if _, err := fmt.Fprintf(c.conn, string(data)); err != nil {
return errors.New("cannot send packet " + err.Error())
}
return nil
}
// SendRaw sends an XMPP stanza as a string to the server.
// It can be invalid XML or XMPP content. In that case, the server will
// disconnect the client. It is up to the user of this method to
// carefully craft the XML content to produce valid XMPP.
func (c *Client) SendRaw(packet string) error {
fmt.Fprintf(c.Session.socketProxy, packet) // TODO handle errors
return nil
}