Is there any callback function after 'Friends List' loaded in cometchat?

486 Views Asked by At

I have integrated 'Embed Layout' comet chat on my site. Now I want to open particular friend chat on page load.

In the documentation, I've found below code to do the same. REF : Documentation Link

jqcc.cometchat.chatWith(user_id)

I have included in custom js from admin panel. However, it is showing below error in console

jqcc.cometchat.chatWith is not a function

But If I use same after friends list loaded from the console it is working fine.

How can I fix this issue?

2

There are 2 best solutions below

0
On

Currently for time being I have fixed this issue by adding below code in custom js

var first_chat_loaded = false;
var first_chat = setInterval(function () {
    try {
        if (first_chat_loaded === false) {
            // Function to get other user id defined in parent html page
            var other_userid = parent.get_other_user_id();
            jqcc.cometchat.chatWith(other_userid);
            first_chat_loaded = true;
            clear_first_load();
        }
    } catch (e) {

    }
}, 1000);

function clear_first_load() {
    clearInterval(first_chat);
}

Please let me know, If there is any proper way to do the same.

0
On

Kindly make use of this code snippet for the above mentioned issue

var checkfn = setInterval(
    function(){
        if(typeof  jqcc.cometchat.chatWith == 'function'){
            jqcc.cometchat.chatWith(user_id);
            clearInterval(checkfn);
        }
    },
500);