-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
66 lines (47 loc) · 1.32 KB
/
server.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* CodeX Meetup server-side application
*
* @uses express, socket.io
* @since 17.17.02
* @author CodeX Team https://ifmo.su
*/
var express = require('express');
var app = express();
var server = require('http').Server(app); // create server
var io = require('socket.io')(server); // create socket.io instance
var PORT = 3000;
/**
* Express js
*/
/** Start web server port listening */
server.listen(PORT, function(){
console.log('Listening ' + PORT + '...');
});
/** Express's route for index page */
app.get('/', function( request , response ){
response.sendFile( __dirname + '/index.html');
});
/**
* Route for delivering static files (JS, CSS, images)
* @see http://expressjs.com/en/starter/static-files.html
*/
app.use('/public', express.static('public'));
/**
* Socket.io
*/
/**
* Web socket connection's handler
* @param {Socket} socket - web-socket object
*/
io.on('connection', function( socket ){
/**
* 'user moved' message handler
* @param {object} data passed with emit-event from client-side
* contains user's {id, photo, x, y}
*/
socket.on('user moved', function( data ){
console.log('user moved', data);
/** Say to all others connected sockets about someones moved */
socket.broadcast.emit('someone moved', data);
});
});