|
|
@@ -103,6 +103,8 @@ function Slideshow(dir, changeInterval) { |
|
|
|
var currentSlide = null; |
|
|
|
var awaiters = []; |
|
|
|
var slides = []; |
|
|
|
var slideIndex = 0; |
|
|
|
var nextTimeout; |
|
|
|
|
|
|
|
self.sendEvent = function(evt, args) { |
|
|
|
var str = JSON.stringify({ evt: evt, args: args }); |
|
|
@@ -156,6 +158,25 @@ function Slideshow(dir, changeInterval) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
function next() { |
|
|
|
slideIndex += 1; |
|
|
|
|
|
|
|
// Go to the next slide, or restart |
|
|
|
if ((slideIndex >= slides.length) |
|
|
|
|| (!slides[slideIndex].dirExists())) { |
|
|
|
clearTimeout(nextTimeout); |
|
|
|
init(); |
|
|
|
} else { |
|
|
|
currentSlide = slides[slideIndex]; |
|
|
|
nextTimeout = setTimeout(next, changeInterval); |
|
|
|
} |
|
|
|
|
|
|
|
// End all awaiting connections to notify slide change |
|
|
|
self.sendEvent("next", { name: currentSlide.name }); |
|
|
|
} |
|
|
|
|
|
|
|
self.next = next; |
|
|
|
|
|
|
|
// This function starts the slideshow and goes through the slides |
|
|
|
// one by one. When done, it starts again by calling this function again. |
|
|
|
function init() { |
|
|
@@ -163,24 +184,10 @@ function Slideshow(dir, changeInterval) { |
|
|
|
.sort() |
|
|
|
.map(file => Slide(pathlib.join(dir, file))); |
|
|
|
|
|
|
|
var slideIndex = 0; |
|
|
|
slideIndex = 0; |
|
|
|
currentSlide = slides[slideIndex]; |
|
|
|
|
|
|
|
var interval = setInterval(() => { |
|
|
|
slideIndex += 1; |
|
|
|
|
|
|
|
// Go to the next slide, or restart |
|
|
|
if ((slideIndex >= slides.length) |
|
|
|
|| (!slides[slideIndex].dirExists())) { |
|
|
|
clearInterval(interval); |
|
|
|
init(); |
|
|
|
} else { |
|
|
|
currentSlide = slides[slideIndex]; |
|
|
|
} |
|
|
|
|
|
|
|
// End all awaiting connections to notify slide change |
|
|
|
self.sendEvent("next", { name: currentSlide.name }); |
|
|
|
}, changeInterval); |
|
|
|
nextTimeout = setTimeout(next, changeInterval); |
|
|
|
} |
|
|
|
init(); |
|
|
|
|
|
|
@@ -189,7 +196,8 @@ function Slideshow(dir, changeInterval) { |
|
|
|
|
|
|
|
var slideshow = Slideshow(conf.slides, conf.interval); |
|
|
|
|
|
|
|
function onexit() { |
|
|
|
function onexit(code) { |
|
|
|
console.log("exiting", code); |
|
|
|
slideshow.sendEvent("reload"); |
|
|
|
process.exit(); |
|
|
|
} |
|
|
@@ -197,11 +205,13 @@ process.on("exit", onexit); |
|
|
|
process.on("SIGINT", onexit); |
|
|
|
process.on("SIGTERM", onexit); |
|
|
|
|
|
|
|
process.on("uncaughtException", onexit); |
|
|
|
|
|
|
|
var server = http.createServer((req, res) => { |
|
|
|
slideshow.serve(req, res); |
|
|
|
}); |
|
|
|
server.on("error", err => { |
|
|
|
console.error(err.toString()); |
|
|
|
console.error(err); |
|
|
|
system.exit(1); |
|
|
|
}); |
|
|
|
server.listen(conf.port); |