Created
September 28, 2014 15:35
-
-
Save developerdizzle/887d3e3b5bab01f4e32e to your computer and use it in GitHub Desktop.
Primus WS Reconnect client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="en" ng-app> | |
<head> | |
<title>Primus WS Reconnect Example</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<link rel="stylesheet" href="/css/bootstrap.min.css"> | |
<link rel="stylesheet" href="/css/bootstrap-responsive.min.css"> | |
<style> | |
body { | |
padding-top: 60px; | |
} | |
</style> | |
<script src="/js/jquery.min.js"></script> | |
<script src="/js/bootstrap.min.js"></script> | |
<script src="/js/primus.js"></script> | |
<script> | |
$(function() { | |
var log = $('#log')[0]; | |
console.log = function (message) { | |
if (typeof message == 'object') { | |
log.innerHTML += (JSON && JSON.stringify ? JSON.stringify(message) : message) + '\n'; | |
} else { | |
log.innerHTML += message + '\n'; | |
} | |
} | |
window.spark = window.spark || new window.Primus({ | |
reconnect: { | |
retries: 20 | |
}, | |
timeout: 5000, | |
ping: 5000, | |
pong: 5000, | |
queueSize: 50, | |
manual: true, | |
}); | |
window.spark.on('offline', function() { | |
console.log('offline'); | |
}); | |
window.spark.on('online', function() { | |
console.log('online'); | |
}); | |
window.spark.on('reconnecting', function(opts) { | |
console.log('reconnecting'); | |
console.log('Reconnecting in ' + opts.timeout + 'ms'); | |
console.log('This is attempt ' + opts.attempt + ' out of ' + opts.retries); | |
}); | |
window.spark.on('reconnect', function() { | |
console.log('reconnect'); | |
}); | |
window.spark.on('reconnected', function() { | |
console.log('reconnected'); | |
}); | |
window.spark.on('open', function() { | |
console.log('open'); | |
}); | |
window.spark.on('close', function() { | |
console.log('close'); | |
}); | |
window.spark.on('outgoing::ping', function() { | |
console.log('outgoing::ping'); | |
}); | |
window.spark.on('incoming::pong', function() { | |
console.log('incoming::pong'); | |
}); | |
window.spark.open(); | |
}); | |
</script> | |
</head> | |
<body> | |
<div class="container" ng-controller="ChatController"> | |
<div class="navbar navbar-fixed-top navbar-inverse"> | |
<div class="navbar-inner"> | |
<div class="pull-right"> | |
<a href="https://c9.io" class="brand">Cloud9 IDE</a> | |
</div> | |
</div> | |
</div> | |
<div class="page-header"> | |
<h1>Primus WS Reconnect Example</h1> | |
</div> | |
<div class="row"> | |
<div class="col-sm-12"> | |
This server is running off Forever, and will exit the process 10 seconds after a Primus/WS connection is made. 15 seconds later, it will restart. | |
</div> | |
</div> | |
<div class="row well"> | |
<pre id="log"></pre> | |
</div> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment