Created
October 8, 2018 11:03
-
-
Save enricop89/b13c1cfbf83b1c77040281141deeb006 to your computer and use it in GitHub Desktop.
Bandyer chat logout after timeout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This function calls the BandyerChat.logout() method after a specified timeout (default: 5 minutes) | |
* If BandyerChat widget has not been initialized, the function will throw an error. | |
* @param timeout | |
* @param callback | |
*/ | |
var exitWidgetAfterTimeout = function (timeout, callback) { | |
if (BandyerChat) { | |
var delay = timeout || (5* 60 * 1000); | |
setTimeout(function() { | |
try { | |
var unreadMessages = BandyerChat.getUnreadMessages(); | |
var haveUnreadMessages = false; | |
for (var i = 0; i < unreadMessages.length; i++) { | |
if (unreadMessages[i].unreadMessages > 0) { | |
haveUnreadMessages = true; | |
} | |
} | |
if (!haveUnreadMessages) { | |
BandyerChat.logout(); | |
} | |
if (callback) { | |
callback(); | |
} | |
} catch (e) { | |
throw e; | |
} | |
}, delay); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment