Commit d686da74 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

implements fnordmetric enterprise websocket handshake

parent f298e01a
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -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")
  }

+17 −6
Original line number Diff line number Diff line
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() {
    if (enterprise)
      socket = new WebSocket(wsAddress, "fnordmetric_enterprise");
    else
      socket = new WebSocket(wsAddress);

    socket.onmessage = onSocketMessage;
    socket.onclose = onSocketClose;
    socket.onopen = onSocketOpen;
@@ -77,10 +82,16 @@ var FnordMetric = (function(pre){
    });
  }

  function onSocketClose() {
  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 {
    setup: setup,