Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

Etherpad.js 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /* global APP, interfaceConfig */
  2. import $ from 'jquery';
  3. import { setDocumentEditingState } from '../../../react/features/etherpad/actions';
  4. import { getSharedDocumentUrl } from '../../../react/features/etherpad/functions';
  5. import { getToolboxHeight } from '../../../react/features/toolbox/functions.web';
  6. import Filmstrip from '../videolayout/Filmstrip';
  7. import LargeContainer from '../videolayout/LargeContainer';
  8. import VideoLayout from '../videolayout/VideoLayout';
  9. /**
  10. * Default Etherpad frame width.
  11. */
  12. const DEFAULT_WIDTH = 640;
  13. /**
  14. * Default Etherpad frame height.
  15. */
  16. const DEFAULT_HEIGHT = 480;
  17. const ETHERPAD_CONTAINER_TYPE = 'etherpad';
  18. /**
  19. * Container for Etherpad iframe.
  20. */
  21. class Etherpad extends LargeContainer {
  22. /**
  23. * Creates new Etherpad object
  24. */
  25. constructor(url) {
  26. super();
  27. const iframe = document.createElement('iframe');
  28. iframe.id = 'etherpadIFrame';
  29. iframe.src = url;
  30. iframe.style.border = 0;
  31. iframe.scrolling = 'no';
  32. iframe.width = DEFAULT_WIDTH;
  33. iframe.height = DEFAULT_HEIGHT;
  34. iframe.setAttribute('style', 'visibility: hidden;');
  35. this.container.appendChild(iframe);
  36. this.iframe = iframe;
  37. }
  38. /**
  39. *
  40. */
  41. get isOpen() {
  42. return Boolean(this.iframe);
  43. }
  44. /**
  45. *
  46. */
  47. get container() {
  48. return document.getElementById('etherpad');
  49. }
  50. /**
  51. *
  52. */
  53. resize(containerWidth, containerHeight) {
  54. let height, width;
  55. if (interfaceConfig.VERTICAL_FILMSTRIP) {
  56. height = containerHeight - getToolboxHeight();
  57. width = containerWidth - Filmstrip.getVerticalFilmstripWidth();
  58. } else {
  59. height = containerHeight - Filmstrip.getFilmstripHeight();
  60. width = containerWidth;
  61. }
  62. $(this.iframe)
  63. .width(width)
  64. .height(height);
  65. }
  66. /**
  67. *
  68. */
  69. show() {
  70. const $iframe = $(this.iframe);
  71. const $container = $(this.container);
  72. const self = this;
  73. return new Promise(resolve => {
  74. $iframe.fadeIn(300, () => {
  75. self.bodyBackground = document.body.style.background;
  76. document.body.style.background = '#eeeeee';
  77. $iframe.css({ visibility: 'visible' });
  78. $container.css({ zIndex: 2 });
  79. APP.store.dispatch(setDocumentEditingState(true));
  80. resolve();
  81. });
  82. });
  83. }
  84. /**
  85. *
  86. */
  87. hide() {
  88. const $iframe = $(this.iframe);
  89. const $container = $(this.container);
  90. document.body.style.background = this.bodyBackground;
  91. return new Promise(resolve => {
  92. $iframe.fadeOut(300, () => {
  93. $iframe.css({ visibility: 'hidden' });
  94. $container.css({ zIndex: 0 });
  95. APP.store.dispatch(setDocumentEditingState(false));
  96. resolve();
  97. });
  98. });
  99. }
  100. /**
  101. * @return {boolean} do not switch on dominant speaker event if on stage.
  102. */
  103. stayOnStage() {
  104. return true;
  105. }
  106. }
  107. /**
  108. * Manager of the Etherpad frame.
  109. */
  110. export default class EtherpadManager {
  111. /**
  112. *
  113. */
  114. constructor(eventEmitter) {
  115. this.eventEmitter = eventEmitter;
  116. this.etherpad = null;
  117. }
  118. /**
  119. *
  120. */
  121. get isOpen() {
  122. return Boolean(this.etherpad);
  123. }
  124. /**
  125. *
  126. */
  127. isVisible() {
  128. return VideoLayout.isLargeContainerTypeVisible(ETHERPAD_CONTAINER_TYPE);
  129. }
  130. /**
  131. * Create new Etherpad frame.
  132. */
  133. openEtherpad() {
  134. this.etherpad = new Etherpad(getSharedDocumentUrl(APP.store.getState));
  135. VideoLayout.addLargeVideoContainer(
  136. ETHERPAD_CONTAINER_TYPE,
  137. this.etherpad
  138. );
  139. }
  140. /**
  141. * Toggle Etherpad frame visibility.
  142. * Open new Etherpad frame if there is no Etherpad frame yet.
  143. */
  144. toggleEtherpad() {
  145. if (!this.isOpen) {
  146. this.openEtherpad();
  147. }
  148. const isVisible = this.isVisible();
  149. VideoLayout.showLargeVideoContainer(
  150. ETHERPAD_CONTAINER_TYPE, !isVisible);
  151. APP.store.dispatch(setDocumentEditingState(!isVisible));
  152. }
  153. }