diff --git a/app.js b/app.js
index 7db0273..399555b 100644
--- a/app.js
+++ b/app.js
@@ -13,4 +13,6 @@ handle["/js/jquery-1.12.1.min"] = requestHandlers.sendJquery;
handle["/js/jquery-ui.js"] = requestHandlers.sendJqueryUI;
handle["/css/bootstrap.min.css"] = requestHandlers.sendBootstrap;
+handle["/clear"] = requestHandlers.sendClear;
+
server.start(router.route,handle,debug);
diff --git a/board.html b/board.html
index 3f994d0..7a0a200 100644
--- a/board.html
+++ b/board.html
@@ -71,8 +71,14 @@ body {
function initSocketIO()
{
iosocket = io.connect();
+
+ iosocket.on('clientrefresh', function() {
+ location.reload();
+ });
+
iosocket.on('onconnection', function() {
- initButton();
+
+
iosocket.on('debugMessage', function(message) {
alert(message);
@@ -81,9 +87,9 @@ body {
iosocket.on('config', function(phonenumber) {
mynumber = phonenumber;
$( "span.number" ).html(mynumber);
- console.log(mynumber);
});
+
iosocket.on('newMessage', function(time,number,message,color) {
var censoredNumber = number.substring(0,3) + "********" +number.substring(number.length - 3, number.length);
var messages = document.getElementById('messagesBody');
diff --git a/clear.html b/clear.html
new file mode 100644
index 0000000..7f1dc06
--- /dev/null
+++ b/clear.html
@@ -0,0 +1,62 @@
+
+
+
+
+Clear Board
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/requestHandlers.js b/requestHandlers.js
index ebdc415..b702778 100644
--- a/requestHandlers.js
+++ b/requestHandlers.js
@@ -47,6 +47,16 @@ function sendJqueryUI(response) {
response.end(html);
}
+function sendClear(response) {
+ console.log("Request handler 'clear' was called.");
+ response.writeHead(200, {"Content-Type": "text/html"});
+ var html = fs.readFileSync(__dirname + "/clear.html")
+ response.end(html);
+}
+
+
+exports.sendClear = sendClear;
+
exports.sendBootstrap = sendBootstrap;
exports.sendJqueryUI = sendJqueryUI;
diff --git a/server.js b/server.js
index 2611882..89153d8 100644
--- a/server.js
+++ b/server.js
@@ -68,6 +68,16 @@ function initSocketIO(httpServer,debug)
console.log("user connected");
socket.emit('onconnection');
+
+ socket.on('clear', function(number) {
+
+ var index = db.object.messages.length - 1;
+ db.object.messages.splice(index,1);
+ db.write();
+
+ console.log('removed entry ' + number)
+ });
+
socket.on('getConfig', function(data) {
var number = config('mainConfig').chain().find({ param: 'mynumber' }).value()['value'];
socket.emit('config',number);
@@ -78,6 +88,11 @@ function initSocketIO(httpServer,debug)
console.log('sending AT...');
});
+ socket.on('refreshClients', function() {
+ console.log('Refreshing all clients');
+ socketServer.emit('clientrefresh'); // send this to all so use socketServer
+ });
+
socket.on('getLastMessages', function(number) {
console.log('retrieving messages');
var times = db('messages').chain().takeRight(number).map('time').value();