-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
45 lines (35 loc) · 1.22 KB
/
app.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
// Including libraries
var app = require('http').createServer(handler),
io = require('socket.io').listen(app),
static = require('node-static'); // for serving files
// This will make all the files in the current folder
// accessible from the web
var fileServer = new static.Server('./');
// This is the port for our web server.
var port = process.env.PORT || 8080;
app.listen(port, function(){
console.log("Listening on port "+port);
});
// If the URL of the socket server is opened in a browser
function handler (request, response) {
request.addListener('end', function () {
fileServer.serve(request, response);
});
}
// config required for heroku
io.configure(function () {
io.set("transports", ["xhr-polling"]);
io.set("polling duration", 10);
});
// Listen for incoming connections from clients
io.sockets.on('connection', function (socket) {
// Start listening for mouse move events
socket.on('mousemove', function (data) {
// This line sends the event (broadcasts it)
// to everyone except the originating client.
socket.broadcast.emit('moving', data);
});
socket.on('textEntry', function(data){
socket.broadcast.emit('writeText', data);
});
});