Permalink
Browse files

applied MAILTO patch for PubNub JavaScript API discovered by Jon Wu @…

…jon_wu today.

added Disconnect and Reconnect events to PubNub JavaScript API.
  • Loading branch information...
1 parent 3d39179 commit 27e7025e09cf143e89766b8cac7fb387c9bb7ff7 @stephenlb stephenlb committed Feb 5, 2012
View
@@ -1,5 +1,6 @@
*~
*.swp
*.pyc
+*.class
.DS_Store
node_modules
View
@@ -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>
View
@@ -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 );
@@ -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 ]);
@@ -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(
Oops, something went wrong.
View
@@ -225,6 +225,17 @@
}
});
+
+ /*
+ restore : true,
+ disconnect : function() {
+ },
+ reconnect : function() {
+ },
+ connect : function() {
+ },
+ */
+
}
start_test();
Binary file not shown.
View
Oops, something went wrong.
Binary file not shown.

0 comments on commit 27e7025

Please sign in to comment.