Stanza.io отправляет сообщение с атрибутами клиента в ReactJS - PullRequest
0 голосов
/ 25 апреля 2018

Я хочу отправить сообщение с пользовательскими атрибутами в ReactJS / Stanza.io. Я не могу заставить его работать. Есть хороший рабочий пример?

1 Ответ

0 голосов
/ 04 мая 2018

Предположим, мне нужно отправить сообщение с пользовательским атрибутом с именем custom :

<message to="tom@example" id="273z4-567" type="chat" from="john@example"> 
   <body>hi</body> 
   <custom xmlns="xmpp:customAttr" layout="testLayout"> // custom attribute
      <value>1234</value> 
   </custom>
</message>

, вы можете сделать это следующим образом:

const XMPP = require('stanza.io');

let client = XMPP.createClient({}); // obj with config
client.use(this.setCustomMessageAttributes());


setCustomMessageAttributes() {
    const NS = 'xmpp:customAttr';
    const customAttribute = stanzas.define({
        name: 'custom',
        element: 'custom',
        namespace: NS,
        fields: {
            value: stanzas.utils.textSub(NS, 'value'),
            layout: stanzas.utils.attribute('layout')
        }
    });

    stanzas.withMessage((Message) => {
        stanzas.extend(Message, customAttribute);
    });
}

Вы можете отправитьсообщение как

client.sendMessage({
    to: "jid",
    body: "hi",
    custom: {
        value: "1234",
        layout: "testLayout"
    }
});

Вы также можете обратиться к https://github.com/legastero/stanza.io/blob/master/docs/Create_Plugin.md

Если у вас по-прежнему возникают проблемы, вставьте сюда свой код.

...