0
votes

I want the bot owner of the XMPP room to be persistently present, but I keep disappearing from the room and have to rejoin. What must I do to maintain my presence in a room? Is it configurable? I cannot find an answer in XEP-0045.

http://xmpp.org/extensions/xep-0045.html

Here is my code:

function daemonPresence(callback) {
    var ElizaBot = require('./eliza');
    var eliza = new ElizaBot();
    var initial = eliza.getInitial();
    var XMPP = require('stanza.io');
    var administrator = 'metalaureate@' + config.get('xmpp.domain');
    var client = XMPP.createClient({
        jid: administrator, 
        password: 'password',
        transport: 'bosh',
        boshURL: config.get('xmpp.bosh_url') 

    });
    client.enableKeepAlive();

    client.on('session:started', function () {
        console.log(administrator + ' is sending presence');
       client.joinRoom("[email protected]", 'Daemon');
        setInterval(function () {client.sendPresence();console.log('daemon presence');},60000);

        client.on('chat', function (msg) {
            console.log(msg.body);
            var reply = eliza.transform(msg.body);
            client.sendMessage({
                to: msg.from,
                body: 'hello world' // 'You sent: ' + msg.body
            });
        });
        client.on('groupchat', function (msg) {
            console.log('group chat',  msg.body);

        });
    });
    client.on('session:end', function (result) {
        console.info("daemon session ended, restarting");
        setTimeout(function () {
            daemonPresence();
        }, 10000);
        // callback(null, result);
    });
    client.on('session:error', function (error) {
        console.err('xmpp error', error);
        callback(error, null);
    });

    client.connect();

}
1
Check if the machine from which your bot is running is not sleeping after some time (for example, if you run the bot from anything else than a server, always on).H_I

1 Answers

2
votes

This is the nature of XMPP Multi User Chat as defined in XEP-0045. XMPP MUC room are presence based. It means you need to send your presence to the MUC every time you login. This is what is defined in the protocol. Some client work around this by implementing bookmarks as XML private storage to store a list of MUC room the client will auto join on connect you may want to look into this.

The XMPP Standards Foundation is discussing building a new MUC specification (aka MUC 2) that will not be coupled to presence. However, this is just a discussion at the moment.