Working connect/disconnect handlers and status indicator

This commit is contained in:
AlexKvazos
2015-04-28 11:19:36 -05:00
parent 542ae1f549
commit 793fe3e162
7 changed files with 55 additions and 10 deletions
@@ -13,9 +13,4 @@ module.exports = function($scope, socket, buffer) {
buffer.append('---');
buffer.append('<br>');
// buffer errors when received
socket.on('bot:error', function(error) {
buffer.error(error);
});
};
+1
View File
@@ -7,5 +7,6 @@ exports.register = function(app) {
app.controller('connectController', require('./connectController'));
app.controller('bufferController', require('./bufferController'));
app.controller('chatController', require('./chatController'));
app.controller('navController', require('./navController'));
};
+30
View File
@@ -0,0 +1,30 @@
/**
* Connect Controller
*/
module.exports = function($scope, socket) {
$scope.connected = false;
socket.on('bot:connect', function(data) {
$scope.$apply(function() {
$scope.host = data.host;
$scope.port = data.port;
$scope.username = data.username;
$scope.connected = true;
});
});
socket.on('bot:disconnect', function() {
$scope.$apply(function() {
$scope.connected = false;
});
})
socket.on('disconnect', function() {
$scope.$apply(function() {
$scope.connected = false;
});
});
};
+1 -1
View File
@@ -15,7 +15,7 @@ module.exports = function(socket) {
});
socket.on('buffer:error', function(string) {
$('#buffer').append('<span style="color:#D62D18;">[i] ' + error + '</span><br>')
$('#buffer').append('<span style="color:#D62D18;">[i] ' + string + '</span><br>')
$('#buffer').scrollTop($('#buffer').prop('scrollHeight'));
});
+16 -2
View File
@@ -30,7 +30,11 @@ module.exports = function(socket) {
// login event
bot.on('login', function() {
socket.emit('buffer:success', 'Successfully logged in as ' + bot.username + ' with entity id ' + bot.entity.id);
socket.emit('bot:login')
socket.emit('bot:connect', {
host: socket.connectionParams.hostname,
port: socket.connectionParams.port,
username: socket.connectionParams.username
});
});
// spawn event
@@ -69,7 +73,7 @@ module.exports = function(socket) {
// format the buffer with the correct coloring
buffer = buffer.replace(/§([0-9abcdef])([^§]*)/ig, function replace(regex, color, msg) {
return '<span class="color-'+color+'">'+msg+'</span>';
return '<span class="color-'+color+'">'+msg.replace(' ', '&nbsp;')+'</span>';
});
// send line back to the client
@@ -77,4 +81,14 @@ module.exports = function(socket) {
});
bot.on('end', function() {
socket.emit('buffer:error', 'Connection lost...');
socket.emit('bot:disconnect');
});
bot.on('kick', function(reason) {
console.log(reason);
socket.emit('buffer:error', 'Kicked for: ' + reason);
});
};
+4
View File
@@ -16,9 +16,13 @@ module.exports = function(socket) {
password: data.password
});
// store connection params in socket
socket.connectionParams = data;
// prepare for errors
socket.mcbot.on('error', function(error) {
socket.emit('buffer:error', error);
socket.mcbot = null;
});
// bind bot events