问题描述
我试图发送此节以更改房间主题
<iq from='hag66@shakespeare.lit/pda'
id='subject1'
to='coven@muclight.shakespeare.lit'
type='set'>
<query xmlns='urn:xmpp:muclight:0#configuration'>
<subject>To be or not to be?</subject>
</query>
</iq
roomsubject.ts ,我尝试在其中实施自定义节以更改房间主题
import { Agent,JXT } from 'stanza';
import { IQType } from 'stanza/Constants';
export interface MyStanza {
subject: string;
}
declare module 'stanza' {
export interface Agent {
sendMyStanza(jid: string,data: string): void;
}
export interface AgentEvents {
mystanza: IQType & { mystanza: MyStanza };
}
namespace Stanzas {
export interface IQType {
mystanza?: MyStanza;
}
}
}
export default function (client: Agent,stanzas: JXT.Registry) {
const NS = 'urn:xmpp:muclight:0#configuration';
stanzas.define({
element: 'query',namespace: NS,fields: {
subject: JXT.childText(null,'subject'),},});
client.sendMyStanza = (jid: string,data: string)=> {
client.sendIQ({
id:'subject1',type:"set",to:jid,mystanza: {
subject:data
}
});
};
client.on('iq',iq => {
console.log(iq)
});
};
APP.js
我导出了自定义插件,并在使用效果组件中使用了它。.但是我收到错误的请求错误
import Roomsubject from './roomsubject.tsx';
function App() {
useEffect(() => {
const client = XMPP.createClient({
jid: "92333@chat.com",password: "123456",transports: {
websocket: "ws://chat.com:1234/ws-xmpp",}
});
client.use(Roomsubject);
client.on('session:started',async() => {
try {
await client.sendMyStanza("644727e2-3600@muclight.chat..com","test")
} catch (error) {
alert(error)
}
});
client.connect();
},[]);
正在发送的IQ
<iq xmlns="jabber:client" id="29a7e0d6-26ae-4a16-bd1b-e1b9f6aae446" type="set" to="644727e2-3600-@muclight.chat.com"/>
<iq from='644727e2-3600@muclight.chat.com' to='92333594@chat.i.com/0fd1f99427c80e891600-3352860' type='error' xml:lang='en' xmlns='jabber:client'
id='29a7e0d6-26ae-4a16-bd1b-e1b9f6aae446'><error code='400' type='modify'><bad-request xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/></error></iq>
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)