-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebtocanvas.js
42 lines (33 loc) · 1.34 KB
/
webtocanvas.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
/*
* This Codebase is a mess :)
* Most of the mess is from Alexander 'Pfannkuchensack' Eichhorn
* Thanks for the great npm packages: tetris-engine, gamepad, serialport, cli-color
* In use Arduino Uno + 384 WS2812B. Communication wokrs over Serial. RPi/Laptop -> usb -> Uno
*/
// 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('./static');
// This is the port for our web server.
// you will need to go to http://localhost:8080 to see it
app.listen(8080);
// If the URL of the socket server is opened in a browser
function handler (request, response) {
request.addListener('end', function () {
fileServer.serve(request, response); // this will return the correct file
});
}
// Delete this row if you want to see debug messages
//io.set('log level', 1);
// 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);
});
});