如何解决自定义插件实现节js的问题
我试图发送此节以更改房间主题
<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
使用节documentation的自定义插件
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 举报,一经查实,本站将立刻删除。