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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /* global $ */
  2. import VideoLayout from "../videolayout/VideoLayout";
  3. import LargeContainer from '../videolayout/LargeContainer';
  4. import UIUtil from "../util/UIUtil";
  5. import SidePanelToggler from "../side_pannels/SidePanelToggler";
  6. const options = $.param({
  7. showControns: true,
  8. showChat: false,
  9. showLineNumbers: true,
  10. useMonospaceFont: false
  11. });
  12. function bubbleIframeMouseMove(iframe){
  13. var existingOnMouseMove = iframe.contentWindow.onmousemove;
  14. iframe.contentWindow.onmousemove = function(e){
  15. if(existingOnMouseMove) existingOnMouseMove(e);
  16. var evt = document.createEvent("MouseEvents");
  17. var boundingClientRect = iframe.getBoundingClientRect();
  18. evt.initMouseEvent(
  19. "mousemove",
  20. true, // bubbles
  21. false, // not cancelable
  22. window,
  23. e.detail,
  24. e.screenX,
  25. e.screenY,
  26. e.clientX + boundingClientRect.left,
  27. e.clientY + boundingClientRect.top,
  28. e.ctrlKey,
  29. e.altKey,
  30. e.shiftKey,
  31. e.metaKey,
  32. e.button,
  33. null // no related element
  34. );
  35. iframe.dispatchEvent(evt);
  36. };
  37. }
  38. const DEFAULT_WIDTH = 640;
  39. const DEFAULT_HEIGHT = 480;
  40. const EtherpadContainerType = "etherpad";
  41. class Etherpad extends LargeContainer {
  42. constructor (domain, name) {
  43. super();
  44. const iframe = document.createElement('iframe');
  45. iframe.src = domain + name + '?' + options;
  46. iframe.frameBorder = 0;
  47. iframe.scrolling = "no";
  48. iframe.width = DEFAULT_WIDTH;
  49. iframe.height = DEFAULT_HEIGHT;
  50. iframe.setAttribute('style', 'visibility: hidden;');
  51. this.container.appendChild(iframe);
  52. iframe.onload = function() {
  53. document.domain = document.domain;
  54. bubbleIframeMouseMove(iframe);
  55. setTimeout(function() {
  56. const doc = iframe.contentDocument;
  57. // the iframes inside of the etherpad are
  58. // not yet loaded when the etherpad iframe is loaded
  59. const outer = doc.getElementsByName("ace_outer")[0];
  60. bubbleIframeMouseMove(outer);
  61. const inner = doc.getElementsByName("ace_inner")[0];
  62. bubbleIframeMouseMove(inner);
  63. }, 2000);
  64. };
  65. this.iframe = iframe;
  66. }
  67. get isOpen () {
  68. return !!this.iframe;
  69. }
  70. get container () {
  71. return document.getElementById('etherpad');
  72. }
  73. resize (containerWidth, containerHeight, animate) {
  74. let remoteVideos = $('#remoteVideos');
  75. let height = containerHeight - remoteVideos.outerHeight();
  76. let width = containerWidth;
  77. $(this.iframe).width(width).height(height);
  78. }
  79. show () {
  80. const $iframe = $(this.iframe);
  81. const $container = $(this.container);
  82. return new Promise(resolve => {
  83. $iframe.fadeIn(300, function () {
  84. document.body.style.background = '#eeeeee';
  85. $iframe.css({visibility: 'visible'});
  86. $container.css({zIndex: 2});
  87. resolve();
  88. });
  89. });
  90. }
  91. hide () {
  92. const $iframe = $(this.iframe);
  93. const $container = $(this.container);
  94. return new Promise(resolve => {
  95. $iframe.fadeOut(300, function () {
  96. $iframe.css({visibility: 'hidden'});
  97. $container.css({zIndex: 0});
  98. resolve();
  99. });
  100. });
  101. }
  102. }
  103. export default class EtherpadManager {
  104. constructor (domain, name) {
  105. if (!domain || !name) {
  106. throw new Error("missing domain or name");
  107. }
  108. this.domain = domain;
  109. this.name = name;
  110. this.etherpad = null;
  111. }
  112. get isOpen () {
  113. return !!this.etherpad;
  114. }
  115. openEtherpad () {
  116. this.etherpad = new Etherpad(this.domain, this.name);
  117. VideoLayout.addLargeVideoContainer(
  118. EtherpadContainerType,
  119. this.etherpad
  120. );
  121. }
  122. toggleEtherpad () {
  123. if (!this.isOpen) {
  124. this.openEtherpad();
  125. }
  126. let isVisible = VideoLayout.isLargeContainerTypeVisible(
  127. EtherpadContainerType
  128. );
  129. VideoLayout.showLargeVideoContainer(EtherpadContainerType, !isVisible);
  130. }
  131. }