dayu/packages/core/public/logs/js/index.js
MiaoWoo 84c304a26a feat: add config and exec
Signed-off-by: MiaoWoo <admin@yumc.pw>
2019-12-31 18:35:00 +08:00

71 lines
1.5 KiB
JavaScript

let command = '';
Terminal.applyAddon(fit);
Terminal.applyAddon(attach);
Terminal.applyAddon(fullscreen);
var term = new Terminal({
experimentalCharAtlas: 'dynamic',
cursorBlink: false,
});
term.open(document.getElementById('terminal'));
term.toggleFullScreen();
term.fit();
window.onresize = function() {
term.fit();
}
let query = {}
location.search.substring(1).split("&").forEach(q => {
let qy = q.split("=", 2);
query[qy[0]] = qy[1]
})
function connectServer(namespace, id) {
var server = io(namespace, {
path: '/ws',
transports: ['websocket']
});
server.on('connect', () => {
term.writeln('connect')
server.emit('logs', {
id: id,
tail: "200"
})
});
server.on('message', data => {
term.write(data.toString() + '\r\n');
});
server.on('disconnect', () => {
term.reset();
term.writeln('disconnect');
});
}
console.log(query);
term.writeln(`Recover Action: ${query.action} Data: ${query.data}`)
switch (query.action) {
case "container":
case "service":
connectServer(`/${query.action}`, query.data)
break;
default:
var system = io('/', {
path: '/ws',
transports: ['websocket']
});
system.on('connect', () => {
system.emit('events', {})
})
system.on('message', data => {
term.write(data.toString() + '\r\n');
});
}
term.on('data', async data => {
});