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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /* global $ */
  2. import VideoLayout from "../videolayout/VideoLayout";
  3. import LargeContainer from '../videolayout/LargeContainer';
  4. import UIUtil from "../util/UIUtil";
  5. import UIEvents from "../../../service/UI/UIEvents";
  6. import FilmStrip from '../videolayout/FilmStrip';
  7. /**
  8. * Etherpad options.
  9. */
  10. const options = $.param({
  11. showControns: true,
  12. showChat: false,
  13. showLineNumbers: true,
  14. useMonospaceFont: false
  15. });
  16. function bubbleIframeMouseMove(iframe){
  17. var existingOnMouseMove = iframe.contentWindow.onmousemove;
  18. iframe.contentWindow.onmousemove = function(e){
  19. if(existingOnMouseMove) existingOnMouseMove(e);
  20. var evt = document.createEvent("MouseEvents");
  21. var boundingClientRect = iframe.getBoundingClientRect();
  22. evt.initMouseEvent(
  23. "mousemove",
  24. true, // bubbles
  25. false, // not cancelable
  26. window,
  27. e.detail,
  28. e.screenX,
  29. e.screenY,
  30. e.clientX + boundingClientRect.left,
  31. e.clientY + boundingClientRect.top,
  32. e.ctrlKey,
  33. e.altKey,
  34. e.shiftKey,
  35. e.metaKey,
  36. e.button,
  37. null // no related element
  38. );
  39. iframe.dispatchEvent(evt);
  40. };
  41. }
  42. /**
  43. * Default Etherpad frame width.
  44. */
  45. const DEFAULT_WIDTH = 640;
  46. /**
  47. * Default Etherpad frame height.
  48. */
  49. const DEFAULT_HEIGHT = 480;
  50. const ETHERPAD_CONTAINER_TYPE = "etherpad";
  51. /**
  52. * Container for Etherpad iframe.
  53. */
  54. class Etherpad extends LargeContainer {
  55. constructor (domain, name) {
  56. super();
  57. const iframe = document.createElement('iframe');
  58. iframe.src = domain + name + '?' + options;
  59. iframe.frameBorder = 0;
  60. iframe.scrolling = "no";
  61. iframe.width = DEFAULT_WIDTH;
  62. iframe.height = DEFAULT_HEIGHT;
  63. iframe.setAttribute('style', 'visibility: hidden;');
  64. this.container.appendChild(iframe);
  65. iframe.onload = function() {
  66. document.domain = document.domain;
  67. bubbleIframeMouseMove(iframe);
  68. setTimeout(function() {
  69. const doc = iframe.contentDocument;
  70. // the iframes inside of the etherpad are
  71. // not yet loaded when the etherpad iframe is loaded
  72. const outer = doc.getElementsByName("ace_outer")[0];
  73. bubbleIframeMouseMove(outer);
  74. const inner = doc.getElementsByName("ace_inner")[0];
  75. bubbleIframeMouseMove(inner);
  76. }, 2000);
  77. };
  78. this.iframe = iframe;
  79. }
  80. get isOpen () {
  81. return !!this.iframe;
  82. }
  83. get container () {
  84. return document.getElementById('etherpad');
  85. }
  86. resize (containerWidth, containerHeight, animate) {
  87. let height = containerHeight - FilmStrip.getFilmStripHeight();
  88. let width = containerWidth;
  89. $(this.iframe).width(width).height(height);
  90. }
  91. show () {
  92. const $iframe = $(this.iframe);
  93. const $container = $(this.container);
  94. let self = this;
  95. return new Promise(resolve => {
  96. $iframe.fadeIn(300, function () {
  97. self.bodyBackground = document.body.style.background;
  98. document.body.style.background = '#eeeeee';
  99. $iframe.css({visibility: 'visible'});
  100. $container.css({zIndex: 2});
  101. resolve();
  102. });
  103. });
  104. }
  105. hide () {
  106. const $iframe = $(this.iframe);
  107. const $container = $(this.container);
  108. document.body.style.background = this.bodyBackground;
  109. return new Promise(resolve => {
  110. $iframe.fadeOut(300, function () {
  111. $iframe.css({visibility: 'hidden'});
  112. $container.css({zIndex: 0});
  113. resolve();
  114. });
  115. });
  116. }
  117. /**
  118. * @return {boolean} do not switch on dominant speaker event if on stage.
  119. */
  120. stayOnStage () {
  121. return true;
  122. }
  123. }
  124. /**
  125. * Manager of the Etherpad frame.
  126. */
  127. export default class EtherpadManager {
  128. constructor (domain, name, eventEmitter) {
  129. if (!domain || !name) {
  130. throw new Error("missing domain or name");
  131. }
  132. this.domain = domain;
  133. this.name = name;
  134. this.eventEmitter = eventEmitter;
  135. this.etherpad = null;
  136. }
  137. get isOpen () {
  138. return !!this.etherpad;
  139. }
  140. isVisible() {
  141. return VideoLayout.isLargeContainerTypeVisible(ETHERPAD_CONTAINER_TYPE);
  142. }
  143. /**
  144. * Create new Etherpad frame.
  145. */
  146. openEtherpad () {
  147. this.etherpad = new Etherpad(this.domain, this.name);
  148. VideoLayout.addLargeVideoContainer(
  149. ETHERPAD_CONTAINER_TYPE,
  150. this.etherpad
  151. );
  152. }
  153. /**
  154. * Toggle Etherpad frame visibility.
  155. * Open new Etherpad frame if there is no Etherpad frame yet.
  156. */
  157. toggleEtherpad () {
  158. if (!this.isOpen) {
  159. this.openEtherpad();
  160. }
  161. let isVisible = this.isVisible();
  162. VideoLayout.showLargeVideoContainer(
  163. ETHERPAD_CONTAINER_TYPE, !isVisible);
  164. this.eventEmitter
  165. .emit(UIEvents.TOGGLED_SHARED_DOCUMENT, !isVisible);
  166. }
  167. }