mirror of
https://github.com/sorenisanerd/gotty.git
synced 2024-11-09 15:24:25 +00:00
Split input into buffer sized chunks
Input chunks from the client exceeding the buffer size would get truncated. Now we communicate the size of the buffer to the webtty and it will split the input into buffer sized chunks. Fixes #1.
This commit is contained in:
parent
77c436b99b
commit
0d6766f621
2
js/dist/gotty-bundle.js
vendored
2
js/dist/gotty-bundle.js
vendored
File diff suppressed because one or more lines are too long
2
js/dist/webtty.d.ts
vendored
2
js/dist/webtty.d.ts
vendored
@ -9,6 +9,7 @@ export declare const msgPong = "2";
|
||||
export declare const msgSetWindowTitle = "3";
|
||||
export declare const msgSetPreferences = "4";
|
||||
export declare const msgSetReconnect = "5";
|
||||
export declare const msgSetBufferSize = "6";
|
||||
export interface Terminal {
|
||||
info(): {
|
||||
columns: number;
|
||||
@ -43,6 +44,7 @@ export declare class WebTTY {
|
||||
args: string;
|
||||
authToken: string;
|
||||
reconnect: number;
|
||||
bufSize: number;
|
||||
constructor(term: Terminal, connectionFactory: ConnectionFactory, args: string, authToken: string);
|
||||
open(): () => void;
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ export const msgPong = '2';
|
||||
export const msgSetWindowTitle = '3';
|
||||
export const msgSetPreferences = '4';
|
||||
export const msgSetReconnect = '5';
|
||||
export const msgSetBufferSize = '6';
|
||||
|
||||
|
||||
export interface Terminal {
|
||||
@ -48,6 +49,7 @@ export class WebTTY {
|
||||
args: string;
|
||||
authToken: string;
|
||||
reconnect: number;
|
||||
bufSize: number;
|
||||
|
||||
constructor(term: Terminal, connectionFactory: ConnectionFactory, args: string, authToken: string) {
|
||||
this.term = term;
|
||||
@ -55,6 +57,7 @@ export class WebTTY {
|
||||
this.args = args;
|
||||
this.authToken = authToken;
|
||||
this.reconnect = -1;
|
||||
this.bufSize = 1024;
|
||||
};
|
||||
|
||||
open() {
|
||||
@ -90,7 +93,14 @@ export class WebTTY {
|
||||
|
||||
this.term.onInput(
|
||||
(input: string) => {
|
||||
connection.send(msgInput + input);
|
||||
// Leave room for message type id
|
||||
let effectiveBufferSize = this.bufSize - 1;
|
||||
|
||||
// Split input into buffer sized chunks
|
||||
for (let i = 0; i < Math.ceil(input.length/effectiveBufferSize); i++) {
|
||||
let inputChunk = input.substring(i*effectiveBufferSize, Math.min((i+1)*effectiveBufferSize, input.length))
|
||||
connection.send(msgInput + inputChunk);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
@ -120,6 +130,10 @@ export class WebTTY {
|
||||
console.log("Enabling reconnect: " + autoReconnect + " seconds")
|
||||
this.reconnect = autoReconnect;
|
||||
break;
|
||||
case msgSetBufferSize:
|
||||
const bufSize = JSON.parse(payload);
|
||||
this.bufSize = bufSize;
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
|
File diff suppressed because one or more lines are too long
@ -28,4 +28,6 @@ const (
|
||||
SetPreferences = '4'
|
||||
// Make terminal to reconnect
|
||||
SetReconnect = '5'
|
||||
// Set the input buffer size
|
||||
SetBufferSize = '6'
|
||||
)
|
||||
|
@ -115,6 +115,12 @@ func (wt *WebTTY) sendInitializeMessage() error {
|
||||
return errors.Wrapf(err, "failed to send window title")
|
||||
}
|
||||
|
||||
bufSizeMsg, _ := json.Marshal(wt.bufferSize)
|
||||
err = wt.masterWrite(append([]byte{SetBufferSize}, bufSizeMsg...))
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to send buffer size")
|
||||
}
|
||||
|
||||
if wt.reconnect > 0 {
|
||||
reconnect, _ := json.Marshal(wt.reconnect)
|
||||
err := wt.masterWrite(append([]byte{SetReconnect}, reconnect...))
|
||||
|
Loading…
Reference in New Issue
Block a user