Skip to content

Instantly share code, notes, and snippets.

@ghtomcat
Created July 17, 2012 12:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ghtomcat/3129198 to your computer and use it in GitHub Desktop.
Save ghtomcat/3129198 to your computer and use it in GitHub Desktop.
node.js server for EnyoSlides
var io = require('socket.io').listen(8080);
console.log("listening on port 8080");
// Socket Routes
io.sockets.on('connection', function (socket) {
socket.on('setPresenter', function(){
socket.set('presenter', true, function(){
socket.emit('ready');
});
});
socket.on('slideChanged', function(slideIndex){
socket.get('presenter', function(err, isPresenter){
if(isPresenter){
io.sockets['in']('viewers').emit('changeSlide', slideIndex);
}
});
});
socket.on('joinViewer', function(){
socket.join('viewers');
});
socket.on('leaveViewer', function(){
socket.leave('viewers');
});
socket.on('newQuestion', function(question){
if(question.name && question.question){
question.name = question.name.trim();
question.question = question.question.trim();
socket.emit('updateQuestions', question);
socket.broadcast.emit('updateQuestions', question);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment