function processUpdatedMessages() {
var data = $(PrimeFaces.escapeClientId('chatHistoryForm:unreadMessages')).html();
data = convertToLinks(data);
if (data.length != 0) {
var chatContent = $(PrimeFaces.escapeClientId('chatHistoryForm:chatHistory'));
chatContent.append(data);
try{
if($(PrimeFaces.escapeClientId('chatHistoryForm:unreadMessages')).find("div[class*='msg_chatMessageByCustomer']").length == 0) {
playNotification();
}
}catch (e) {}
$(PrimeFaces.escapeClientId('chatHistoryForm:public')).animate({scrollTop: $(PrimeFaces.escapeClientId('chatHistoryForm:chatWrapper')).height()}, 800);
$(PrimeFaces.escapeClientId('chatHistoryForm:unreadMessages')).html('');
}
}
function playNotification(){
//HTML5 Audio is Supported
if("Audio" in window)
{
var audio = $('#chatAudio')[0];//document.getElementByID('audio');
audio.play();
}
//HTML5 Audio is NOT Supported
else
{
document.getElementById("bgsound").src="notify.wav";
//"";
}
}
function convertToLinks(text) {
//URLs starting with http://, https://
var replacePattern1 = /(\b(https?):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
var replacedText = text.replace(replacePattern1, '$1');
//URLs starting with "www."
var replacePattern2 = /(^|[^\/])(www\.[\S]+(\b|$))/gim;
replacedText = replacedText.replace(replacePattern2, '$1$2');
//returns the text result
return replacedText;
}