Class: ChatObserver

LiveSupport.VisitorAPI. ChatObserver

new ChatObserver()

The central event publisher for all events the chat window sends.

LIMITED SUPPORT:
ChatObserver requires a yalst Business edition

ChatObserver is not available on mobile devices where the chat runs in a dedicated browser tab as touch-friendly single page web application. In this case you can use the ThemeApi ChatEventPublisher.

The chat window to be observed can be created by LiveSupport.VisitorAPI.startLiveChat or by the chat button which is created by the regular yalst integration code.

There can be just a single instance of ChatObserver per page. It must be accessed via LiveSupport.VisitorAPI.ChatObserver.asyncSharedChatObserver().

IMPORTANT: Attempts to call this constructor will fail with an exception. (Singleton pattern)

LIMITED BROWSER SUPPORT:
  • will not work in Internet Explorer version 7 or older.
  • will not work in Google Chrome if third-party cookies are blocked by the user
  • in Internet Explorer 8 and 9 the schema (http or https) of the url in the LiveSupport.VisitorAPI.associateWithLiveSupportProduct command must match the SSL capability of your yalst product.
  • will not work with the touch-friendly chat for mobile devices. Instead inject JavaScript via user theme and subscribe to `KeyStepPublisher`.


Throws LiveSupport.ManagedError in case readyCallback is not given and
  • the constructor is called more than once or
  • the browser is not supported (IE 7 and older)
Properties:
Name Type Description
onChatEvent function Event handlers receive a single parameter which is in case of success a LiveSupport.VisitorAPI.ChatObserver.Event or a LiveSupport.ManagedError in case of failure.
Source:

Members

(static, readonly) ChatObserver.Event :string

observable events fired by the chat (popup) window
Type:
  • string
Properties:
Name Type Description
open string Event is fired when the (popup) window showing the start chat form appears. Event is silenced when the start form is skipped by specifying `direct=true` as additional parameter to LiveSupport.VisitorAPI.startLiveChat
start string Event is fired when the chat is started.
join string Event is fired when the operator joins the chat.
finish string Event is fired when the chat is finished. This event is only delivered if the chat is closed by the operator or by the user through the inner close button. It does not fire if the user quits the popup using the window's system close button or closes the popup before the chat is started.
Source:

Methods

(static) ChatObserver.asyncSharedChatObserver(resultCallbackopt)

Accesses and creates the single ChatObserver object.

If called for the first time depending on the user agent this method may load additional external resources to receive chat events. When this setup is complete the callback will be invoked with the ChatObserver object as parameter or in case of an error an LiveSupport.ManagedError object.
Parameters:
Name Type Attributes Description
resultCallback function <optional>
called when ChatObserver is ready to receive and re-publish chat window events. It may receive an Error object in case of an error the single ChatObserver instance otherwise.
Source:
Example
LiveSupport.VisitorAPI.ChatObserver.asyncSharedChatObserver(function(chatObserverOrError){
	if (chatObserverOrError instanceof Error){
		alert(chatObserverOrError.message);
	}
	else{
		chatObserverOrError.onChatEvent = chatEventHandler;
		startButton.removeAttribute("disabled");
	}
});
startButton.setAttribute("disabled", "disabled");

function chatEventHandler(evtOrError){
	if (evtOrError instanceof LiveSupport.ManagedError){
		alert(evtOrError.message);
		return;
	}

	if (evtOrError == LiveSupport.VisitorAPI.ChatObserver.Event.join){
		startButton.style.visibility = "hidden";
	}
	else{
		startButton.style.visibility = "visible";
	}
}