Add remote.js to workshop template and pub/sub server

This commit is contained in:
Jerome Petazzoni
2017-12-21 04:51:49 +01:00
parent 270c36b29a
commit ec7b46b779
3 changed files with 36 additions and 1 deletions

View File

@@ -0,0 +1,21 @@
/* This snippet is loaded from the workshop HTML file.
* It sets up callbacks to synchronize the local slide
* number with the remote pub/sub server.
*/
var socket = io();
var leader = true;
slideshow.on('showSlide', function (slide) {
if (leader) {
var n = slide.getSlideIndex()+1;
socket.emit('slide change', n);
}
});
socket.on('slide change', function (n) {
leader = false;
slideshow.gotoSlide(n);
leader = true;
});

View File

@@ -19,7 +19,10 @@ app.get('/', function(req, res){
res.send('container.training autopilot pub/sub server');
});
/* Serve slides etc. from the parent directory */
/* Serve remote.js from the current directory */
app.use(express.static('.'));
/* Serve slides etc. from current and the parent directory */
app.use(express.static('..'));
io.on('connection', function(socket){

View File

@@ -31,5 +31,16 @@
excludedClasses: [@@EXCLUDE@@]
});
</script>
<!--
These two scripts will be available only when loading the
content using the pub/sub server. Otherwise, they'll just
404 and that's OK.
-->
<script src="/socket.io/socket.io.js">
</script>
<script src="/remote.js">
</script>
</body>
</html>