Add jodo widget in HTML website with external events

Author: ritika raj 160 views

Step 1
With HTML website select the page to add Jodo widget and paste below Snippet just before the end of the tag of the page

Step 2
Insert your API key and Service key provided at line #4 & #5
Replace the server path at line number #9, #10, #11

Step 3
Check to see if the widget has loaded on your integrated page.

				
					<script>
    var __acstoolbar = {};
    var jodoinitdone = false;
    __acstoolbar.servicekey = <Insert your service key here>;
    __acstoolbar.apikey = <Insert your api key here>;
    __acstoolbar.tracelevel = '1';
    __acstoolbar.theme = 'theme_blue2';
    __acstoolbar.language = 'english';
    __acstoolbar.target = <serverPath>;
    __acstoolbar.serverpath = <serverPath>;
    __acstoolbar.applicationpath = <serverPath>;
    __acstoolbar.visibility = "hide";
    __acstoolbar.widgeticon = "hide";

    (function () {
        var joinSC = document.createElement('script');
        joinSC.type = 'text/javascript';
        joinSC.src = __acstoolbar.target + '/jodowidgetapi/js/initfunctions.js';
        joinSC.onload = validateKey;
        var joinScript = document.getElementsByTagName('script')[0];
        joinScript.parentNode.insertBefore(joinSC, joinScript);
    })();
    
    function validateKey() {
        var jodoInit = new jodoworld.initfunctions();
        jodoInit.initService();
    }
    
    function jodoCall(productobject) {
        var calldata = [];
        var calldataelement = {};
        var jodoInit = new jodoworld.initfunctions();
        if (jodoinitdone === true) {
            jodoInit.setLanguage(productobject[0]);
            calldataelement = new Object();
            calldataelement.parameterid = 4011;
            calldataelement.value = productobject[0];
            calldata.push(calldataelement);
            calldataelement = new Object();
            calldataelement.parameterid = 4031;
            calldataelement.value = productobject[1];
            calldata.push(calldataelement);
            calldataelement = new Object();
            calldataelement.parameterid = 4035;
            calldataelement.value = productobject[2];
            calldata.push(calldataelement);
            calldataelement = new Object();
            calldataelement.parameterid = 4045;
            calldataelement.value = productobject[3];
            calldata.push(calldataelement);
            jodoInit.SaveCustomerSessionData(calldata);
            jodoInit.showwidgetfromscript();
            jodoInit.showwidget_Voicefromscript();
        }
    }
    
    function jodoChat(productobject) {
        var calldata = [];
        var calldataelement = {};
        var jodoInit = new jodoworld.initfunctions();
        if (jodoinitdone === true) {
            jodoInit.setLanguage(productobject[0]);
            calldataelement = new Object();
            calldataelement.parameterid = 4011;
            calldataelement.value = productobject[0];
            calldata.push(calldataelement);
            calldataelement = new Object();
            calldataelement.parameterid = 4031;
            calldataelement.value = productobject[1];
            calldata.push(calldataelement);
            calldataelement = new Object();
            calldataelement.parameterid = 4035;
            calldataelement.value = productobject[2];
            calldata.push(calldataelement);
            calldataelement = new Object();
            calldataelement.parameterid = 4045;
            calldataelement.value = productobject[3];
            calldata.push(calldataelement);
            jodoInit.SaveCustomerSessionData(calldata);
            jodoInit.showwidgetfromscript();
            jodoInit.showwidget_Chatfromscript();
        }
    }
    
    function jodoVideo(productobject) {
        var calldata = [];
        var calldataelement = {};
        var jodoInit = new jodoworld.initfunctions();
        if (jodoinitdone === true) {
            jodoInit.setLanguage(productobject[0]);
            calldataelement = new Object();
            calldataelement.parameterid = 4011;
            calldataelement.value = productobject[0];
            calldata.push(calldataelement);
            calldataelement = new Object();
            calldataelement.parameterid = 4031;
            calldataelement.value = productobject[1];
            calldata.push(calldataelement);
            calldataelement = new Object();
            calldataelement.parameterid = 4035;
            calldataelement.value = productobject[2];
            calldata.push(calldataelement);
            calldataelement = new Object();
            calldataelement.parameterid = 4045;
            calldataelement.value = productobject[3];
            calldata.push(calldataelement);
            jodoInit.SaveCustomerSessionData(calldata);
            jodoInit.showwidgetfromscript();
            jodoInit.showwidget_Videofromscript();
        }
    }
    
    function jodoScreenshare(productobject) {
        var calldata = [];
        var calldataelement = {};
        var jodoInit = new jodoworld.initfunctions();
        if (jodoinitdone === true) {
            jodoInit.setLanguage(productobject[0]);
            calldataelement = new Object();
            calldataelement.parameterid = 4011;
            calldataelement.value = productobject[0];
            calldata.push(calldataelement);
            calldataelement = new Object();
            calldataelement.parameterid = 4031;
            calldataelement.value = productobject[1];
            calldata.push(calldataelement);
            calldataelement = new Object();
            calldataelement.parameterid = 4035;
            calldataelement.value = productobject[2];
            calldata.push(calldataelement);
            calldataelement = new Object();
            calldataelement.parameterid = 4045;
            calldataelement.value = productobject[3];
            calldata.push(calldataelement);
            jodoInit.SaveCustomerSessionData(calldata);
            jodoInit.showwidgetfromscript();
            jodoInit.showwidget_Startscreensharefromscript();
        }
    }
    
    function jodoWidgetInitialized() {
        jodoinitdone = true;
    }
    
    //show button after UA registered
    function waitForJodoInitDone() {
        if (jodoinitdone) {
            setTimeout(function () {
                // Event trigger for auto start: Need to map page controls and function to start voice call from script 'jodoCall()'
            }, 1000);
        }
        else {
            setTimeout(function () {
               waitForJodoInitDone();
            }, 1000);
        }
    }
    
    function bindEvent(element, eventName, eventHandler) {
        if (element.addEventListener) {
            element.addEventListener(eventName, eventHandler, false);
        } else if (element.attachEvent) {
            element.attachEvent('on' + eventName, eventHandler);
        }
    }
    
    bindEvent(window, 'message', function (e) {
        //console.log("iframe message from Parent:" + e.data);
        var parentMsg = JSON.parse(e.data);
        var status = parentMsg.id;
        var message = parentMsg.message;
        
        switch (status) {
            case "screenshare":
                if (message === "started") {
                    // To hide page control.
                    // document.getElementById("screensharetxt").innerHTML = "End Screen";
                    screenshareflag = 2;
                }
                if (message === "ended") {
                    // To hide page control.
                    // document.getElementById("screensharetxt").innerHTML = "Share Screen";
                    screenshareflag = 1;
                }
                break;
            
            case "voice":
                if (message === "answered") {
                }
                if (message === "ended") {
                }
                break;
            
            case "UaRegistered":
                break;
        }
    });
    
    waitForJodoInitDone();
<script>
				
			

Description for the above code

jodoChat() : To start chat session from widget .
Following parameters need to pass with widget :
Example :
jodoChat([‘English’,”,”,”]);

jodoCall() : To start voice call session from widget .
Following parameters need to pass with widget :
Example :
jodoCall([‘English’,”,”,”]);

jodoVideo() : To start video call session from widget .
Following parameters need to pass with widget :
Example :
jodoVideo([‘English’,”,”,”]);

jodoScreenshare() : To start screenshare session from widget.
Following parameters need to pass with widget :
Example :
jodoScreenshare([‘English’,”,”,”]);

Auto Trigger event :
At script line number #149 pass the id from page to trigger the event from script. Or this can be done from HTML code only.
Example:
document.getElementById(‘startchat’).click();