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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. resolve();
  132. });
  133. });
  134. }
  135. /**
  136. *
  137. */
  138. hide() {
  139. const $iframe = $(this.iframe);
  140. const $container = $(this.container);
  141. document.body.style.background = this.bodyBackground;
  142. return new Promise(resolve => {
  143. $iframe.fadeOut(300, () => {
  144. $iframe.css({ visibility: 'hidden' });
  145. $container.css({ zIndex: 0 });
  146. resolve();
  147. });
  148. });
  149. }
  150. /**
  151. * @return {boolean} do not switch on dominant speaker event if on stage.
  152. */
  153. stayOnStage() {
  154. return true;
  155. }
  156. }
  157. /**
  158. * Manager of the Etherpad frame.
  159. */
  160. export default class EtherpadManager {
  161. /**
  162. *
  163. */
  164. constructor(domain, name, eventEmitter) {
  165. if (!domain || !name) {
  166. throw new Error('missing domain or name');
  167. }
  168. this.domain = domain;
  169. this.name = name;
  170. this.eventEmitter = eventEmitter;
  171. this.etherpad = null;
  172. }
  173. /**
  174. *
  175. */
  176. get isOpen() {
  177. return Boolean(this.etherpad);
  178. }
  179. /**
  180. *
  181. */
  182. isVisible() {
  183. return VideoLayout.isLargeContainerTypeVisible(ETHERPAD_CONTAINER_TYPE);
  184. }
  185. /**
  186. * Create new Etherpad frame.
  187. */
  188. openEtherpad() {
  189. this.etherpad = new Etherpad(this.domain, this.name);
  190. VideoLayout.addLargeVideoContainer(
  191. ETHERPAD_CONTAINER_TYPE,
  192. this.etherpad
  193. );
  194. }
  195. /**
  196. * Toggle Etherpad frame visibility.
  197. * Open new Etherpad frame if there is no Etherpad frame yet.
  198. */
  199. toggleEtherpad() {
  200. if (!this.isOpen) {
  201. this.openEtherpad();
  202. }
  203. const isVisible = this.isVisible();
  204. VideoLayout.showLargeVideoContainer(
  205. ETHERPAD_CONTAINER_TYPE, !isVisible);
  206. this.eventEmitter
  207. .emit(UIEvents.TOGGLED_SHARED_DOCUMENT, !isVisible);
  208. APP.store.dispatch(setDocumentEditingState(!isVisible));
  209. }
  210. }