PubNub on 3G/4G/LTE Mobile Networks
Use the backfill: true
option when you invoke the pubnub.subscribe(...)
method. This allows your device to receive messages on mobile networks. The backfill option prevents mobile network latency race conditions.
// Setup
var channel = 'a'+Math.random();
var pubnub = PUBNUB({
ssl : true
, "publish_key" : "pub-c-aefb421c-b30a-4afc-bae4-b866c5ea3d69"
, "subscribe_key" : "sub-c-76f89e66-c3a9-11e5-b5a8-0693d8625082"
});
// Receive Message
pubnub.subscribe({
backfill : true
, channel : channel
, error : out
, connect : publish
, message : out
});
// Send Message
function publish() {
out("CONNECTED!");
pubnub.publish({
channel : channel
, error : out
, message : "SUCCESS IT WORKS!"
});
}
// Network Check
pubnub.time(function(a){out(a ? "NETWORK CHECK" : "NETWORK BAD")});
function out(m) {
document.getElementById("result").innerHTML
+= "<br>" + JSON.stringify(m);
}
<script src="https://cdn.pubnub.com/pubnub-dev.js"></script>
<h1>PubNub 3G/4G/LTE Network</h1>
<div id="result">PROCESSING_CONNECTIVITY...</div>

PubNub Mobile Network - Example Output
You may also decide that you want another option. You can also issue the pubnub.publish()
method call inside the connect
callback.
pubnub.subscribe({
channel : channel,
message : out,
connect : function() {
pubnub.publish({
channel : channel
, message : "SUCCESS IT WORKS!"
});
}
});