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.

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