PubNub: Publish does not seem to be working for me on 3G network -
i'm using pubnub. there no problem doing publish , subscribe. however, publish not work on slow connection 3g network. wifi ok people 4g has have same problem. know how fix it?
what want below.
1. usera opens web page pc , subscribe channel. 2. usera publishes data channel mobile app.
pubnub on 3g/4g/lte mobile networks
use backfill: true
option when invoke pubnub.subscribe(...)
method. allows device receive messages on mobile networks. 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 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 decide want option. can issue pubnub.publish()
method call inside connect
callback.
pubnub.subscribe({ channel : channel, message : out, connect : function() { pubnub.publish({ channel : channel , message : "success works!" }); } });
Comments
Post a Comment