Merge branch 'main' of github.com:koush/scrypted

This commit is contained in:
Koushik Dutta
2023-10-25 08:49:14 -07:00
2 changed files with 18 additions and 5 deletions

View File

@@ -37,16 +37,22 @@ export default {
const rootLocation = `${window.location.protocol}//${window.location.host}`;
this.socket = eio(rootLocation, options);
this.socket.send(JSON.stringify({ dim: { cols: term.cols, rows: term.rows } }));
this.socket.on("message", (data) => {
term.write(new Uint8Array(Buffer.from(data)));
term.write(new Uint8Array(Buffer.from(JSON.parse(data).data)));
});
term.onData((data) => {
this.socket.send(data);
this.socket.send(JSON.stringify({ data }));
});
term.on('resize', dim => {
this.socket.send(JSON.stringify({ dim }));
});
term.onBinary((data) => {
this.socket.send(data);
this.socket.send(JSON.stringify({ data }));
});
},
destroyed() {

View File

@@ -119,8 +119,15 @@ export class ScryptedRuntime extends PluginHttp<HttpPluginData> {
const spawn = require('node-pty-prebuilt-multiarch').spawn as typeof ptySpawn;
const cp = spawn(process.env.SHELL, [], {
});
cp.onData(data => connection.send(data));
connection.on('message', message => cp.write(message.toString()));
cp.onData(data => connection.send(JSON.stringify({data})));
connection.on('message', message => {
const parsed = JSON.parse(message.toString());
if (parsed.data) {
cp.write(parsed.data);
} else if (parsed.dim) {
cp.resize(parsed.dim.cols, parsed.dim.rows);
}
});
connection.on('close', () => cp.kill());
}
catch (e) {