Skip to content

Instantly share code, notes, and snippets.

@s3u
Created November 16, 2011 13:54
Show Gist options
  • Save s3u/1370108 to your computer and use it in GitHub Desktop.
Save s3u/1370108 to your computer and use it in GitHub Desktop.
function probe(cb) {
var wsCtor = window['MozWebSocket'] ? MozWebSocket : WebSocket;
var socket = new wsCtor(uri, 'blah');
socket.onopen = function () {
// Send a probe
socket.send(JSON.stringify({
type: 'probe',
data: {}
}));
};
socket.onerror = function() {
cb('Not supported');
}
socket.onmessage = function(e) {
cb();
}
socket.onclose = function() {
cb('Not supported');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment