-
Notifications
You must be signed in to change notification settings - Fork 0
/
xmpptesting.js
51 lines (42 loc) · 1 KB
/
xmpptesting.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
43
44
45
46
47
48
49
50
51
const { client, xml, jid } = require("@xmpp/client");
const debug = require("@xmpp/debug");
const xmpp = client({
service: "xmpps://140.90.59.197:5223",
domain: "nwws-oi.weather.gov",
resource: "nwws",
username: "wind.096",
password: "Mxq#cD&",
});
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.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);
/*
xmpp.connect({
jid: "[email protected]",
password: "Mxq#cD&",
host: "ws://conference.nwws-oi.weather.gov",
port: 5223,
});
*/