~samwhited/xmpp

b3d532ffcddcecc31025bb14d57131fd2f2bd705 — Sam Whited 2 years ago 7c55656
xmpp: update docs to mention Send/SendElement
2 files changed, 10 insertions(+), 8 deletions(-)

M doc.go
M echobot_example_test.go
M doc.go => doc.go +8 -6
@@ 80,18 80,20 @@
// "mellium.im/xmlstream".TokenWriter interface.
// The session may also buffer writes and has a Flush method which will write
// any buffered XML to the underlying connection.
//
// However, writing individual XML tokens can be tedious and error prone.
// The mellium.im/xmpp/stanza package contains functions and structs that aid in
// the construction of message, presence and IQ elements which have special
// semantics in XMPP and are known as "stanzas".
// These can be sent with the Send and SendElement methods.
//
//     // Send initial presence to let the server know we want to receive messages.
//     _, err = xmlstream.Copy(session, stanza.WrapPresence(nil, stanza.AvailablePresence, nil))
//     …
//     err = session.Flush()
//     _, err = session.Send(stanza.WrapPresence(nil, stanza.AvailablePresence, nil))
//
// To make the common case of polling for incoming XML on the input stream—and
// possibly writing to the output stream in response—easier, Session includes
// the Serve method.
// For Send to correctly handle IQ responses, and to make the common case of
// polling for incoming XML on the input stream—and possibly writing to the
// output stream in response—easier, we need a long running goroutine.
// Session includes the Serve method for starting this processing.
// Serve provides a Handler with access to the stream but prevents it from
// advancing the stream beyond the current element and always advances the
// stream to the end of the element when the handler returns (even if the

M echobot_example_test.go => echobot_example_test.go +2 -2
@@ 49,7 49,7 @@ func Example_echobot() {
	}()

	// Send initial presence to let the server know we want to receive messages.
	_, err = xmlstream.Copy(s, stanza.WrapPresence(nil, stanza.AvailablePresence, nil))
	_, err = s.Send(context.TODO(), stanza.WrapPresence(nil, stanza.AvailablePresence, nil))
	if err != nil {
		log.Printf("Error sending initial presence: %q", err)
		return


@@ 86,7 86,7 @@ func Example_echobot() {
				return xml.CharData(msg.Body), io.EOF
			}), xml.StartElement{Name: xml.Name{Local: "body"}}),
		)
		_, err = xmlstream.Copy(s, reply)
		_, err = s.Send(context.TODO(), reply)
		if err != nil {
			log.Printf("Error responding to mid-%s: %q", msg.ID, err)
		}