javascriptxmppopenfirestrophe

XEP-0333, implementation using javascript


I am working on a chat in a website using openfire and strophe js. I want to integrate message seen function like whatsapp. But I am not getting how to implement xep-0333 with strophe js. Please help with this.

Thanks


Solution

  • Here is an example of ready methods on how to use XEP-0333, especially for delivered & read statuses:

    Strophe.addNamespace('CHAT_MARKERS', "urn:xmpp:chat-markers:0");
    
    ...
    
    sendDeliveredMarker: function(to, from, originalMessageId) {
        var stanzaParams = {
            type: 'chat',
            from: from,
            id: "<id>",
            to: to
        };
    
        var messageStanza = $msg(stanzaParams);
        messageStanza
            .c('received', {
                xmlns: "urn:xmpp:chat-markers:0",
                id: originalMessageId
            })
            .up();
    
        this.xmppClient.send(messageStanza);
    },
    
    sendReadMarker: function(to, from, originalMessageId) {
        var stanzaParams = {
            type: 'chat',
            from: from,
            id: "<id>",
            to: to
        };
    
        var messageStanza = $msg(stanzaParams);
        messageStanza
            .c('displayed', {
                xmlns: "urn:xmpp:chat-markers:0",
                id: originalMessageId
            })
            .up();
    
        this.xmppClient.send(messageStanza);
    },