server: remove the reconnect option (enabled by default)

This commit is contained in:
Shuanglei Tao
2019-07-05 23:05:09 +08:00
parent fd29928a9c
commit 0fc275f3a3
8 changed files with 7 additions and 45 deletions

View File

@@ -80,7 +80,6 @@ OPTIONS:
-u, --uid User id to run with -u, --uid User id to run with
-g, --gid Group id to run with -g, --gid Group id to run with
-s, --signal Signal to send to the command when exit it (default: 1, SIGHUP) -s, --signal Signal to send to the command when exit it (default: 1, SIGHUP)
-r, --reconnect Time to reconnect for the client in seconds (default: 10)
-a, --url-arg Allow client to send command line arguments in URL (eg: http://localhost:7681?arg=foo&arg=bar) -a, --url-arg Allow client to send command line arguments in URL (eg: http://localhost:7681?arg=foo&arg=bar)
-R, --readonly Do not allow clients to write to the TTY -R, --readonly Do not allow clients to write to the TTY
-t, --client-option Send option to client (format: key=value), repeat to add more options -t, --client-option Send option to client (format: key=value), repeat to add more options

View File

@@ -21,7 +21,6 @@ const enum Command {
OUTPUT = '0', OUTPUT = '0',
SET_WINDOW_TITLE = '1', SET_WINDOW_TITLE = '1',
SET_PREFERENCES = '2', SET_PREFERENCES = '2',
SET_RECONNECT = '3',
// client side // client side
INPUT = '0', INPUT = '0',
@@ -44,7 +43,6 @@ export class Xterm extends Component<Props> {
private zmodemAddon: ZmodemAddon; private zmodemAddon: ZmodemAddon;
private socket: WebSocket; private socket: WebSocket;
private title: string; private title: string;
private reconnect: number;
private resizeTimeout: number; private resizeTimeout: number;
private backoff: backoff.Backoff; private backoff: backoff.Backoff;
@@ -124,7 +122,6 @@ export class Xterm extends Component<Props> {
socket.onopen = this.onSocketOpen; socket.onopen = this.onSocketOpen;
socket.onmessage = this.onSocketData; socket.onmessage = this.onSocketData;
socket.onclose = this.onSocketClose; socket.onclose = this.onSocketClose;
socket.onerror = this.onSocketError;
terminal.loadAddon(fitAddon); terminal.loadAddon(fitAddon);
terminal.loadAddon(overlayAddon); terminal.loadAddon(overlayAddon);
@@ -166,7 +163,7 @@ export class Xterm extends Component<Props> {
private onSocketClose(event: CloseEvent) { private onSocketClose(event: CloseEvent) {
console.log(`[ttyd] websocket connection closed with code: ${event.code}`); console.log(`[ttyd] websocket connection closed with code: ${event.code}`);
const { overlayAddon, openTerminal, reconnect } = this; const { overlayAddon } = this;
overlayAddon.showOverlay('Connection Closed', null); overlayAddon.showOverlay('Connection Closed', null);
window.removeEventListener('beforeunload', this.onWindowUnload); window.removeEventListener('beforeunload', this.onWindowUnload);
@@ -174,15 +171,11 @@ export class Xterm extends Component<Props> {
if (event.code === 1008) { if (event.code === 1008) {
window.location.reload(); window.location.reload();
} }
// 1000: CLOSE_NORMAL
if (event.code !== 1000 && reconnect > 0) {
setTimeout(openTerminal, reconnect * 1000);
}
}
@bind // 1000: CLOSE_NORMAL
private onSocketError() { if (event.code !== 1000) {
this.backoff.backoff(); this.backoff.backoff();
}
} }
@bind @bind
@@ -207,10 +200,6 @@ export class Xterm extends Component<Props> {
terminal.setOption(key, preferences[key]); terminal.setOption(key, preferences[key]);
}); });
break; break;
case Command.SET_RECONNECT:
this.reconnect = Number(textDecoder.decode(data));
console.log(`[ttyd] enabling reconnect: ${this.reconnect} seconds`);
break;
default: default:
console.warn(`[ttyd] unknown command: ${cmd}`); console.warn(`[ttyd] unknown command: ${cmd}`);
break; break;

View File

@@ -54,10 +54,6 @@ Cross platform: macOS, Linux, FreeBSD/OpenBSD, OpenWrt/LEDE, Windows
\-s, \-\-signal <signal string> \-s, \-\-signal <signal string>
Signal to send to the command when exit it (default: 1, SIGHUP) Signal to send to the command when exit it (default: 1, SIGHUP)
.PP
\-r, \-\-reconnect <seconds>
Time to reconnect for the client in seconds (default: 10)
.PP .PP
\-a, \-\-url\-arg \-a, \-\-url\-arg
Allow client to send command line arguments in URL (eg: Allow client to send command line arguments in URL (eg:

View File

@@ -37,9 +37,6 @@ ttyd 1 "September 2016" ttyd "User Manual"
-s, --signal <signal string> -s, --signal <signal string>
Signal to send to the command when exit it (default: 1, SIGHUP) Signal to send to the command when exit it (default: 1, SIGHUP)
-r, --reconnect <seconds>
Time to reconnect for the client in seconds (default: 10)
-a, --url-arg -a, --url-arg
Allow client to send command line arguments in URL (eg: http://localhost:7681?arg=foo&arg=bar) Allow client to send command line arguments in URL (eg: http://localhost:7681?arg=foo&arg=bar)

2
src/index.html vendored

File diff suppressed because one or more lines are too long

View File

@@ -28,7 +28,6 @@
// initial message list // initial message list
char initial_cmds[] = { char initial_cmds[] = {
SET_WINDOW_TITLE, SET_WINDOW_TITLE,
SET_RECONNECT,
SET_PREFERENCES SET_PREFERENCES
}; };
@@ -45,9 +44,6 @@ send_initial_message(struct lws *wsi, int index) {
gethostname(buffer, sizeof(buffer) - 1); gethostname(buffer, sizeof(buffer) - 1);
n = sprintf((char *) p, "%c%s (%s)", cmd, server->command, buffer); n = sprintf((char *) p, "%c%s (%s)", cmd, server->command, buffer);
break; break;
case SET_RECONNECT:
n = sprintf((char *) p, "%c%d", cmd, server->reconnect);
break;
case SET_PREFERENCES: case SET_PREFERENCES:
n = sprintf((char *) p, "%c%s", cmd, server->prefs_json); n = sprintf((char *) p, "%c%s", cmd, server->prefs_json);
break; break;

View File

@@ -44,7 +44,6 @@ static const struct option options[] = {
{"uid", required_argument, NULL, 'u'}, {"uid", required_argument, NULL, 'u'},
{"gid", required_argument, NULL, 'g'}, {"gid", required_argument, NULL, 'g'},
{"signal", required_argument, NULL, 's'}, {"signal", required_argument, NULL, 's'},
{"reconnect", required_argument, NULL, 'r'},
{"index", required_argument, NULL, 'I'}, {"index", required_argument, NULL, 'I'},
{"ipv6", no_argument, NULL, '6'}, {"ipv6", no_argument, NULL, '6'},
{"ssl", no_argument, NULL, 'S'}, {"ssl", no_argument, NULL, 'S'},
@@ -62,7 +61,7 @@ static const struct option options[] = {
{"help", no_argument, NULL, 'h'}, {"help", no_argument, NULL, 'h'},
{NULL, 0, 0, 0} {NULL, 0, 0, 0}
}; };
static const char *opt_string = "p:i:c:u:g:s:r:I:6aSC:K:A:Rt:T:Om:oBd:vh"; static const char *opt_string = "p:i:c:u:g:s:I:6aSC:K:A:Rt:T:Om:oBd:vh";
void print_help() { void print_help() {
fprintf(stderr, "ttyd is a tool for sharing terminal over the web\n\n" fprintf(stderr, "ttyd is a tool for sharing terminal over the web\n\n"
@@ -77,7 +76,6 @@ void print_help() {
" -u, --uid User id to run with\n" " -u, --uid User id to run with\n"
" -g, --gid Group id to run with\n" " -g, --gid Group id to run with\n"
" -s, --signal Signal to send to the command when exit it (default: 1, SIGHUP)\n" " -s, --signal Signal to send to the command when exit it (default: 1, SIGHUP)\n"
" -r, --reconnect Time to reconnect for the client in seconds (default: 10)\n"
" -a, --url-arg Allow client to send command line arguments in URL (eg: http://localhost:7681?arg=foo&arg=bar)\n" " -a, --url-arg Allow client to send command line arguments in URL (eg: http://localhost:7681?arg=foo&arg=bar)\n"
" -R, --readonly Do not allow clients to write to the TTY\n" " -R, --readonly Do not allow clients to write to the TTY\n"
" -t, --client-option Send option to client (format: key=value), repeat to add more options\n" " -t, --client-option Send option to client (format: key=value), repeat to add more options\n"
@@ -110,7 +108,6 @@ tty_server_new(int argc, char **argv, int start) {
memset(ts, 0, sizeof(struct tty_server)); memset(ts, 0, sizeof(struct tty_server));
LIST_INIT(&ts->clients); LIST_INIT(&ts->clients);
ts->client_count = 0; ts->client_count = 0;
ts->reconnect = 10;
ts->sig_code = SIGHUP; ts->sig_code = SIGHUP;
sprintf(ts->terminal_type, "%s", "xterm-256color"); sprintf(ts->terminal_type, "%s", "xterm-256color");
get_sig_name(ts->sig_code, ts->sig_name, sizeof(ts->sig_name)); get_sig_name(ts->sig_code, ts->sig_name, sizeof(ts->sig_name));
@@ -329,13 +326,6 @@ main(int argc, char **argv) {
} }
} }
break; break;
case 'r':
server->reconnect = atoi(optarg);
if (server->reconnect < 0) {
fprintf(stderr, "ttyd: invalid reconnect: %s\n", optarg);
return -1;
}
break;
case 'I': case 'I':
if (!strncmp(optarg, "~/", 2)) { if (!strncmp(optarg, "~/", 2)) {
const char* home = getenv("HOME"); const char* home = getenv("HOME");
@@ -448,9 +438,6 @@ main(int argc, char **argv) {
lwsl_notice(" start command: %s\n", server->command); lwsl_notice(" start command: %s\n", server->command);
lwsl_notice(" close signal: %s (%d)\n", server->sig_name, server->sig_code); lwsl_notice(" close signal: %s (%d)\n", server->sig_name, server->sig_code);
lwsl_notice(" terminal type: %s\n", server->terminal_type); lwsl_notice(" terminal type: %s\n", server->terminal_type);
if (server->reconnect > 0) {
lwsl_notice(" reconnect timeout: %ds\n", server->reconnect);
}
if (server->check_origin) if (server->check_origin)
lwsl_notice(" check origin: true\n"); lwsl_notice(" check origin: true\n");
if (server->url_arg) if (server->url_arg)

View File

@@ -11,7 +11,6 @@
#define OUTPUT '0' #define OUTPUT '0'
#define SET_WINDOW_TITLE '1' #define SET_WINDOW_TITLE '1'
#define SET_PREFERENCES '2' #define SET_PREFERENCES '2'
#define SET_RECONNECT '3'
// websocket url path // websocket url path
#define WS_PATH "/ws" #define WS_PATH "/ws"
@@ -65,7 +64,6 @@ struct tty_server {
int client_count; // client count int client_count; // client count
char *prefs_json; // client preferences char *prefs_json; // client preferences
char *credential; // encoded basic auth credential char *credential; // encoded basic auth credential
int reconnect; // reconnect timeout
char *index; // custom index.html char *index; // custom index.html
char *command; // full command line char *command; // full command line
char **argv; // command with arguments char **argv; // command with arguments