0

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?

Bahadir Tasdemir
  • 10,325
  • 4
  • 49
  • 61
Rajasekhar
  • 517
  • 1
  • 4
  • 14

2 Answers2

0

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.

Rajasekhar
  • 517
  • 1
  • 4
  • 14
0

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);
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
CometChat
  • 57
  • 3