Added error handling to the connection
This commit is contained in:
parent
dcbc4c90c6
commit
42016ac9bc
|
@ -26,3 +26,4 @@ node_modules
|
||||||
|
|
||||||
# Users Environment Variables
|
# Users Environment Variables
|
||||||
.lock-wscript
|
.lock-wscript
|
||||||
|
docs/Thumbs.db
|
||||||
|
|
|
@ -248,21 +248,21 @@ define({
|
||||||
// Save to history
|
// Save to history
|
||||||
pushHistory(buffer);
|
pushHistory(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Connect to server
|
// Post the help/welcome message
|
||||||
|
post('motd', templates.motd, true);
|
||||||
|
|
||||||
|
// Push 'Connecting...' message
|
||||||
|
post('info', $.template(templates.messages.connecting, {
|
||||||
|
host: data.host || 'localhost'
|
||||||
|
}));
|
||||||
|
|
||||||
|
// The one and only socket
|
||||||
socket = $.Websocket.connect(data.host);
|
socket = $.Websocket.connect(data.host);
|
||||||
|
|
||||||
// Bind socket events
|
// Bind socket events
|
||||||
socket
|
socket
|
||||||
.on('connect', function () {
|
|
||||||
$(document).on('keydown', onKeyDown);
|
|
||||||
components.input.focus();
|
|
||||||
})
|
|
||||||
|
|
||||||
.on('room:generated', function (data) {
|
.on('room:generated', function (data) {
|
||||||
var sanitized = $.escapeHtml(data);
|
var sanitized = $.escapeHtml(data);
|
||||||
post('server', $.template(templates.server.room_generated, { payload: sanitized }));
|
post('server', $.template(templates.server.room_generated, { payload: sanitized }));
|
||||||
|
@ -319,10 +319,19 @@ define({
|
||||||
} else {
|
} else {
|
||||||
post('error', templates.server.bogus);
|
post('error', templates.server.bogus);
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
// Post the help/welcome message
|
.on('connect', function () {
|
||||||
post('motd', templates.motd, true);
|
// Bind the necessary DOM events
|
||||||
|
$(document).on('keydown', onKeyDown);
|
||||||
|
|
||||||
|
// Put focus on the message input
|
||||||
|
components.input.focus();
|
||||||
|
|
||||||
|
// Tell the user that the chat is ready to interact with
|
||||||
|
post('info', $.template(templates.messages.connected, {
|
||||||
|
host: data.host || 'localhost'
|
||||||
|
}));
|
||||||
|
|
||||||
// It's possible to provide room and key using the hashtag.
|
// It's possible to provide room and key using the hashtag.
|
||||||
// The room and key is then seperated by semicolon (room:key).
|
// The room and key is then seperated by semicolon (room:key).
|
||||||
|
@ -333,4 +342,9 @@ define({
|
||||||
parts[0] && commands.join(parts[0]);
|
parts[0] && commands.join(parts[0]);
|
||||||
parts[1] && commands.key(parts[1]);
|
parts[1] && commands.key(parts[1]);
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
.on('error', function () {
|
||||||
|
post('error', templates.messages.socket_error);
|
||||||
|
});
|
||||||
});
|
});
|
|
@ -79,7 +79,13 @@ define({
|
||||||
left_room: 'Left room {roomName}',
|
left_room: 'Left room {roomName}',
|
||||||
already_in_room: 'You are already in a room ({roomName}), stoopid.',
|
already_in_room: 'You are already in a room ({roomName}), stoopid.',
|
||||||
|
|
||||||
unable_to_decrypt: 'Unabled to decrypt received message, keys does not match.'
|
unable_to_decrypt: 'Unabled to decrypt received message, keys does not match.',
|
||||||
|
|
||||||
|
socket_error: 'A network error has occurred. A restart may be required to bring back full functionality.<br>Examine the logs for more details.',
|
||||||
|
|
||||||
|
// Available variable: 'host'
|
||||||
|
connecting: 'Connecting to host {host}...',
|
||||||
|
connected: 'A connection to the server has been established. Happy chatting!'
|
||||||
},
|
},
|
||||||
|
|
||||||
server: {
|
server: {
|
||||||
|
|
Loading…
Reference in New Issue