How to add custom fields in elements of XMPP stanza/packet?

前端 未结 2 1120
一生所求
一生所求 2020-12-02 00:46

I want to send



        
相关标签:
2条回答
  • 2020-12-02 01:38
    1. Smack surely has a better way to work with XML than this approach with modifying the string representation. This will break badly when anything contains a " or any of the other characters that need to be escaped as an attribute.

    2. You have to add custom payloads to messages as a separate XML element within the message, not as attributes on the message. Your XML should look like:

       <message id="qm5Dx-8" to="abc" type="chat" from="abc">
          <body>Image</body>
          <request xmlns='urn:xmpp:receipts'/>
          <data xmlns='http://bstkaal/custom/data'
            msgType="2"
            msgTimeStamp="1413971599039"
            fileSize="18 MB" 
            fileHeight="300"
            fileWidth="300"
            thumbnail="abc"
            mediaURL=""
            serverMediaURL="xyz"
            isFromMe="1"
            status="1" />
      </message>
      
    0 讨论(0)
  • 2020-12-02 01:46

    xnyhps answer is correct. I've just want to add a few things. He already said that, but I can't stress the fact enough, because I see it again and again:

    Never add custom values to specified stream element attributes (e.g. a new value for the type attribute of messages), and never add new attributes to top level elements (like you did with msgType, msgTimeStamp and so on).

    This has the potential to break things! Don't do it. See also "XEP-0134: XMPP Design Guidelines § 2.1 XMPP is Sacred". That's why it's not possible in Smack. Instead, use a custom extension element, like xnyhps showed in his example (the data element). See also "RFC 6120 § 8.4 Extended Content" Those are called PacketExtension's in Smack.

    0 讨论(0)
提交回复
热议问题