Permalink
Browse files

updated pubnub javascript api with improved on-reconnect callback.

  • Loading branch information...
stephenlb committed Jun 5, 2012
1 parent 5677781 commit 1cf64829c6ed3cd1e8375be7791e1a1cf44c3d69
@@ -404,6 +404,11 @@ function PN(setup) {
}
timeout( pubnub, 1000 );
SELF['time'](function(success){
+ // Reconnect
+ if (success && disconnected) {
+ disconnected = 0;
+ reconnect();
+ }
success || error();
});
},
View
@@ -213,7 +213,7 @@ function rnow() { return+new Date }
var db = (function(){
var ls = window['localStorage'];
return {
- get : function(key) {
+ 'get' : function(key) {
try {
if (ls) return ls.getItem(key);
if (document.cookie.indexOf(key) == -1) return null;
@@ -222,7 +222,7 @@ var db = (function(){
)||[])[1] || null;
} catch(e) { return }
},
- set : function( key, value ) {
+ 'set' : function( key, value ) {
try {
if (ls) return ls.setItem( key, value ) && 0;
document.cookie = key + '=' + value +
@@ -797,7 +797,14 @@ var PDIV = $('pubnub') || {}
}
timeout( pubnub, SECOND );
SELF['time'](function(success){
- success || error();
+ // Reconnect
+ if (success && disconnected) {
+ disconnected = 0;
+ reconnect();
+ }
+ else {
+ error();
+ }
});
},
success : function(messages) {

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -24,7 +24,7 @@ test('PUBNUB JavaScript API', function (test) {
message : { test : "test" },
callback : function(response) {
test.ok(response[0]);
- test.equal( response[1], 'D' );
+ test.equal( response[1], 'Sent' );
}
});
}
View
@@ -33,7 +33,7 @@ browsers=$browsers',safari/5.1'
echo -e "Testing: $browsers"
-noinstrument='pubnub-3.1.js'
+noinstrument='pubnub-3.1.js,test.js'
tar -cf- test.js ../pubnub-3.1.js | \
curl -u $1 -sSNT- \
@@ -46,7 +46,7 @@
</script>
<div id=pubnub pub-key=demo sub-key=demo></div>
-<script src=http://pubnub.s3.amazonaws.com/pubnub-3.1.min.js></script>
+<script src=../pubnub-3.1.min.js></script>
<script>(function(){
function test( t, msg ) {
View

Large diffs are not rendered by default.

Oops, something went wrong.
Binary file not shown.
@@ -50,7 +50,7 @@
<div id=pubnub></div>
<!--
-<script src=http://cdn.pubnub.com/pubnub-3.1.min.js></script>
+<script src=http://pubnub.s3.amazonaws.com/pubnub-3.1.js></script>
<script src=../crypto.js></script>
<script src=../socket.io.js></script>
-->

0 comments on commit 1cf6482

Please sign in to comment.