-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
57 lines (47 loc) · 1.55 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
var express = require('express');
var mustache = require('mustache-express');
var favicon = require('serve-favicon');
var app = express();
var path = require('path');
var http = require('http').Server(app);
var port = process.env.PORT || 4000;
var rtcPort = 4001;
var io = require('socket.io')(http);
var bodyParser = require('body-parser');
var webRTC = require('webrtc.io').listen(rtcPort);
// express setup
app.use(express.static(path.join(__dirname, '/public')));
app.use(favicon(path.join(__dirname,'public','images','favicon.ico')));
app.use(bodyParser.json()); // to support JSON-encoded bodies
app.use(bodyParser.urlencoded({ extended: true })); // to support URL-encoded bodies
// mustache-express templating engine
app.engine('html', mustache());
app.set('view engine', 'html');
app.set('views', path.join(__dirname, '/public/views'));
/*** routing ***/
// enable cross-origin requests
app.all ('*', function (req, res, next) {
res.header ('Access-Control-Allow-Origin', '*');
res.header ('Access-Control-Allow-Headers', 'X-Requested-With');
next();
});
app.get('/', function (req, res) {
res.render('projector.html');
});
/*** server ***/
http.listen(port, function(error) {
if (error) {
return console.log("ERROR: ", error);
}
console.log('node on: ' + port);
console.log('rtc on: ' + rtcPort);
});
/*** socket actions ***/
io.on('connection', function(socket) {
socket.on('draw', function(data) {
io.emit('draw', data);
});
socket.on('greeting', function(data) {
io.emit('greeting', data);
});
});