2014-09-05 10:33:43 +04:00
|
|
|
var shell = {
|
2014-09-30 10:55:04 +04:00
|
|
|
_shellWS: undefined,
|
2014-09-25 05:46:24 +04:00
|
|
|
_initWS: function () {
|
2014-09-30 10:55:04 +04:00
|
|
|
shell.shellWS = new WebSocket(config.channel.shell + '/shell/ws?sid=' + config.wideSessionId);
|
|
|
|
shell.shellWS.onopen = function () {
|
2014-09-25 05:46:24 +04:00
|
|
|
console.log('[shell onopen] connected');
|
|
|
|
};
|
2014-09-30 10:55:04 +04:00
|
|
|
shell.shellWS.onmessage = function (e) {
|
2014-09-25 05:46:24 +04:00
|
|
|
console.log('[shell onmessage]' + e.data);
|
|
|
|
var data = JSON.parse(e.data);
|
|
|
|
if ('init-shell' !== data.cmd) {
|
|
|
|
$('#shellOutput').val(data.output);
|
|
|
|
}
|
|
|
|
};
|
2014-09-30 10:55:04 +04:00
|
|
|
shell.shellWS.onclose = function (e) {
|
2014-09-25 05:46:24 +04:00
|
|
|
console.log('[shell onclose] disconnected (' + e.code + ')');
|
2014-09-30 10:55:04 +04:00
|
|
|
delete shell.shellWS;
|
2014-09-25 05:46:24 +04:00
|
|
|
};
|
2014-09-30 10:55:04 +04:00
|
|
|
shell.shellWS.onerror = function (e) {
|
2014-09-25 05:46:24 +04:00
|
|
|
console.log('[shell onerror] ' + e);
|
|
|
|
};
|
|
|
|
},
|
|
|
|
init: function () {
|
|
|
|
this._initWS();
|
|
|
|
|
|
|
|
$('#shellInput').keydown(function (event) {
|
2014-09-05 10:33:43 +04:00
|
|
|
if (13 === event.which) {
|
|
|
|
var input = {
|
|
|
|
cmd: $('#shellInput').val()
|
|
|
|
};
|
2014-09-30 10:55:04 +04:00
|
|
|
shell.shellWS.send(JSON.stringify(input));
|
2014-09-05 10:33:43 +04:00
|
|
|
$('#shellInput').val('');
|
|
|
|
}
|
2014-09-25 05:46:24 +04:00
|
|
|
});
|
2014-09-05 10:33:43 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-09-25 05:46:24 +04:00
|
|
|
$(document).ready(function () {
|
2014-09-05 10:33:43 +04:00
|
|
|
shell.init();
|
|
|
|
});
|