Skip to content

Commit

Permalink
implements fnordmetric enterprise websocket handshake
Browse files Browse the repository at this point in the history
  • Loading branch information
asmuth committed Mar 5, 2013
1 parent f298e01 commit d686da7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
6 changes: 5 additions & 1 deletion fnordmetric-enterprise/src/WebSocket.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ class WebSocket extends org.eclipse.jetty.websocket.WebSocket.OnTextMessage {

var endpoint : Connection = null

def onOpen(conn: Connection) = {
def onOpen(conn: Connection) : Unit = {
endpoint = conn

if (conn.getProtocol == null || conn.getProtocol != "fnordmetric_enterprise")
return conn.close(1003, "fnordmetric_enterprise")

FnordMetric.log_debug("[WebSocket] connection opened")
}

Expand Down
23 changes: 17 additions & 6 deletions fnordmetric-ui/js/fnordmetric.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
var FnordMetric = (function(pre){

var wsAddress, socket, currentNamespace;
var widgets = {};
var wsAddress, socket, currentNamespace,
widgets = {},
enterprise = false;

function setup(opts) {
if (typeof $ == 'undefined') {
Expand All @@ -18,7 +19,11 @@ var FnordMetric = (function(pre){
}

function connect() {
socket = new WebSocket(wsAddress);
if (enterprise)
socket = new WebSocket(wsAddress, "fnordmetric_enterprise");
else
socket = new WebSocket(wsAddress);

socket.onmessage = onSocketMessage;
socket.onclose = onSocketClose;
socket.onopen = onSocketOpen;
Expand Down Expand Up @@ -77,9 +82,15 @@ var FnordMetric = (function(pre){
});
}

function onSocketClose() {
console.log("[FnordMetric] socket closed");
window.setTimeout(connect, 1000);
function onSocketClose(e) {
if (e.code = 1003 && e.reason == "fnordmetric_enterprise") {
console.log("[FnordMetric] switching to fnordmetric enterprise protocol")
enterprise = true;
window.setTimeout(connect, 100);
} else {
console.log("[FnordMetric] socket closed");
window.setTimeout(connect, 1000);
}
}

return {
Expand Down

0 comments on commit d686da7

Please sign in to comment.