wxchat-xmpp-client

1.0.0 • Public • Published

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);

Readme

Keywords

none

Package Sidebar

Install

npm i wxchat-xmpp-client

Weekly Downloads

1

Version

1.0.0

License

ISC

Unpacked Size

258 kB

Total Files

19

Last publish

Collaborators

  • liuzhe529