You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /* global $, config,
  2. setLargeVideoVisible, Util */
  3. var VideoLayout = require("../videolayout/VideoLayout");
  4. var Prezi = require("../prezi/Prezi");
  5. var UIUtil = require("../util/UIUtil");
  6. var etherpadName = null;
  7. var etherpadIFrame = null;
  8. var domain = null;
  9. var options = "?showControls=true&showChat=false&showLineNumbers=true&useMonospaceFont=false";
  10. /**
  11. * Resizes the etherpad.
  12. */
  13. function resize() {
  14. if ($('#etherpad>iframe').length) {
  15. var remoteVideos = $('#remoteVideos');
  16. var availableHeight
  17. = window.innerHeight - remoteVideos.outerHeight();
  18. var availableWidth = UIUtil.getAvailableVideoWidth();
  19. $('#etherpad>iframe').width(availableWidth);
  20. $('#etherpad>iframe').height(availableHeight);
  21. }
  22. }
  23. /**
  24. * Shares the Etherpad name with other participants.
  25. */
  26. function shareEtherpad() {
  27. APP.xmpp.addToPresence("etherpad", etherpadName);
  28. }
  29. /**
  30. * Creates the Etherpad button and adds it to the toolbar.
  31. */
  32. function enableEtherpadButton() {
  33. if (!$('#etherpadButton').is(":visible"))
  34. $('#etherpadButton').css({display: 'inline-block'});
  35. }
  36. /**
  37. * Creates the IFrame for the etherpad.
  38. */
  39. function createIFrame() {
  40. etherpadIFrame = document.createElement('iframe');
  41. etherpadIFrame.src = domain + etherpadName + options;
  42. etherpadIFrame.frameBorder = 0;
  43. etherpadIFrame.scrolling = "no";
  44. etherpadIFrame.width = $('#largeVideoContainer').width() || 640;
  45. etherpadIFrame.height = $('#largeVideoContainer').height() || 480;
  46. etherpadIFrame.setAttribute('style', 'visibility: hidden;');
  47. document.getElementById('etherpad').appendChild(etherpadIFrame);
  48. etherpadIFrame.onload = function() {
  49. document.domain = document.domain;
  50. bubbleIframeMouseMove(etherpadIFrame);
  51. setTimeout(function() {
  52. // the iframes inside of the etherpad are
  53. // not yet loaded when the etherpad iframe is loaded
  54. var outer = etherpadIFrame.
  55. contentDocument.getElementsByName("ace_outer")[0];
  56. bubbleIframeMouseMove(outer);
  57. var inner = outer.
  58. contentDocument.getElementsByName("ace_inner")[0];
  59. bubbleIframeMouseMove(inner);
  60. }, 2000);
  61. };
  62. }
  63. function bubbleIframeMouseMove(iframe){
  64. var existingOnMouseMove = iframe.contentWindow.onmousemove;
  65. iframe.contentWindow.onmousemove = function(e){
  66. if(existingOnMouseMove) existingOnMouseMove(e);
  67. var evt = document.createEvent("MouseEvents");
  68. var boundingClientRect = iframe.getBoundingClientRect();
  69. evt.initMouseEvent(
  70. "mousemove",
  71. true, // bubbles
  72. false, // not cancelable
  73. window,
  74. e.detail,
  75. e.screenX,
  76. e.screenY,
  77. e.clientX + boundingClientRect.left,
  78. e.clientY + boundingClientRect.top,
  79. e.ctrlKey,
  80. e.altKey,
  81. e.shiftKey,
  82. e.metaKey,
  83. e.button,
  84. null // no related element
  85. );
  86. iframe.dispatchEvent(evt);
  87. };
  88. }
  89. /**
  90. * On video selected event.
  91. */
  92. $(document).bind('video.selected', function (event, isPresentation) {
  93. if (config.etherpad_base && etherpadIFrame && etherpadIFrame.style.visibility !== 'hidden')
  94. Etherpad.toggleEtherpad(isPresentation);
  95. });
  96. var Etherpad = {
  97. /**
  98. * Initializes the etherpad.
  99. */
  100. init: function (name) {
  101. if (config.etherpad_base && !etherpadName) {
  102. domain = config.etherpad_base;
  103. if (!name) {
  104. // In case we're the focus we generate the name.
  105. etherpadName = Math.random().toString(36).substring(7) +
  106. '_' + (new Date().getTime()).toString();
  107. shareEtherpad();
  108. }
  109. else
  110. etherpadName = name;
  111. enableEtherpadButton();
  112. /**
  113. * Resizes the etherpad, when the window is resized.
  114. */
  115. $(window).resize(function () {
  116. resize();
  117. });
  118. }
  119. },
  120. /**
  121. * Opens/hides the Etherpad.
  122. */
  123. toggleEtherpad: function (isPresentation) {
  124. if (!etherpadIFrame)
  125. createIFrame();
  126. var largeVideo = null;
  127. if (Prezi.isPresentationVisible())
  128. largeVideo = $('#presentation>iframe');
  129. else
  130. largeVideo = $('#largeVideo');
  131. if ($('#etherpad>iframe').css('visibility') === 'hidden') {
  132. $('#activeSpeaker').css('visibility', 'hidden');
  133. largeVideo.fadeOut(300, function () {
  134. if (Prezi.isPresentationVisible()) {
  135. largeVideo.css({opacity: '0'});
  136. } else {
  137. VideoLayout.setLargeVideoVisible(false);
  138. }
  139. });
  140. $('#etherpad>iframe').fadeIn(300, function () {
  141. document.body.style.background = '#eeeeee';
  142. $('#etherpad>iframe').css({visibility: 'visible'});
  143. $('#etherpad').css({zIndex: 2});
  144. });
  145. }
  146. else if ($('#etherpad>iframe')) {
  147. $('#etherpad>iframe').fadeOut(300, function () {
  148. $('#etherpad>iframe').css({visibility: 'hidden'});
  149. $('#etherpad').css({zIndex: 0});
  150. document.body.style.background = 'black';
  151. });
  152. if (!isPresentation) {
  153. $('#largeVideo').fadeIn(300, function () {
  154. VideoLayout.setLargeVideoVisible(true);
  155. });
  156. }
  157. }
  158. resize();
  159. },
  160. isVisible: function() {
  161. var etherpadIframe = $('#etherpad>iframe');
  162. return etherpadIframe && etherpadIframe.is(':visible');
  163. }
  164. };
  165. module.exports = Etherpad;