2014-09-16 21:40:25 +00:00
|
|
|
function _Connection(url) {
|
|
|
|
this.url = url;
|
|
|
|
}
|
2014-09-17 00:13:37 +00:00
|
|
|
_Connection.prototype.init = function () {
|
2014-09-16 09:06:30 +00:00
|
|
|
this.openWebSocketConnection();
|
|
|
|
};
|
2014-09-17 00:13:37 +00:00
|
|
|
_Connection.prototype.openWebSocketConnection = function () {
|
2014-09-16 21:40:25 +00:00
|
|
|
this.ws = new WebSocket(this.url.replace("http", "ws"));
|
2014-09-16 09:06:30 +00:00
|
|
|
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);
|
|
|
|
};
|
2014-09-17 00:13:37 +00:00
|
|
|
_Connection.prototype.onopen = function (open) {
|
2014-09-16 09:06:30 +00:00
|
|
|
console.log("onopen", this, arguments);
|
|
|
|
};
|
2014-09-17 00:13:37 +00:00
|
|
|
_Connection.prototype.onmessage = function (message) {
|
2014-09-16 09:06:30 +00:00
|
|
|
//AppDispatcher.dispatchServerAction(...);
|
2014-09-17 01:58:56 +00:00
|
|
|
var m = JSON.parse(message.data);
|
|
|
|
switch (m.type){
|
|
|
|
case "flow":
|
|
|
|
console.log("flow", m.data);
|
|
|
|
break;
|
|
|
|
case "event":
|
|
|
|
console.log("event", m.data.message)
|
|
|
|
break;
|
|
|
|
}
|
2014-09-16 09:06:30 +00:00
|
|
|
};
|
2014-09-17 00:13:37 +00:00
|
|
|
_Connection.prototype.onerror = function (error) {
|
2014-09-16 09:06:30 +00:00
|
|
|
console.log("onerror", this, arguments);
|
|
|
|
};
|
2014-09-17 00:13:37 +00:00
|
|
|
_Connection.prototype.onclose = function (close) {
|
2014-09-16 09:06:30 +00:00
|
|
|
console.log("onclose", this, arguments);
|
|
|
|
};
|
2014-09-16 04:26:16 +00:00
|
|
|
|
2014-09-16 21:40:25 +00:00
|
|
|
var Connection = new _Connection(location.origin + "/updates");
|