2014-09-16 04:26:16 +00:00
|
|
|
function _Connection(root) {"use strict";
|
2014-09-15 22:05:06 +00:00
|
|
|
if (!root) {
|
2014-09-15 16:08:26 +00:00
|
|
|
root = location.origin + "/api/v1";
|
|
|
|
}
|
|
|
|
this.root = root;
|
2014-09-15 22:05:06 +00:00
|
|
|
}
|
2014-09-16 09:06:30 +00:00
|
|
|
_Connection.prototype.init=function() {"use strict";
|
|
|
|
this.openWebSocketConnection();
|
|
|
|
};
|
|
|
|
_Connection.prototype.openWebSocketConnection=function() {"use strict";
|
|
|
|
this.ws = new WebSocket(this.root.replace("http", "ws") + "/ws");
|
|
|
|
var ws = this.ws;
|
2014-09-15 16:08:26 +00:00
|
|
|
|
2014-09-16 09:06:30 +00:00
|
|
|
ws.onopen = this.onopen.bind(this);
|
|
|
|
ws.onmessage = this.onmessage.bind(this);
|
|
|
|
ws.onerror = this.onerror.bind(this);
|
|
|
|
ws.onclose = this.onclose.bind(this);
|
|
|
|
};
|
|
|
|
_Connection.prototype.onopen=function(open) {"use strict";
|
|
|
|
console.log("onopen", this, arguments);
|
|
|
|
};
|
|
|
|
_Connection.prototype.onmessage=function(message) {"use strict";
|
|
|
|
//AppDispatcher.dispatchServerAction(...);
|
|
|
|
console.log("onmessage", this, arguments);
|
|
|
|
};
|
|
|
|
_Connection.prototype.onerror=function(error) {"use strict";
|
|
|
|
console.log("onerror", this, arguments);
|
|
|
|
};
|
|
|
|
_Connection.prototype.onclose=function(close) {"use strict";
|
|
|
|
console.log("onclose", this, arguments);
|
|
|
|
};
|
2014-09-16 04:26:16 +00:00
|
|
|
|
|
|
|
var Connection = new _Connection();
|