aboutsummaryrefslogtreecommitdiffstats
path: root/web/src/js/connection.js
diff options
context:
space:
mode:
Diffstat (limited to 'web/src/js/connection.js')
-rw-r--r--web/src/js/connection.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/web/src/js/connection.js b/web/src/js/connection.js
new file mode 100644
index 00000000..3edbfc20
--- /dev/null
+++ b/web/src/js/connection.js
@@ -0,0 +1,33 @@
+function _Connection(url) {
+ this.url = url;
+}
+_Connection.prototype.init = function () {
+ this.openWebSocketConnection();
+};
+_Connection.prototype.openWebSocketConnection = function () {
+ this.ws = new WebSocket(this.url.replace("http", "ws"));
+ 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);
+};
+_Connection.prototype.onopen = function (open) {
+ console.debug("onopen", this, arguments);
+};
+_Connection.prototype.onmessage = function (message) {
+ //AppDispatcher.dispatchServerAction(...);
+ var m = JSON.parse(message.data);
+ AppDispatcher.dispatchServerAction(m);
+};
+_Connection.prototype.onerror = function (error) {
+ EventLogActions.add_event("WebSocket Connection Error.");
+ console.debug("onerror", this, arguments);
+};
+_Connection.prototype.onclose = function (close) {
+ EventLogActions.add_event("WebSocket Connection closed.");
+ console.debug("onclose", this, arguments);
+};
+
+var Connection = new _Connection(location.origin + "/updates");