forked from xmppjs/xmpp.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.js
42 lines (32 loc) · 837 Bytes
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/* eslint-disable node/no-extraneous-require */
"use strict";
const { component, xml } = require("@xmpp/component");
const debug = require("@xmpp/debug");
const xmpp = component({
service: "xmpp://localhost:5347",
domain: "component.localhost",
password: "mysecretcomponentpassword",
});
debug(xmpp, true);
xmpp.on("error", (err) => {
console.error(err);
});
xmpp.on("offline", () => {
console.log("offline");
});
xmpp.on("stanza", async (stanza) => {
if (stanza.is("message")) {
await xmpp.stop();
}
});
xmpp.on("online", async (address) => {
console.log("online as", address.toString());
// 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);