/* Create a new instance of the eGainLibrarySettings Object */ var librarySettings = new eGainLibrarySettings(); librarySettings.CORSHost ="http://myegainserver.com/system"; librarySettings.IsDevelopmentModeOn = false; ibrarySettings.eGainContextPath = ""; librarySettings.ChatPauseInSec = "30"; librarySettings.IsDebugOn = false; /* Next create a new instance of the eGainLibrary */ /* passing in the settings you have just created. */ var myLibrary = new eGainLibrary(librarySettings); /* Now create an instance of the Chat Object */ var myChat = new myLibrary.Chat(); /* Next get the event handlers for chat. It is mandatory to provide definition for the mandatory event handlers before initializing chat */ var myEventHandlers = myChat.GetEventHandlers(); /* Example browser alert when chat is connected */ myEventHandlers.OnConnectSuccess = function () { alert('Chat Started!'); }; /* Example browser alert when there is a connection failure */ myEventHandlers.OnConnectionFailure = function () { alert('Oops! Something went wrong'); }; /* Example browser alert when there is an error during chat */ myEventHandlers.OnErrorOccurred = function () { alert('Oops! Something went wrong'); }; /* Example output of agent messages to a DIV named TransScript with jQuery */ myEventHandlers.OnAgentMessageReceived = function (agentMessageReceivedEventArgs) { $('#TransScript').append("<br />Agent: " + agentMessageReceivedEventArgs.Message); }; /* Example output of system messages to the same DIV */ myEventHandlers.OnSystemMessageReceived = function (systemMessageReceivedEventArgs) { $('#TransScript').append("<br />" + systemMessageReceivedEventArgs.Message); }; /* Example browser alert when agents are not available */ myEventHandlers.OnAgentsNotAvailable = function (agentsNotAvailableEventArgs) { alert('Sorry no agents available'); }; /* Example browser alert when the chat is completed */ myEventHandlers.OnConnectionComplete = function () { $.mobile.changePage("#SimpleAnonymousChatPostChatScreen") }; /* Now call the Chat initialization method with your entry point and callbacks */ myChat.Initialize($('#ChatEntryPointId').val(),'en', 'US', myEventHandlers,'aria', 'v11'); /* Start chat */ myChat.Start();