Commit a4e7ea6d authored by Kannan V M's avatar Kannan V M
Browse files

add mod section with delte facility

parent 227fde4b
......@@ -13,6 +13,17 @@ server.listen(port, () => {
//assign static path to public folder
app.use(express.static(path.join(__dirname, '/')));
app.get('/mod', (req, res) => {
res.sendFile(__dirname + '/mod.html');
});
app.get('/', (req, res) => {
res.sendFile(__dirname + '/index.html');
});
const user = io.of('/');
const mod = io.of('/mod');
var leafids = [];
for (let i=7; i<332; i++) {
leafID = "path" + i.toString();
......@@ -24,7 +35,7 @@ var leavesdata = {}; //object of structure {socketid1: {leaftext:"text",leafid:"
var leafno = 0;
var socketids = [];
io.on('connection', (socket) => {
user.on('connection', (socket) => {
let id = socket.id;
io.to(id).emit('leaves data', leavesdata);
......@@ -38,6 +49,20 @@ io.on('connection', (socket) => {
leavesdata[id]["leaftext"] = leafdata["leaftext"]; //if yes update the message
leafdata = leavesdata[id];
};
socket.emit('leaf data', leafdata);
io.emit('leaf data', leafdata);
io.of('mod').emit('leaves data', leavesdata);
});
});
mod.on('connection', (socket) => {
io.of('mod').emit('leaves data', leavesdata);
socket.on('message delete', id => {
io.emit('delete text', leavesdata[id]["leafid"]);
delete leavesdata[id];
const index = socketids.indexOf(id);
if (index > -1) {
socketids.splice(index, 1);
}
io.of('mod').emit('leaves data', leavesdata);
});
});
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment