Class: ChatObserver

LiveSupport.VisitorAPI. ChatObserver

ChatObserver

new ChatObserver()

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

LIMITED SUPPORT:
ChatObserver requires a yalst Business edition

The chat window to be observed can be created by LiveSupport.VisitorAPI.startLiveChat or 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
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:
Throws:
in case if readyCallback is not given and
  • the constructor is called more than once or
  • the browser is not supported (IE 7 and older)
Type
LiveSupport.ManagedError

Members

<static, readonly> ChatObserver.Event :string

observable events fired by the chat (popup) window
Type:
  • string
Properties:
Name Type Default Description
open string open 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 start Event is fired when the chat is started.
join string join Event is fired when the operator joins the chat.
finish string finish 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:

<inner, constant> FRAME_NAME :String

name attribute of the helper iFrame must be identically named in "msgframe.html"
Type:
  • String
Default Value:
  • yeventreceiver
Source:

Methods

<static> ChatObserver.asyncSharedChatObserver(resultCallback)

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 Argument 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";
	}
}