wxchat-xmpp-client
v1.0.0
Published
Rebuild xmpp.js apply to Wechat Mini Programt.
Downloads
3
Readme
client
Rebuild xmpp.js apply to Wechat Mini Programt.
Install
npm i cd ./imchat-wxapp-demo npm i
Setup
npm run dev open other cmd window cd ./imchat-wxapp-demo npm run wxDev
build
npm run build
xmpp origin code
https://github.com/xmppjs/xmpp.js.git
How to use
npm i wxchat-xmpp-client
const { client, xml } = require("wxchat-xmpp-client");
const xmpp = client({
service: "ws://localhost:5280/xmpp-websocket",
domain: "localhost",
resource: "example",
username: "username",
password: "password",
});
xmpp.on("error", (err) => {
console.error(err);
});
xmpp.on("offline", () => {
console.log("offline");
});
xmpp.on("stanza", async (stanza) => {
if (stanza.is("message")) {
await xmpp.send(xml("presence", { type: "unavailable" }));
await xmpp.stop();
}
});
xmpp.on("online", async (address) => {
// Makes itself available
await xmpp.send(xml("presence"));
// Sends a chat message to itself
const message = xml(
"message",
{ type: "chat", to: address },
xml("body", {}, "hello world"),
);
await xmpp.send(message);
});
xmpp.start().catch(console.error);