this.websocket = new WebSocket(url);
this.websocket.onopen = function(event) {
window.setInterval(function() { server.send(['PING']) }, 30000);
- server.send(['GET_GAMESTATE']);
+ tui.log_msg("@ server connected!");
+ tui.init_login();
};
},
send: function(tokens) {
- this.websocket.send(unparser.untokenize(tokens));
+ if (this.websocket.readyState !== WebSocket.OPEN) {
+ tui.log_msg('server disconnected :(');
+ } else {
+ this.websocket.send(unparser.untokenize(tokens));
+ }
}
}
this.shows_annotations = shows_annotations;
}
}
+let mode_waiting_for_server = new Mode('waiting_for_server', false, false);
let mode_login = new Mode('login', true, false);
let mode_chat = new Mode('chat', true, false);
let mode_annotate = new Mode('annotate', true, true);
let mode_edit = new Mode('edit', false, false);
let tui = {
- mode: mode_login,
+ mode: mode_waiting_for_server,
log: [],
input_prompt: '> ',
input: '',
init: function() {
this.recalc_input_lines();
this.height_header = this.height_turn_line + this.height_mode_line;
- this.log_msg("Please enter your username:");
+ this.log_msg("@ waiting for server connection ...");
+ },
+ init_login: function() {
+ this.log_msg("@ please enter your username:");
+ this.switch_mode(mode_login);
},
switch_mode: function(mode, keep_pos=false) {
if (mode == mode_study && !keep_pos) {
tui.log_msg('@ ' + tokens[1]);
tui.refresh();
} else if (tokens[0] === 'LOGIN_OK') {
- tui.log_msg('@ ' + tokens[1]);
+ server.send(['GET_GAMESTATE']);
tui.log_help();
+ tui.log_msg('@ ' + tokens[1]);
tui.switch_mode(mode_chat);
} else if (tokens[0] === 'ANNOTATION') {
let position = parser.parse_yx(tokens[1]);