Stupid xterm
This commit is contained in:
parent
2f18843893
commit
f9d7bc89b0
17
index.html
17
index.html
@ -11,9 +11,14 @@
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
|
||||
<style>
|
||||
body {
|
||||
height: 100vh!important;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
div#terminal {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@ -22,10 +27,20 @@
|
||||
</div>
|
||||
<script>
|
||||
var term = new Terminal();
|
||||
term.open(document.getElementById('terminal'))
|
||||
|
||||
// Connect to the socket.io server
|
||||
var socket = io.connect('http://localhost:9774');
|
||||
// Wait for data from the server
|
||||
socket.on('client_identify', function() {
|
||||
var size = {
|
||||
height: document.querySelector('body').offsetHeight,
|
||||
width: document.querySelector('body').offsetWidth,
|
||||
}
|
||||
socket.emit('client_size', size)
|
||||
});
|
||||
|
||||
term.open(document.getElementById('terminal'))
|
||||
|
||||
socket.on('output', function (data) {
|
||||
term.write(data);
|
||||
});
|
||||
|
49
main.js
49
main.js
@ -24,25 +24,32 @@ var io = require('socket.io')(server);
|
||||
// When a new socket connects
|
||||
io.on('connection', function (socket) {
|
||||
console.log('Client connect');
|
||||
// Create terminal
|
||||
var term = pty.spawn('sh', [], {
|
||||
name: 'xterm-color',
|
||||
cols: 80,
|
||||
rows: 30,
|
||||
cwd: process.env.HOME,
|
||||
env: process.env
|
||||
});
|
||||
// Listen on the terminal for output and send it to the client
|
||||
term.on('data', function (data) {
|
||||
socket.emit('output', data);
|
||||
});
|
||||
// Listen on the client and send any input to the terminal
|
||||
socket.on('input', function (data) {
|
||||
term.write(data);
|
||||
});
|
||||
// When socket disconnects, destroy the terminal
|
||||
socket.on("disconnect", function () {
|
||||
term.destroy();
|
||||
console.log("Client disconnect");
|
||||
});
|
||||
socket.emit('client_identify');
|
||||
|
||||
socket.on('client_size', function (size) {
|
||||
// Create terminal
|
||||
console.log(size);
|
||||
console.log({ cols: Math.floor(size.width / 9), rows: Math.floor(size.height / 10) })
|
||||
|
||||
var term = pty.spawn('sh', [], {
|
||||
name: 'xterm-color',
|
||||
cols: Math.floor(size.width / 9),
|
||||
rows: Math.floor(size.height / 10),
|
||||
cwd: process.env.HOME,
|
||||
env: process.env
|
||||
});
|
||||
// Listen on the terminal for output and send it to the client
|
||||
term.on('data', function (data) {
|
||||
socket.emit('output', data);
|
||||
});
|
||||
// Listen on the client and send any input to the terminal
|
||||
socket.on('input', function (data) {
|
||||
term.write(data);
|
||||
});
|
||||
// When socket disconnects, destroy the terminal
|
||||
socket.on("disconnect", function () {
|
||||
term.destroy();
|
||||
console.log("Client disconnect");
|
||||
});
|
||||
})
|
||||
});
|
Loading…
Reference in New Issue
Block a user