text: // Generated by CoffeeScript 1.6.3
  var SkeletonSync,
    __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
  
  SkeletonSync = (function() {
    function SkeletonSync(skeleton, endpoint) {
      this.skeleton = skeleton;
      this.endpoint = endpoint != null ? endpoint : 'local';
      this.onSocketMessage = __bind(this.onSocketMessage, this);
      this.onSocketClosed = __bind(this.onSocketClosed, this);
      this.onSocketOpened = __bind(this.onSocketOpened, this);
      this.onSocketIOMessage = __bind(this.onSocketIOMessage, this);
      this.socket = null;
      this.reconnecting = false;
      this.onUserIn = null;
      this.onUserOut = null;
      this.onRatio = null;
      this.onDataUpdated = null;
    }
  
    SkeletonSync.prototype.connect = function() {
      var _this = this;
      if (this.endpoint === 'local') {
        this.socket = new WebSocket('ws://kikko.local:9092');
        this.socket.binaryType = 'arraybuffer';
        this.socket.onopen = this.onSocketOpened;
        this.socket.onclose = this.onSocketClosed;
        return this.socket.onmessage = function(msg) {
          return _this.onSocketMessage(msg.data);
        };
      } else {
        this.socket = io.connect(this.endpoint);
        this.socket.on('connect', this.onSocketOpened);
        this.socket.on('message', this.onSocketMessage);
        return this.socket.on('skeleton', function(data) {
          if (data) {
            _this.skeleton.data = data;
            if (_this.onDataUpdated) {
              return onDataUpdated();
            }
          }
        });
      }
    };
  
    SkeletonSync.prototype.onSocketIOMessage = function(data) {
      return console.log('message');
    };
  
    SkeletonSync.prototype.onSocketOpened = function() {
      return console.log("websocket connected");
    };
  
    SkeletonSync.prototype.onSocketClosed = function() {
      var _this = this;
      if (!this.reconnecting) {
        console.log("websocket disconnected");
      }
      setTimeout(function() {
        return _this.connect();
      }, 2000);
      return this.reconnecting = true;
    };
  
    SkeletonSync.prototype.onSocketMessage = function(data) {
      var cmd;
      if (data instanceof ArrayBuffer) {
        this.skeleton.data = new Float32Array(data);
        if (this.onDataUpdated) {
          return onDataUpdated();
        }
      } else {
        if (data === '/skeleton') {
  
        } else {
          cmd = data.split('/');
          cmd.shift();
          switch (cmd[0]) {
            case 'user':
              if (cmd[1] === 'in') {
                if (this.onUserIn) {
                  return this.onUserIn(cmd[2]);
                }
              } else {
                if (this.onUserOut) {
                  return this.onUserOut(cmd[2]);
                }
              }
              break;
            case 'ratio':
              if (this.onRatio) {
                return this.onRatio(parseFloat(cmd[1]) / parseFloat(cmd[2]));
              }
              break;
            default:
              return console.log(data);
          }
        }
      }
    };
  
    return SkeletonSync;
  
  })();
  