2014-09-15 22:05:06 +00:00
|
|
|
class _Connection {
|
|
|
|
constructor(root) {
|
|
|
|
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
|
|
|
}
|
|
|
|
init() {
|
2014-09-15 16:08:26 +00:00
|
|
|
this.openWebSocketConnection();
|
|
|
|
}
|
2014-09-15 22:05:06 +00:00
|
|
|
openWebSocketConnection() {
|
|
|
|
this.ws = new WebSocket(this.root.replace("http", "ws") + "/ws");
|
2014-09-15 16:08:26 +00:00
|
|
|
var ws = this.ws;
|
|
|
|
|
|
|
|
ws.onopen = this.onopen.bind(this);
|
|
|
|
ws.onmessage = this.onmessage.bind(this);
|
|
|
|
ws.onerror = this.onerror.bind(this);
|
|
|
|
ws.onclose = this.onclose.bind(this);
|
|
|
|
}
|
2014-09-15 22:05:06 +00:00
|
|
|
onopen(open) {
|
2014-09-15 16:08:26 +00:00
|
|
|
console.log("onopen", this, arguments);
|
|
|
|
}
|
2014-09-15 22:05:06 +00:00
|
|
|
onmessage(message) {
|
|
|
|
//AppDispatcher.dispatchServerAction(...);
|
2014-09-15 16:08:26 +00:00
|
|
|
console.log("onmessage", this, arguments);
|
|
|
|
}
|
2014-09-15 22:05:06 +00:00
|
|
|
onerror(error) {
|
2014-09-15 16:08:26 +00:00
|
|
|
console.log("onerror", this, arguments);
|
|
|
|
}
|
2014-09-15 22:05:06 +00:00
|
|
|
onclose(close) {
|
2014-09-15 16:08:26 +00:00
|
|
|
console.log("onclose", this, arguments);
|
|
|
|
}
|
|
|
|
}
|
2014-09-15 22:05:06 +00:00
|
|
|
var Connection = new _Connection();
|