-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
62 lines (52 loc) · 1.7 KB
/
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
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
var http = require('http');
var websocket = require('websocket').server;
var fs = require('fs');
var path = require('path');
var count = 0;
var clients = {};
var audienceSync = http.createServer(function(req, res) {});
audienceSync.listen(2723);
ws = new websocket({
httpServer: audienceSync
});
var presenter = http.createServer(function(req, res) {
console.log(req.url + ' = url');
var page = parseInt(req.url.substr(1));
if ( typeof page == 'number' ) {
console.log('request for page ' + page + ' received');
// SEND PAGE TO PRESENTER
res.writeHead(200, {"Content-Type": "text/html"});
//res.end('' + page + '\n');
var filePath = path.join(__dirname, '' + page + '.html');
fs.readFile(filePath, {encoding: 'utf-8'}, function(err, data) {
if ( !err ) {
res.writeHead(200, {"Content-Type": "text/html"});
res.write(data);
res.end();
}
else { console.log(err); }
});
// SEND CURRENT PAGE TO AUDIENCE
for ( ii in clients ) {
clients[ii].sendUTF('' + page);
}
}
});
presenter.listen(9147);
var audienceNotes = http.createServer(function(req, res) {
var filePath = path.join(__dirname, 'audienceNotes.html');
fs.readFile(filePath, {encoding: 'utf-8'}, function(err, data) {
if ( !err ) {
res.writeHead(200, {"Content-Type": "text/html"});
res.write(data);
res.end();
}
else { console.log(err); }
});
});
audienceNotes.listen(2000);
ws.on('request', function(request) {
var conn = request.accept('echo-protocol', request.origin);
var id = count++;
clients[id] = conn;
});