commit 191bb109e07e13eeae65c85f5a22c4f9bc8b0e7e parent 28360c31e2b8762af997dbeefcb0943d166dd4df Author: Sheng <webmaster0115@gmail.com> Date: Tue, 22 May 2018 19:28:04 +0800 Fixed a bug that client closes websocket on handling non utf-8 encoded bytes Diffstat:
M | webssh/static/js/main.js | | | 10 | ++++++++-- |
M | webssh/worker.py | | | 2 | +- |
2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/webssh/static/js/main.js b/webssh/static/js/main.js @@ -91,8 +91,14 @@ jQuery(function($){ }; socket.onmessage = function(msg) { - // console.log(msg); - term.write(msg.data); + var reader = new FileReader(); + reader.onloadend = function(event){ + var decoder = new TextDecoder(); + var text = decoder.decode(reader.result); + // console.log(text); + term.write(text); + }; + reader.readAsArrayBuffer(msg.data); }; socket.onerror = function(e) { diff --git a/webssh/worker.py b/webssh/worker.py @@ -63,7 +63,7 @@ class Worker(object): logging.debug('{!r} to {}:{}'.format(data, *self.handler.src_addr)) try: - self.handler.write_message(data) + self.handler.write_message(data, binary=True) except tornado.websocket.WebSocketClosedError: self.close(reason='websocket closed')