我想在sendMessage中使用ReactJS / Stanza.io中的自定义属性。我无法使它发挥作用。有什么好的例子吗?
发布于 2018-05-04 10:29:48
假设我必须发送一条带有名为自定义的自定义属性的消息:
<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"
}
});您也可以参考Plugin.md
如果您仍然面临问题,请将您的代码粘贴在这里。
https://stackoverflow.com/questions/50017642
复制相似问题