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>
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
|
height: 100vh!important;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
div#terminal {
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
@ -22,10 +27,20 @@
|
|||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
var term = new Terminal();
|
var term = new Terminal();
|
||||||
term.open(document.getElementById('terminal'))
|
|
||||||
// Connect to the socket.io server
|
// Connect to the socket.io server
|
||||||
var socket = io.connect('http://localhost:9774');
|
var socket = io.connect('http://localhost:9774');
|
||||||
// Wait for data from the server
|
// 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) {
|
socket.on('output', function (data) {
|
||||||
term.write(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
|
// When a new socket connects
|
||||||
io.on('connection', function (socket) {
|
io.on('connection', function (socket) {
|
||||||
console.log('Client connect');
|
console.log('Client connect');
|
||||||
// Create terminal
|
socket.emit('client_identify');
|
||||||
var term = pty.spawn('sh', [], {
|
|
||||||
name: 'xterm-color',
|
socket.on('client_size', function (size) {
|
||||||
cols: 80,
|
// Create terminal
|
||||||
rows: 30,
|
console.log(size);
|
||||||
cwd: process.env.HOME,
|
console.log({ cols: Math.floor(size.width / 9), rows: Math.floor(size.height / 10) })
|
||||||
env: process.env
|
|
||||||
});
|
var term = pty.spawn('sh', [], {
|
||||||
// Listen on the terminal for output and send it to the client
|
name: 'xterm-color',
|
||||||
term.on('data', function (data) {
|
cols: Math.floor(size.width / 9),
|
||||||
socket.emit('output', data);
|
rows: Math.floor(size.height / 10),
|
||||||
});
|
cwd: process.env.HOME,
|
||||||
// Listen on the client and send any input to the terminal
|
env: process.env
|
||||||
socket.on('input', function (data) {
|
});
|
||||||
term.write(data);
|
// Listen on the terminal for output and send it to the client
|
||||||
});
|
term.on('data', function (data) {
|
||||||
// When socket disconnects, destroy the terminal
|
socket.emit('output', data);
|
||||||
socket.on("disconnect", function () {
|
});
|
||||||
term.destroy();
|
// Listen on the client and send any input to the terminal
|
||||||
console.log("Client disconnect");
|
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