Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. /* global $, APP */
  2. /* jshint -W101 */
  3. import VideoLayout from "../videolayout/VideoLayout";
  4. import LargeContainer from '../videolayout/LargeContainer';
  5. import PreziPlayer from './PreziPlayer';
  6. import UIUtil from '../util/UIUtil';
  7. import UIEvents from '../../../service/UI/UIEvents';
  8. import messageHandler from '../util/MessageHandler';
  9. import ToolbarToggler from "../toolbars/ToolbarToggler";
  10. import SidePanelToggler from "../side_pannels/SidePanelToggler";
  11. import BottomToolbar from '../toolbars/BottomToolbar';
  12. const defaultPreziLink = "http://prezi.com/wz7vhjycl7e6/my-prezi";
  13. const alphanumRegex = /^[a-z0-9-_\/&\?=;]+$/i;
  14. const aspectRatio = 16.0 / 9.0;
  15. const DEFAULT_WIDTH = 640;
  16. const DEFAULT_HEIGHT = 480;
  17. /**
  18. * Indicates if the given string is an alphanumeric string.
  19. * Note that some special characters are also allowed (-, _ , /, &, ?, =, ;) for the
  20. * purpose of checking URIs.
  21. */
  22. function isAlphanumeric(unsafeText) {
  23. return alphanumRegex.test(unsafeText);
  24. }
  25. /**
  26. * Returns the presentation id from the given url.
  27. */
  28. function getPresentationId (url) {
  29. let presId = url.substring(url.indexOf("prezi.com/") + 10);
  30. return presId.substring(0, presId.indexOf('/'));
  31. }
  32. function isPreziLink(url) {
  33. if (url.indexOf('http://prezi.com/') !== 0 && url.indexOf('https://prezi.com/') !== 0) {
  34. return false;
  35. }
  36. let presId = url.substring(url.indexOf("prezi.com/") + 10);
  37. if (!isAlphanumeric(presId) || presId.indexOf('/') < 2) {
  38. return false;
  39. }
  40. return true;
  41. }
  42. function notifyOtherIsSharingPrezi() {
  43. messageHandler.openMessageDialog(
  44. "dialog.sharePreziTitle",
  45. "dialog.sharePreziMsg"
  46. );
  47. }
  48. function proposeToClosePrezi() {
  49. return new Promise(function (resolve, reject) {
  50. messageHandler.openTwoButtonDialog(
  51. "dialog.removePreziTitle",
  52. null,
  53. "dialog.removePreziMsg",
  54. null,
  55. false,
  56. "dialog.Remove",
  57. function(e,v,m,f) {
  58. if (v) {
  59. resolve();
  60. } else {
  61. reject();
  62. }
  63. }
  64. );
  65. });
  66. }
  67. function requestPreziLink() {
  68. const title = APP.translation.generateTranslationHTML("dialog.sharePreziTitle");
  69. const cancelButton = APP.translation.generateTranslationHTML("dialog.Cancel");
  70. const shareButton = APP.translation.generateTranslationHTML("dialog.Share");
  71. const backButton = APP.translation.generateTranslationHTML("dialog.Back");
  72. const linkError = APP.translation.generateTranslationHTML("dialog.preziLinkError");
  73. const i18nOptions = {url: defaultPreziLink};
  74. const defaultUrl = APP.translation.translateString(
  75. "defaultPreziLink", i18nOptions
  76. );
  77. return new Promise(function (resolve, reject) {
  78. let dialog = messageHandler.openDialogWithStates({
  79. state0: {
  80. html: `
  81. <h2>${title}</h2>
  82. <input name="preziUrl" type="text"
  83. data-i18n="[placeholder]defaultPreziLink"
  84. data-i18n-options="${JSON.stringify(i18nOptions)}"
  85. placeholder="${defaultUrl}" autofocus>`,
  86. persistent: false,
  87. buttons: [
  88. {title: cancelButton, value: false},
  89. {title: shareButton, value: true}
  90. ],
  91. focus: ':input:first',
  92. defaultButton: 1,
  93. submit: function (e, v, m, f) {
  94. e.preventDefault();
  95. if (!v) {
  96. reject('cancelled');
  97. dialog.close();
  98. return;
  99. }
  100. let preziUrl = f.preziUrl;
  101. if (!preziUrl) {
  102. return;
  103. }
  104. let urlValue = encodeURI(UIUtil.escapeHtml(preziUrl));
  105. if (!isPreziLink(urlValue)) {
  106. dialog.goToState('state1');
  107. return false;
  108. }
  109. resolve(urlValue);
  110. dialog.close();
  111. }
  112. },
  113. state1: {
  114. html: `<h2>${title}</h2> ${linkError}`,
  115. persistent: false,
  116. buttons: [
  117. {title: cancelButton, value: false},
  118. {title: backButton, value: true}
  119. ],
  120. focus: ':input:first',
  121. defaultButton: 1,
  122. submit: function (e, v, m, f) {
  123. e.preventDefault();
  124. if (v === 0) {
  125. reject();
  126. dialog.close();
  127. } else {
  128. dialog.goToState('state0');
  129. }
  130. }
  131. }
  132. });
  133. });
  134. }
  135. export const PreziContainerType = "prezi";
  136. class PreziContainer extends LargeContainer {
  137. constructor ({preziId, isMy, slide, onSlideChanged}) {
  138. super();
  139. this.reloadBtn = $('#reloadPresentation');
  140. let preziPlayer = new PreziPlayer(
  141. 'presentation', {
  142. preziId,
  143. width: DEFAULT_WIDTH,
  144. height: DEFAULT_HEIGHT,
  145. controls: isMy,
  146. debug: true
  147. }
  148. );
  149. this.preziPlayer = preziPlayer;
  150. this.$iframe = $(preziPlayer.iframe);
  151. this.$iframe.attr('id', preziId);
  152. preziPlayer.on(PreziPlayer.EVENT_STATUS, function({value}) {
  153. console.log("prezi status", value);
  154. if (value == PreziPlayer.STATUS_CONTENT_READY && !isMy) {
  155. preziPlayer.flyToStep(slide);
  156. }
  157. });
  158. preziPlayer.on(PreziPlayer.EVENT_CURRENT_STEP, function({value}) {
  159. console.log("event value", value);
  160. onSlideChanged(value);
  161. });
  162. }
  163. goToSlide (slide) {
  164. if (this.preziPlayer.getCurrentStep() === slide) {
  165. return;
  166. }
  167. this.preziPlayer.flyToStep(slide);
  168. let animationStepsArray = this.preziPlayer.getAnimationCountOnSteps();
  169. if (!animationStepsArray) {
  170. return;
  171. }
  172. for (var i = 0; i < parseInt(animationStepsArray[slide]); i += 1) {
  173. this.preziPlayer.flyToStep(slide, i);
  174. }
  175. }
  176. showReloadBtn (show) {
  177. this.reloadBtn.css('display', show ? 'inline-block' : 'none');
  178. }
  179. show () {
  180. return new Promise(resolve => {
  181. this.$iframe.fadeIn(300, () => {
  182. this.$iframe.css({opacity: 1});
  183. ToolbarToggler.dockToolbar(true);
  184. resolve();
  185. });
  186. });
  187. }
  188. hide () {
  189. return new Promise(resolve => {
  190. this.$iframe.fadeOut(300, () => {
  191. this.$iframe.css({opacity: 0});
  192. this.showReloadBtn(false);
  193. ToolbarToggler.dockToolbar(false);
  194. resolve();
  195. });
  196. });
  197. }
  198. onHoverIn () {
  199. let rightOffset = window.innerWidth - this.$iframe.offset().left - this.$iframe.width();
  200. this.showReloadBtn(true);
  201. this.reloadBtn.css('right', rightOffset);
  202. }
  203. onHoverOut (event) {
  204. let e = event.toElement || event.relatedTarget;
  205. if (e && e.id != 'reloadPresentation' && e.id != 'header') {
  206. this.showReloadBtn(false);
  207. }
  208. }
  209. resize (containerWidth, containerHeight) {
  210. let height = containerHeight - BottomToolbar.getFilmStripHeight();
  211. let width = containerWidth;
  212. if (height < width / aspectRatio) {
  213. width = Math.floor(height * aspectRatio);
  214. }
  215. this.$iframe.width(width).height(height);
  216. }
  217. close () {
  218. this.showReloadBtn(false);
  219. this.preziPlayer.destroy();
  220. this.$iframe.remove();
  221. }
  222. }
  223. export default class PreziManager {
  224. constructor (emitter) {
  225. this.emitter = emitter;
  226. this.userId = null;
  227. this.url = null;
  228. this.prezi = null;
  229. $("#reloadPresentationLink").click(this.reloadPresentation.bind(this));
  230. }
  231. get isPresenting () {
  232. return !!this.userId;
  233. }
  234. get isMyPrezi () {
  235. return this.userId === APP.conference.localId;
  236. }
  237. isSharing (id) {
  238. return this.userId === id;
  239. }
  240. handlePreziButtonClicked () {
  241. if (!this.isPresenting) {
  242. requestPreziLink().then(
  243. url => this.emitter.emit(UIEvents.SHARE_PREZI, url, 0),
  244. err => console.error('PREZI CANCELED', err)
  245. );
  246. return;
  247. }
  248. if (this.isMyPrezi) {
  249. proposeToClosePrezi().then(() => this.emitter.emit(UIEvents.STOP_SHARING_PREZI));
  250. } else {
  251. notifyOtherIsSharingPrezi();
  252. }
  253. }
  254. reloadPresentation () {
  255. if (!this.prezi) {
  256. return;
  257. }
  258. let iframe = this.prezi.$iframe[0];
  259. iframe.src = iframe.src;
  260. }
  261. showPrezi (id, url, slide) {
  262. if (!this.isPresenting) {
  263. this.createPrezi(id, url, slide);
  264. }
  265. if (this.userId === id && this.url === url) {
  266. this.prezi.goToSlide(slide);
  267. } else {
  268. console.error(this.userId, id);
  269. console.error(this.url, url);
  270. throw new Error("unexpected presentation change");
  271. }
  272. }
  273. createPrezi (id, url, slide) {
  274. console.log("presentation added", url);
  275. this.userId = id;
  276. this.url = url;
  277. let preziId = getPresentationId(url);
  278. let elementId = `participant_${id}_${preziId}`;
  279. this.$thumb = $(VideoLayout.addRemoteVideoContainer(elementId));
  280. VideoLayout.resizeThumbnails();
  281. this.$thumb.css({
  282. 'background-image': 'url(../images/avatarprezi.png)'
  283. }).click(() => VideoLayout.showLargeVideoContainer(PreziContainerType, true));
  284. this.prezi = new PreziContainer({
  285. preziId,
  286. isMy: this.isMyPrezi,
  287. slide,
  288. onSlideChanged: newSlide => {
  289. if (this.isMyPrezi) {
  290. this.emitter.emit(UIEvents.SHARE_PREZI, url, newSlide);
  291. }
  292. }
  293. });
  294. VideoLayout.addLargeVideoContainer(PreziContainerType, this.prezi);
  295. VideoLayout.showLargeVideoContainer(PreziContainerType, true);
  296. }
  297. removePrezi (id) {
  298. if (this.userId !== id) {
  299. throw new Error(`cannot close presentation from ${this.userId} instead of ${id}`);
  300. }
  301. this.$thumb.remove();
  302. this.$thumb = null;
  303. // wait until Prezi is hidden, then remove it
  304. VideoLayout.showLargeVideoContainer(PreziContainerType, false).then(() => {
  305. console.log("presentation removed", this.url);
  306. VideoLayout.removeLargeVideoContainer(PreziContainerType);
  307. this.userId = null;
  308. this.url = null;
  309. this.prezi.close();
  310. this.prezi = null;
  311. });
  312. }
  313. }