Presence Check in JavaScript

Why might you use this?

This is an alternative presence check in JavaScript that is especially useful if you want to display chat boxes for two different queues on the same web page simultaneously, and you do not want to just use raw IFRAMEs. Use this sample code for one of your code chunks, and use the standard code as generated in the Admin site for the other.

Sample Code

This example code that lets you do basic presence checking on page load. The sample code assumes a embedded chat box, but can be easily modified to provide follow-me or pop-up chat box behaviors.

<div id="online" data-myjid="my-queue@chat.libraryh3lp.com" style="display: none;">
  Queue is online. This can be a pop-up if you don't want an embedded chat box.
  <iframe src="https://libraryh3lp.com/chat/my-queue@chat.libraryh3lp.com"
  frameborder="1" style="width:190px; height: 275px;"></iframe>
</div>
<div id="offline"> Queue is offline. Your offline option here. </div>
<script type="text/javascript"> function show_presence() { for (var i = 0; i < jabber_resources.length; ++i) { var resource = jabber_resources[i]; if (resource.show === 'available' || resource.show === 'chat') { document.getElementById('online').style.display = ''; document.getElementById('offline').style.display = 'none'; } } } function check_presence() { var attr = document.getElementById('online').getAttribute('data-myjid'); var jid = attr.split('@'); var url = ['https://libraryh3lp.com/presence/jid', jid[0], jid[1], 'js'].join('/'); var script = document.createElement('script'); script.src = url + '?cb=show_presence'; document.getElementsByTagName('head')[0].appendChild(script); } check_presence(); </script>

Document URL: https://docs.libraryh3lp.com/presence-js.html

©2024 Nub Games, Inc.