Browse Source

yay

master
mort 8 years ago
parent
commit
a2bbb1feb0
2 changed files with 32 additions and 22 deletions
  1. 4
    4
      index.html
  2. 28
    18
      server.js

+ 4
- 4
index.html View File

@@ -26,6 +26,7 @@
position: absolute;
top: 6px;
right: 6px;
backgrounud: white;
display: none;
}
#_msg.active {
@@ -70,6 +71,9 @@
._content img.fullscreen {
width: auto;
}
._content img.fullscreen.stretch {
width: 100%;
}

#_overlay {
transition: opacity <<transition_time>>s;
@@ -88,11 +92,7 @@
<!-- Fetch polyfill -->
<script src="/polyfills.js"></script>

<!-- Handle reloading -->
<script>
</script>
<script>

(function fullscreen() {
var elem = document.body;
var rFS = elem.requestFullScreen ||

+ 28
- 18
server.js View File

@@ -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);

Loading…
Cancel
Save