How do I detect changes in a JavaScript client's connection state? 

You can detect your local connection state to the internet on any JavaScript ready devices such as mobile phones and web browsers. Use advanced parameters and register the following callbacks (which fire during connection state changes):

    <div pub-key="demo" sub-key="demo" id="pubnub"></div>
<script src=""></script>
// listen for messages
// connect to a channel
channel : "channel_abc",
// resubscribe and reconnect
restore : true,
// message received
callback : function() {alert(JSON.stingify(m))},
// conneciton lost
disconnect : function() {alert("Connection Lost!")},
// connection restored
reconnect : function() {alert("And we're Back!")},
// connection established
connect : function() {
// send a message
channel : "channel_abc",
message : "Hi from PubNub."