From a69bd842735403ab172803e8dd140d516ee650e1 Mon Sep 17 00:00:00 2001 From: ori agranat Date: Sat, 23 Mar 2019 23:42:24 +0200 Subject: [PATCH] working websocket from vue to tornado --- backend/app/ChameleonVisionApp.py | 3 +- backend/app/handlers/SocketHandler.py | 8 +++-- chameleon-client/package-lock.json | 30 ++++++++++++++----- chameleon-client/src/App.vue | 7 +++-- chameleon-client/src/components/InputTab.vue | 4 ++- chameleon-client/src/components/ch-select.vue | 12 ++++---- chameleon-client/src/components/ch-slider.vue | 2 +- chameleon-client/src/main.js | 3 +- 8 files changed, 47 insertions(+), 22 deletions(-) diff --git a/backend/app/ChameleonVisionApp.py b/backend/app/ChameleonVisionApp.py index 2bbdf8e39..dd46abe1f 100644 --- a/backend/app/ChameleonVisionApp.py +++ b/backend/app/ChameleonVisionApp.py @@ -11,7 +11,8 @@ define("port", default=8888, help="run on the given port", type=int) class ChameleonApplication(tornado.web.Application): def __init__(self): - handlers = [(r"/", MainHandler), + handlers = [ + # (r"/", MainHandler), (r"/websocket", ChameleonWebSocket)] settings = dict( diff --git a/backend/app/handlers/SocketHandler.py b/backend/app/handlers/SocketHandler.py index ebb5af37d..ab0a0aba1 100644 --- a/backend/app/handlers/SocketHandler.py +++ b/backend/app/handlers/SocketHandler.py @@ -1,12 +1,16 @@ import tornado.websocket +import json class ChameleonWebSocket(tornado.websocket.WebSocketHandler): + def check_origin(self, origin): + return True def open(self): print("WebSocket opened") def on_message(self, message): - print(message) - self.write_message("why the fuck did you send a message") + print(json.loads(message)) + # print(message) + self.write_message(message) def on_close(self): print("WebSocket closed") diff --git a/chameleon-client/package-lock.json b/chameleon-client/package-lock.json index 7f74702ee..f6adf12f0 100644 --- a/chameleon-client/package-lock.json +++ b/chameleon-client/package-lock.json @@ -5665,7 +5665,8 @@ }, "ansi-regex": { "version": "2.1.1", - "bundled": true + "bundled": true, + "optional": true }, "aproba": { "version": "1.2.0", @@ -5683,11 +5684,13 @@ }, "balanced-match": { "version": "1.0.0", - "bundled": true + "bundled": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -5700,15 +5703,18 @@ }, "code-point-at": { "version": "1.1.0", - "bundled": true + "bundled": true, + "optional": true }, "concat-map": { "version": "0.0.1", - "bundled": true + "bundled": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", - "bundled": true + "bundled": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -5811,7 +5817,8 @@ }, "inherits": { "version": "2.0.3", - "bundled": true + "bundled": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -5821,6 +5828,7 @@ "is-fullwidth-code-point": { "version": "1.0.0", "bundled": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -5833,6 +5841,7 @@ "minimatch": { "version": "3.0.4", "bundled": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -5932,7 +5941,8 @@ }, "number-is-nan": { "version": "1.0.1", - "bundled": true + "bundled": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -5942,6 +5952,7 @@ "once": { "version": "1.4.0", "bundled": true, + "optional": true, "requires": { "wrappy": "1" } @@ -6047,6 +6058,7 @@ "string-width": { "version": "1.0.2", "bundled": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -6064,6 +6076,7 @@ "strip-ansi": { "version": "3.0.1", "bundled": true, + "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -6102,7 +6115,8 @@ }, "wrappy": { "version": "1.0.2", - "bundled": true + "bundled": true, + "optional": true }, "yallist": { "version": "3.0.3", diff --git a/chameleon-client/src/App.vue b/chameleon-client/src/App.vue index ecf5ab397..24432cc58 100644 --- a/chameleon-client/src/App.vue +++ b/chameleon-client/src/App.vue @@ -54,7 +54,7 @@ diff --git a/chameleon-client/src/components/InputTab.vue b/chameleon-client/src/components/InputTab.vue index 33702b615..63c579849 100644 --- a/chameleon-client/src/components/InputTab.vue +++ b/chameleon-client/src/components/InputTab.vue @@ -26,7 +26,9 @@ import chselect from './ch-select.vue' }, methods: { onChange(i) { - console.log(i); + // console.log(i); + this.$socket.send(JSON.stringify(i)); + } } } diff --git a/chameleon-client/src/components/ch-select.vue b/chameleon-client/src/components/ch-select.vue index 21cefb905..c8999a18a 100644 --- a/chameleon-client/src/components/ch-select.vue +++ b/chameleon-client/src/components/ch-select.vue @@ -14,11 +14,11 @@