您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Etherpad.js 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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 = interfaceConfig._USE_NEW_TOOLBOX
  109. ? containerHeight - getToolboxHeight() : containerHeight;
  110. width = containerWidth - Filmstrip.getFilmstripWidth();
  111. } else {
  112. height = containerHeight - Filmstrip.getFilmstripHeight();
  113. width = containerWidth;
  114. }
  115. $(this.iframe)
  116. .width(width)
  117. .height(height);
  118. }
  119. /**
  120. *
  121. */
  122. show() {
  123. const $iframe = $(this.iframe);
  124. const $container = $(this.container);
  125. const self = this;
  126. return new Promise(resolve => {
  127. $iframe.fadeIn(300, () => {
  128. self.bodyBackground = document.body.style.background;
  129. document.body.style.background = '#eeeeee';
  130. $iframe.css({ visibility: 'visible' });
  131. $container.css({ zIndex: 2 });
  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. resolve();
  148. });
  149. });
  150. }
  151. /**
  152. * @return {boolean} do not switch on dominant speaker event if on stage.
  153. */
  154. stayOnStage() {
  155. return true;
  156. }
  157. }
  158. /**
  159. * Manager of the Etherpad frame.
  160. */
  161. export default class EtherpadManager {
  162. /**
  163. *
  164. */
  165. constructor(domain, name, eventEmitter) {
  166. if (!domain || !name) {
  167. throw new Error('missing domain or name');
  168. }
  169. this.domain = domain;
  170. this.name = name;
  171. this.eventEmitter = eventEmitter;
  172. this.etherpad = null;
  173. }
  174. /**
  175. *
  176. */
  177. get isOpen() {
  178. return Boolean(this.etherpad);
  179. }
  180. /**
  181. *
  182. */
  183. isVisible() {
  184. return VideoLayout.isLargeContainerTypeVisible(ETHERPAD_CONTAINER_TYPE);
  185. }
  186. /**
  187. * Create new Etherpad frame.
  188. */
  189. openEtherpad() {
  190. this.etherpad = new Etherpad(this.domain, this.name);
  191. VideoLayout.addLargeVideoContainer(
  192. ETHERPAD_CONTAINER_TYPE,
  193. this.etherpad
  194. );
  195. }
  196. /**
  197. * Toggle Etherpad frame visibility.
  198. * Open new Etherpad frame if there is no Etherpad frame yet.
  199. */
  200. toggleEtherpad() {
  201. if (!this.isOpen) {
  202. this.openEtherpad();
  203. }
  204. const isVisible = this.isVisible();
  205. VideoLayout.showLargeVideoContainer(
  206. ETHERPAD_CONTAINER_TYPE, !isVisible);
  207. this.eventEmitter
  208. .emit(UIEvents.TOGGLED_SHARED_DOCUMENT, !isVisible);
  209. APP.store.dispatch(setDocumentEditingState(!isVisible));
  210. }
  211. }