controldeck-slides.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. var messageHandler;
  2. if (typeof jQuery === 'undefined') jQuery = {};
  3. // detect HTML5 slideshow type, set message handler
  4. if (typeof jQuery.deck !== 'undefined') messageHandler = updateDeckJS;
  5. else if (typeof Reveal !== 'undefined') messageHandler = updateReveal;
  6. else if (typeof impress !== 'undefined') messageHandler = updateImpress;
  7. else if (typeof jQuery.jmpress !== 'undefined') messageHandler = updateJmpress;
  8. else if (typeof jQuery.scrolldeck !== 'undefined') messageHandler = updateScrollDeck;
  9. else if (typeof Flowtime !== 'undefined') messageHandler = updateFlowtime;
  10. else messageHandler = updateGeneric;
  11. // separated in case we want to differentiate in the future
  12. function updateDeckJS(message) {
  13. console.log('updateDeckJS '+message);
  14. var e = jQuery.Event('keydown');
  15. e.which = parseInt(message,10);
  16. $(document).trigger(e);
  17. }
  18. function updateReveal(message) {
  19. console.log('updateReveal '+message);
  20. if (message === '37') Reveal.navigateLeft();
  21. else if (message === '38') Reveal.navigateUp();
  22. else if (message === '39') Reveal.navigateRight();
  23. else if (message === '40') Reveal.navigateDown();
  24. else if (message === '27') Reveal.toggleOverview();
  25. else if (message === 'goto:0') Reveal.slide(0,0);
  26. }
  27. function updateImpress(message) {
  28. console.log('updateImpress '+message);
  29. if (message === '37') impress().prev();
  30. else if (message === '39') impress().next();
  31. else if (message.indexOf('goto') !== -1) {
  32. if (message === 'goto:0') impress().goto(0);
  33. else impress().goto(message.replace('goto:',''));
  34. }
  35. }
  36. function updateJmpress(message) {
  37. console.log('updateJmpress '+message);
  38. var e = jQuery.Event('keydown');
  39. e.which = e.keyCode = parseInt(message,10);
  40. $(document).trigger(e);
  41. }
  42. function updateScrollDeck(message) {
  43. console.log('updateScrollDeck '+message);
  44. var e = jQuery.Event('keydown');
  45. e.which = e.keyCode = parseInt(message,10);
  46. $(document).trigger(e);
  47. }
  48. function updateGeneric(message) {
  49. console.log('updateGeneric '+message);
  50. var e = jQuery.Event('keydown');
  51. e.which = e.keyCode = parseInt(message,10);
  52. $(document).trigger(e);
  53. }
  54. var iosocket = io.connect();
  55. iosocket.on('connect', function () {
  56. console.log('connected');
  57. });
  58. iosocket.on('message', function(message) {
  59. messageHandler(message);
  60. });
  61. iosocket.on('key down', function(data) {
  62. messageHandler("" +data.keyCode, data.shiftKey, data.altKey, data.ctrlKey, data.metaKey);
  63. });
  64. iosocket.on('key up', function(data) {
  65. messageHandler("" + data.keyCode, data.shiftKey, data.altKey, data.ctrlKey, data.metaKey);
  66. });
  67. iosocket.on('disconnect', function() {
  68. console.log('disconnected');
  69. });