/
run.js
executable file
·72 lines (58 loc) · 2.13 KB
/
run.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
65
66
67
68
69
70
71
72
#!/usr/bin/env node
/* Copyright 2013 Bodil Stokke <bodil@bodil.org>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
var fs = require("fs");
var path = require("path");
var express = require("express");
var unirepl = require("./plugin/repl/unirepl");
var app = express(),
server = require("http").createServer(app),
io = require("socket.io").listen(server);
io.set("log level", 1);
io.of("/notes")
.on('connection', function(socket) {
socket.on('slidechanged', function(slideData) {
socket.broadcast.emit('slidedata', slideData);
});
socket.on('fragmentchanged', function(fragmentData) {
socket.broadcast.emit('fragmentdata', fragmentData);
});
});
io.of("/repl")
.on("connection", function(socket) {
socket.on("eval", function(e, cb) {
unirepl.run(e, function(err, res) {
cb({error: err, result: res});
});
});
});
app.configure(function() {
['m', 'css', 'js', 'images', 'plugin', 'lib'].forEach(function(dir) {
app.use('/' + dir, express.static(path.join(__dirname, dir)));
});
});
app.get("/", function(req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
fs.createReadStream(path.join(__dirname, 'index.html')).pipe(res);
});
app.get("/notes/:socketId", function(req, res) {
fs.readFile(path.join(__dirname, 'plugin/notes-server/notes.html'),
function(err, data) {
res.send(require("mustache").to_html(data.toString(), {
socketId: req.params.socketId
}));
});
});
server.listen(1337);
var brown = '\033[33m',
green = '\033[32m',
reset = '\033[0m';
var slidesLocation = "http://localhost:1337/";
console.log( brown + "reveal.js - Speaker Notes" + reset );
console.log( "1. Open the slides at " + green + slidesLocation + reset );
console.log( "2. Click on the link your JS console to go to the notes page" );
console.log( "3. Advance through your slides and your notes will advance automatically" );
server.listen(1337);