FEATURE: add optional shouldLongPollCallback

FEATURE: add optional shouldLongPollCallback

This allows consumers to decide at runtime when to long poll and when to avoid it.

diff --git a/CHANGELOG b/CHANGELOG
index f0bfca9..8378a4a 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,9 @@
+26-03-2020
+
+- Version 2.2.4
+
+  - FEATURE: shouldLongPollCallback optional setting which allows overriding decision about long polling
+
 18-10-2019
 
 - Version 2.2.3
diff --git a/README.md b/README.md
index 950716c..29a7657 100644
--- a/README.md
+++ b/README.md
@@ -280,6 +280,7 @@ backgroundCallbackInterval|60000|Interval to poll when long polling is disabled 
 minPollInterval|100|When polling requests succeed, this is the minimum amount of time to wait before making the next request.
 maxPollInterval|180000|If request to the server start failing, MessageBus will backoff, this is the upper limit of the backoff.
 alwaysLongPoll|false|For debugging you may want to disable the "is browser in background" check and always long-poll
+shouldLongPollCallback|undefined|A callback returning true or false that determines if we should long-poll or not, if unset ignore and simply depend on window visibility.
 baseUrl|/|If message bus is mounted at a sub-path or different domain, you may configure it to perform requests there
 ajax|$.ajax falling back to XMLHttpRequest|MessageBus will first attempt to use jQuery and then fallback to a plain XMLHttpRequest version that's contained in the `message-bus-ajax.js` file. `message-bus-ajax.js` must be loaded after `message-bus.js` for it to be used. You may override this option with a function that implements an ajax request by some other means
 headers|{}|Extra headers to be include with requests. Properties and values of object must be valid values for HTTP Headers, i.e. no spaces or control characters.
diff --git a/assets/message-bus.js b/assets/message-bus.js
index 7ad8f34..5b87051 100644
--- a/assets/message-bus.js
+++ b/assets/message-bus.js
@@ -99,7 +99,10 @@
   };
 
   shouldLongPoll = function() {
-    return me.alwaysLongPoll || !isHidden();
+    return (
+      me.alwaysLongPoll ||
+      (me.shouldLongPollCallback ? me.shouldLongPollCallback() : !isHidden())
+    );
   };
 
   var totalAjaxFailures = 0;
@@ -377,6 +380,7 @@
     callbacks: callbacks,
     clientId: clientId,
     alwaysLongPoll: false,
+    shouldLongPollCallback: undefined,
     baseUrl: baseUrl,
     headers: {},
     ajax: jQuery && jQuery.ajax,

GitHub sha: 8ed1b6cd