function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Alessandro ZuccaAlessandro Zucca 

Live Agent init(), disconnect() and init()

Should liveagent.disconnect(), allow then to re-initialise the chat?
From what I can see this is prevented by the fact that a "qa" variable (obfuscated code) is set to 0 during initialization

var v = f.getCookie("liveagent_sid") , $ = f.getCookie("liveagent_chatted") , qa = !1 , Q = !1 , k = {}

and then the function that handles the button visibility (and more) does not get executed as qa is 

function O() {
if (!qa) {
  qa = !0;
  f.log("DOM is ready. Setting up environment.");
  null == u.getOref() && u.setOref(document.referrer); null == u.getVisitCount() &&   u.setVisitCount(1); if (window._laq) for (var a = 0; a <     window._laq.length; a++) window._laq[a].call(window); q.connection.setCallback("liveagent._.handlePing"); ra()
  }
}

why liveagent.disconnect() does not reset that 'qa' variable to the default and allow us to make a "re"- init() ?

I came across this problem, as the button that displays the livechat link in our application is inside a dialog, therefore the first time I open the dialog the button appears correcty.
The second time it doesn't for the issue highlighed above
 
Andy BoettcherAndy Boettcher
Is your goal the ability for a user to:
  • Start an initial chat
  • Complete the initial chat
  • Re-open chat with a new case
All without refreshing the page?
Alessandro ZuccaAlessandro Zucca
Hi Andy, Thanks for you reply

My goal is to have a live chat button on a dialog window (Ext JS) and being able to close the dialog window, re-opening it and have the livechat agent showing the button again, without having to refresh the page.

At the moment, I assume the liveagent lose the reference to the button elements as the Ext JS possibly removes the buttons from the DOM when the dialog windows is closed therefore when the dialog window is re-opened the liveagent can't show the button

The second time the dialog window is opened, if I run in the console, liveagent.disconnect(), and then run liveagent.init(...) with a breakpoint in if (!qa) and setting qa = 0 when it stops the execution, this makes the button again.
Alessandro ZuccaAlessandro Zucca
This is the dialog window mentioned:

User-added image

 
Alessandro ZuccaAlessandro Zucca
SOLVED: We found a workaround, loading the script via jquery allow us to reload it on a dialog

​    $.getScript( "/agent-34.0.js", function( data, textStatus, jqxhr ) {});
Rey AustralRey Austral
Hi Alessandro, can you post your whole code, i tried loading it in the getscript but the button still not refreshing
here's my sample code
 
var afterScriptBX = function () {
            window._laq = [];
            window._laq.push(function(){liveagent.showWhenOnline('', document.getElementById('liveagent_button_online_'));
                                        liveagent.showWhenOffline('', document.getElementById('liveagent_button_offline_'));
                                       });

            liveagent.init('https://d.la1-c2cs-lon.salesforceliveagent.com/chat', '', ''); 
            liveagent.addCustomDetail("Case SubCategory", component.get('v.CaseSubCategory') );
            liveagent.addCustomDetail("Case Category",  component.get('v.CaseCategory') );
            liveagent.addCustomDetail("Case Type", component.get('v.CaseType') );
            liveagent.findOrCreate("Case").map("SubCategory__c","Case SubCategory",false,false,true).map("Category__c","Case Category",false,false,true).map("Type","Case Type",false,false,true).showOnCreate();
        }
        $.getScript('https://c.la1-c2cs-lon.salesforceliveagent.com/content/g/js/37.0/deployment.js', afterScriptBX);

Thanks and Regards,
Glen BargerGlen Barger
I don't know if you found a solution for this or not, but I was spinning my wheels for hours before I got this working. I actually had to add a couple of extra steps:
delete liveagent;
delete liveAgentDeployment;
jQuery.loadScript("https://<liveagenturlhere>/deployment.js", function() {reInitChat();});

delete liveagent removes that object complete, then I was digging around in the deployment.js and discovered liveAgentDeployment. It hangs around and keeps you from rebuilding liveagent on the page. After running this, I rerun the liveagent.showWhenOnline, and liveagent.init and I can do this as many times as I want before leaving a page.
Glen BargerGlen Barger
I forgot to mention that I'm not using $.getScript because it can have problems, so I have an extra loadScript function.
jQuery.loadScript = function (url, callback) {
    jQuery.ajax({
        url: url,
        dataType: 'script',
        success: callback,
        async: true
    });
};

 
david latotzkydavid latotzky
Thanks, just what i was looking for.

But if you only delete global liveagent-objects using Glen Barger's method,
you may get js error s if there was still a pending network request that returns after you deleted liveAgent.
(if you always reload liveagent after deleting it, it may happens less often)

To supress these occasional  errors, this worked for me.:
delete window.liveagent; 
delete window.liveAgentDeployment; 
// this mock-agent suppresses errors causedby pending avail-checks
window.liveagent = {'_': {'handlePing': () => {/*do nothing supress*/}}};



 
Laney Stroup 3Laney Stroup 3
Does this wtill work in September 2018? I am testing things out for use with Turbolinks, and I cannot seem to find the liveagent or liveAgentDeployment variables in my implementation.