I have installed XMPP prosody server on my ubuntu VM. After installation, in the config file of prosody server. I left the VirtualHost part untouched(i.e it points to localhost). Then in the components part I uncommented and changed Conference.example.com to Conference.localhost. These are the only changes I did in the config file.
Scenario 1->I tried creating a room using pidgin client. This part was successful. Then I made my node.js @xmpp/client join this room by sending its presence to the room. This was also successful. Then I was able to send messages between the two clients. So, everything worked in scenario 1.
Scenario 2 ->I tried creating the room using node.js @xmpp/client. This part was successful. Then I made another node.js client join the same room by sending its presence to the room. This part fails for me. The error I get can be seen below.
OUT {presence from="sameer@localhost/3dh65FV7" to="[email protected]/sameer">}
IN {presence to="sameer@localhost/3dh65FV7" from="[email protected]/sameer" type="error">}
Client1.js(client that creates the room)
const { client, xml } = require("@xmpp/client");
const debug = require("@xmpp/debug");
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
let fromAddr;
const xmpp = client({
service: "xmpp://192.168.0.59:5222",
domain: "localhost",
username: "venki",
password: "Welcome1",
});
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();
}
});
async function sendMessageToRoomWatchParty() {
const message = xml('message', {from: fromAddr, to: '[email protected]', type: 'groupchat'},
xml('body',{},'Hello from Venki'));
await xmpp.send(message);
}
async function joinRoomWatchParty() {
const roomAddr = '[email protected]/venki';
const presence = xml('presence', {from: fromAddr, to: roomAddr},
xml('x', {xmlns: 'http://jabber.org/protocol/muc'}));
await xmpp.send(presence);
setTimeout(sendMessageToRoomWatchParty,10000);
}
xmpp.on("online", async (address) => {
fromAddr = address;
setTimeout(joinRoomWatchParty,5000);
});
xmpp.start().catch(console.error);
Client2.js(client that joins the room)
const { client, xml } = require("@xmpp/client");
const debug = require("@xmpp/debug");
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
let fromAddr;
const xmpp = client({
service: "xmpp://192.168.1.19:5222",
domain: "localhost",
username: "sameer",
password: "Welcome1",
});
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();
}
});
async function joinRoomWatchParty() {
const roomAddr = '[email protected]/sameer';
const presence = xml('presence', {from: fromAddr, to: roomAddr},
xml('x', {xmlns: 'http://jabber.org/protocol/muc'})
);
await xmpp.send(presence);
}
xmpp.on("online", async (address) => {
fromAddr = address;
setTimeout(joinRoomWatchParty,5000);
});
xmpp.start().catch(console.error);
Why is scenario 2 failing? I sense there is some mistake I'm doing with creation of the room using node.js client. Please go through my client1.js code.
Please help.