repl.it
@rshetty/

Communol

Nodejs

No description

fork
loading
Files
  • index.js
  • public
  • package-lock.json
  • package-lock.json.973160351
  • package.json
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
var express = require('express');
var app = express();
var server = require('http').Server(app);
var io = require('socket.io').listen(server);
var hash = require('hash.js');

mapObjects = [];

// Use correct file directory
app.use(express.static('/home/runner/public'));
app.get('/', function (req, res) {
  res.sendFile(__dirname + '/index.html');
});
 
server.listen(2466, function () {
  console.log(`Listening on ${server.address().port}`);
});

io.on('connection', function(socket){
	socket.emit("connected", {id: socket.id, hash: hash.sha512().update("testHash").digest('hex')});
	socket.emit("newMap", mapObjects);

	socket.on("newLine", function(map) {
		map.forEach(function(obj) {
			mapObjects.push(obj);
		});

		socket.broadcast.emit("newMap", mapObjects);
	});
});
node v10.16.0