aluzzardi / wssh

SSH to WebSockets Bridge
MIT License
1.37k stars 273 forks source link

fixed VIM freezes & support UTF-8 #15

Closed zlhgo closed 10 years ago

zlhgo commented 10 years ago

thanks,aluzzardi. sorry everyboy for my english.

diff --git a/wssh/server.py b/wssh/server.py
index 17a4965..b334477 100644
--- a/wssh/server.py
+++ b/wssh/server.py
@@ -118,19 +118,26 @@ class WSSHBridge(object):
                         data['resize'].get('width', 80),
                         data['resize'].get('height', 24))
                 if 'data' in data:
-                    channel.send(data['data'])
+                    channel.send(data['data'].encode('utf-8'))
         finally:
             self.close()

     def _forward_outbound(self, channel):
         """ Forward outbound traffic (ssh -> websockets) """
         try:
+            data = ''
             while True:
                 wait_read(channel.fileno())
-                data = channel.recv(1024)
-                if not len(data):
+                recv = channel.recv(1024)
+                if not len(recv):
                     return
-                self._websocket.send(json.dumps({'data': data}))
+                
+                data += recv
+                try:
+                    self._websocket.send(json.dumps({'data':data}))
+                    data = ''
+                except UnicodeDecodeError:
+                    pass
         finally:
             self.close()

diff --git a/wssh/static/term.js b/wssh/static/term.js
index 9489334..20883bf 100644
--- a/wssh/static/term.js
+++ b/wssh/static/term.js
@@ -129,9 +129,10 @@ function Terminal(cols, rows, handler) {

   this.cols = cols || Terminal.geometry[0];
   this.rows = rows || Terminal.geometry[1];
-
-  if (handler) {
-    this.on('data', handler);
+  this.handler = handler;
+  
+  if (this.handler) {
+    this.on('data', this.handler);
   }

   this.ybase = 0;
@@ -2432,7 +2433,7 @@ Terminal.prototype.reverseIndex = function() {

 // ESC c Full Reset (RIS).
 Terminal.prototype.reset = function() {
-  Terminal.call(this, this.cols, this.rows);
+  Terminal.call(this, this.cols, this.rows, this.handler);
   this.refresh(0, this.rows - 1);
 };
jumpserver commented 8 years ago

I try this patch, but when I login, I can't find the term anymore