How to appear online using stanza.io client and ejabberd server?

987 views Asked by At

I'm having a problem to appear online at ejabberd, I'm doing a chat client for a customer and I have this part of the code:

client.connect();
client.on('session:started', () => {
    client.getRoster()
    client.sendPresence();
    onConnect();
});

When I get session started event I send my presence to the server to appear "online" to other users, but it doesn't work, does the name of the event is wrong? The other functionalities work fine I can send message but only in a offline state. Any tips? Thanks in advance.

2

There are 2 answers

2
Sakshi Nagpal On

You need to send your presence to the server

this.client.on('session:started', () => {
        this.client.enableCarbons(err => {
        if (err) {
            console.log('Server does not support carbons', err);
        }
    });
    this.client.sendPresence();
    });

On saving any new user, we need to subscribe that user

this.client.subscribe(id);

and opposite user has to accept the subscription wheneven they receive presence type as subscribe

this.client.acceptSubscription(id)
1
Sabbir On

Make sure your other client has also sent their presence and the other user is subscribed to your presence.