aboutsummaryrefslogtreecommitdiffstats
path: root/web/src/js/Connection.es6.js
diff options
context:
space:
mode:
Diffstat (limited to 'web/src/js/Connection.es6.js')
-rw-r--r--web/src/js/Connection.es6.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/web/src/js/Connection.es6.js b/web/src/js/Connection.es6.js
new file mode 100644
index 00000000..9daa82e2
--- /dev/null
+++ b/web/src/js/Connection.es6.js
@@ -0,0 +1,33 @@
+class Connection {
+ constructor(root){
+ if(!root){
+ root = location.origin + "/api/v1";
+ }
+ this.root = root;
+ this.openWebSocketConnection();
+ }
+
+ openWebSocketConnection(){
+ this.ws = new WebSocket(this.root.replace("http","ws") + "/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);
+ }
+
+ onopen(open){
+ console.log("onopen", this, arguments);
+ }
+ onmessage(message){
+ console.log("onmessage", this, arguments);
+ }
+ onerror(error){
+ console.log("onerror", this, arguments);
+ }
+ onclose(close){
+ console.log("onclose", this, arguments);
+ }
+
+}