Optimize code

Signed-off-by: Jianhui Zhao <jianhuizhao329@gmail.com>
This commit is contained in:
Jianhui Zhao
2018-01-18 14:29:15 +08:00
parent ffde167d1b
commit c1e8f816c1
+7 -3
View File
@@ -35,6 +35,10 @@
return null;
}
function sendMsg(data) {
ws.send(JSON.stringify({type: 'data', did: did, sid: sid, data: Base64.encode(data)}));
}
function new_session(did) {
ws = new WebSocket('ws://' + location.host + '/ws/browser?did=' + did);
ws.onopen = function() {
@@ -45,7 +49,7 @@
});
term.on('data', function(data) {
ws.send(JSON.stringify({type: 'data', did: did, sid: sid, data: Base64.encode(data)}));
sendMsg(data);
});
term.on('open', function() {
@@ -72,12 +76,12 @@
var data = Base64.decode(resp.data);
if (recvDataCnt < 5) {
if (data.match('login:') && username && username != '') {
ws.send(JSON.stringify({type: 'data', did: did, sid: sid, data: Base64.encode(username + '\n')}));
sendMsg(username + '\n');
return;
}
if (data.match('Password:') && password && password != '') {
ws.send(JSON.stringify({type: 'data', did: did, sid: sid, data: Base64.encode(password + '\n')}));
sendMsg(password + '\n');
return;
}
}