Skip to content

Commit

Permalink
applied MAILTO patch for PubNub JavaScript API discovered by Jon Wu @…
Browse files Browse the repository at this point in the history
…jon_wu today.

added Disconnect and Reconnect events to PubNub JavaScript API.
  • Loading branch information
stephenlb committed Feb 5, 2012
1 parent 3d39179 commit 27e7025
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 47 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,5 +1,6 @@
*~
*.swp
*.pyc
*.class
.DS_Store
node_modules
52 changes: 52 additions & 0 deletions javascript/mailto-fix.html
@@ -0,0 +1,52 @@
<!doctype html>
<html>
<head>
<title>PubNub JavaScript MailTO Fix</title>
<link
rel=stylesheet
href=http://twitter.github.com/bootstrap/1.4.0/bootstrap.min.css
>
</head>
<body><div class=container>

<!-- NOTICE / TITLE -->
<div class="alert-message warning">
<a class="close" href="#">&#215;</a>
<p><strong>PubNub MailTO Test</strong> for JavaScript on Mobile and Desktop Web Browser</p>
</div>

<!-- BUTTON PANNEL -->
<div class=well>
<a href="mailto:hello@pubnub.com">hello@pubnub.com</a>
</div>
<div id=output class=well>0</div>

<div id=pubnub></div>
<script src=pubnub-3.1.min.js></script>
<script>(function(){

var msgs = 1
, out = PUBNUB.$('output');;

PUBNUB.subscribe({
channel : 'mailto-testing',
disconnect : function() {},
connect : function() {startitup()},
reconnect : function() {},
callback : function(num) {
out.innerHTML += ', ' + num;
}
});

function startitup() {
setInterval( function() {
PUBNUB.publish({
channel : 'mailto-testing',
message : msgs++
});
}, 250 );
}

})();</script>
</div></body>
</html>
38 changes: 25 additions & 13 deletions javascript/pubnub-3.1.js
Expand Up @@ -589,8 +589,8 @@ function ajax( setup ) {
new XDomainRequest() ||
new XMLHttpRequest();

xhr.onerror = function(){ done(1) };
xhr.onload = finished;
xhr.onerror = xhr.onabort = function(){ done(1) };
xhr.onload = xhr.onloadend = finished;
xhr.timeout = XHRTME;

xhr.open( 'GET', setup.url.join(URLBIT), true );
Expand Down Expand Up @@ -784,14 +784,16 @@ var PDIV = $('pubnub') || {}
*/
'subscribe' : function( args, callback ) {

var channel = args['channel']
, callback = callback || args['callback']
, restore = args['restore']
, timetoken = 0
, error = args['error'] || function(){}
, connected = 0
, connect = args['connect'] || function(){}
, origin = nextorigin(ORIGIN);
var channel = args['channel']
, callback = callback || args['callback']
, restore = args['restore']
, timetoken = 0
, connect = args['connect'] || function(){}
, reconnect = args['reconnect'] || function(){}
, disconnect = args['error']||args['disconnect']||function(){}
, disconnected = 0
, connected = 0
, origin = nextorigin(ORIGIN);

// Reduce Status Flicker
if (!READY) return READY_BUFFER.push([ args, callback, SELF ]);
Expand Down Expand Up @@ -823,19 +825,29 @@ var PDIV = $('pubnub') || {}
jsonp, timetoken
],
fail : function() {
// Disconnect
if (!disconnected) {
disconnected = 1;
disconnect();
}

timeout( pubnub, SECOND );
SELF['time'](function(success){
success || error();
});
},
success : function(messages) {
if (!CHANNELS[channel].connected) return;

// Connect
if (!connected) {
connected = 1;
connect();
}

// Reconnect
if (disconnected) {
disconnected = 0;
reconnect();
}

// Restore Previous Connection Point if Needed
// Also Update Timetoken
restore = db.set(
Expand Down
34 changes: 17 additions & 17 deletions javascript/pubnub-3.1.min.js

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions javascript/unit-test.html
Expand Up @@ -225,6 +225,17 @@
}
});


/*
restore : true,
disconnect : function() {
},
reconnect : function() {
},
connect : function() {
},
*/

}
start_test();

Expand Down
Binary file modified socket.io/bootstrap-mobile/.DS_Store
Binary file not shown.
35 changes: 18 additions & 17 deletions socket.io/socket.io.min.js

Large diffs are not rendered by default.

Binary file modified socket.io/socket.io.min.js.gz
Binary file not shown.

0 comments on commit 27e7025

Please sign in to comment.