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.

Etherpad.js 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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 Filmstrip from '../videolayout/Filmstrip';
  7. /**
  8. * Etherpad options.
  9. */
  10. const options = $.param({
  11. showControls: true,
  12. showChat: false,
  13. showLineNumbers: true,
  14. useMonospaceFont: false
  15. });
  16. /**
  17. *
  18. */
  19. function bubbleIframeMouseMove(iframe) {
  20. const existingOnMouseMove = iframe.contentWindow.onmousemove;
  21. iframe.contentWindow.onmousemove = function(e) {
  22. if (existingOnMouseMove) {
  23. existingOnMouseMove(e);
  24. }
  25. const evt = document.createEvent('MouseEvents');
  26. const boundingClientRect = iframe.getBoundingClientRect();
  27. evt.initMouseEvent(
  28. 'mousemove',
  29. true, // bubbles
  30. false, // not cancelable
  31. window,
  32. e.detail,
  33. e.screenX,
  34. e.screenY,
  35. e.clientX + boundingClientRect.left,
  36. e.clientY + boundingClientRect.top,
  37. e.ctrlKey,
  38. e.altKey,
  39. e.shiftKey,
  40. e.metaKey,
  41. e.button,
  42. null // no related element
  43. );
  44. iframe.dispatchEvent(evt);
  45. };
  46. }
  47. /**
  48. * Default Etherpad frame width.
  49. */
  50. const DEFAULT_WIDTH = 640;
  51. /**
  52. * Default Etherpad frame height.
  53. */
  54. const DEFAULT_HEIGHT = 480;
  55. const ETHERPAD_CONTAINER_TYPE = 'etherpad';
  56. /**
  57. * Container for Etherpad iframe.
  58. */
  59. class Etherpad extends LargeContainer {
  60. /**
  61. * Creates new Etherpad object
  62. */
  63. constructor(domain, name) {
  64. super();
  65. const iframe = document.createElement('iframe');
  66. iframe.id = 'etherpadIFrame';
  67. iframe.src = `${domain + name}?${options}`;
  68. iframe.frameBorder = 0;
  69. iframe.scrolling = 'no';
  70. iframe.width = DEFAULT_WIDTH;
  71. iframe.height = DEFAULT_HEIGHT;
  72. iframe.setAttribute('style', 'visibility: hidden;');
  73. this.container.appendChild(iframe);
  74. iframe.onload = function() {
  75. // eslint-disable-next-line no-self-assign
  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. APP.store.dispatch(setDocumentEditingState(!isVisible));
  209. }
  210. }