Commit 4c3120e5 by Sheng

Reuse decoder

parent 24a619ae
...@@ -96,23 +96,42 @@ jQuery(function($){ ...@@ -96,23 +96,42 @@ jQuery(function($){
join = (ws_url[ws_url.length-1] === '/' ? '' : '/'), join = (ws_url[ws_url.length-1] === '/' ? '' : '/'),
url = ws_url + join + 'ws?id=' + msg.id, url = ws_url + join + 'ws?id=' + msg.id,
sock = new window.WebSocket(url), sock = new window.WebSocket(url),
encoding = msg.encoding, encoding, decoder,
terminal = document.getElementById('#terminal'), terminal = document.getElementById('#terminal'),
term = new window.Terminal({ term = new window.Terminal({
cursorBlink: true, cursorBlink: true,
}); });
console.log(url); console.log(url);
console.log('The deault encoding of your server is ' + encoding); console.log('The deault encoding of your server is ' + msg.encoding);
// wssh.sock = sock; // wssh.sock = sock;
// wssh.term = term; // wssh.term = term;
var test_decoder;
function resize_terminal (term) { function resize_terminal (term) {
var geometry = current_geometry(); var geometry = current_geometry();
term.on_resize(geometry.cols, geometry.rows); term.on_resize(geometry.cols, geometry.rows);
} }
function set_encoding (new_encoding) {
// for console use
if (new_encoding === undefined) {
console.log('An encoding is required');
return;
}
try {
decoder = new window.TextDecoder(new_encoding);
encoding = new_encoding;
console.log('Set encoding to ' + encoding);
} catch(TypeError) {
console.log('Unknown encoding ' + new_encoding);
}
}
wssh.set_encoding = set_encoding;
set_encoding(msg.encoding);
wssh.window_geometry = function() { wssh.window_geometry = function() {
// for console use // for console use
var geometry = current_geometry(); var geometry = current_geometry();
...@@ -139,33 +158,12 @@ jQuery(function($){ ...@@ -139,33 +158,12 @@ jQuery(function($){
} }
}; };
wssh.set_encoding = function (new_encoding) {
// for console use
if (new_encoding === undefined) {
console.log('An encoding is required');
return;
}
try {
test_decoder = new window.TextDecoder(new_encoding);
} catch(TypeError) {
console.log('Unknown encoding ' + new_encoding);
} finally {
if (test_decoder !== undefined) {
test_decoder = undefined;
encoding = new_encoding;
console.log('Set encoding to ' + encoding);
}
}
};
wssh.reset_encoding = function () { wssh.reset_encoding = function () {
// for console use // for console use
if (encoding === msg.encoding) { if (encoding === msg.encoding) {
console.log('Already reset to ' + msg.encoding); console.log('Already reset to ' + msg.encoding);
} else { } else {
encoding = msg.encoding; set_encoding(msg.encoding);
console.log('Reset encoding to ' + msg.encoding);
} }
}; };
...@@ -216,7 +214,6 @@ jQuery(function($){ ...@@ -216,7 +214,6 @@ jQuery(function($){
var reader = new window.FileReader(); var reader = new window.FileReader();
reader.onloadend = function(){ reader.onloadend = function(){
var decoder = new window.TextDecoder(encoding);
var text = decoder.decode(reader.result); var text = decoder.decode(reader.result);
// console.log(text); // console.log(text);
if (term) { if (term) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment