Permalink
Browse files

implements fnordmetric enterprise websocket handshake

  • Loading branch information...
1 parent f298e01 commit d686da74081c80f25bd7c3872154beb592dace47 @paulasmuth committed Mar 5, 2013
Showing with 22 additions and 7 deletions.
  1. +5 −1 fnordmetric-enterprise/src/WebSocket.scala
  2. +17 −6 fnordmetric-ui/js/fnordmetric.js
View
6 fnordmetric-enterprise/src/WebSocket.scala
@@ -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")
}
View
23 fnordmetric-ui/js/fnordmetric.js
@@ -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') {
@@ -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;
@@ -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 {

0 comments on commit d686da7

Please sign in to comment.