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.

Prezi.js 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. var ToolbarToggler = require("../toolbars/ToolbarToggler");
  2. var UIUtil = require("../util/UIUtil");
  3. var VideoLayout = require("../videolayout/VideoLayout");
  4. var messageHandler = require("../util/MessageHandler");
  5. var preziPlayer = null;
  6. var Prezi = {
  7. /**
  8. * Reloads the current presentation.
  9. */
  10. reloadPresentation: function() {
  11. var iframe = document.getElementById(preziPlayer.options.preziId);
  12. iframe.src = iframe.src;
  13. },
  14. /**
  15. * Returns <tt>true</tt> if the presentation is visible, <tt>false</tt> -
  16. * otherwise.
  17. */
  18. isPresentationVisible: function () {
  19. return ($('#presentation>iframe') != null
  20. && $('#presentation>iframe').css('opacity') == 1);
  21. },
  22. /**
  23. * Opens the Prezi dialog, from which the user could choose a presentation
  24. * to load.
  25. */
  26. openPreziDialog: function() {
  27. var myprezi = connection.emuc.getPrezi(connection.emuc.myroomjid);
  28. if (myprezi) {
  29. messageHandler.openTwoButtonDialog("Remove Prezi",
  30. "Are you sure you would like to remove your Prezi?",
  31. false,
  32. "Remove",
  33. function(e,v,m,f) {
  34. if(v) {
  35. connection.emuc.removePreziFromPresence();
  36. connection.emuc.sendPresence();
  37. }
  38. }
  39. );
  40. }
  41. else if (preziPlayer != null) {
  42. messageHandler.openTwoButtonDialog("Share a Prezi",
  43. "Another participant is already sharing a Prezi." +
  44. "This conference allows only one Prezi at a time.",
  45. false,
  46. "Ok",
  47. function(e,v,m,f) {
  48. $.prompt.close();
  49. }
  50. );
  51. }
  52. else {
  53. var openPreziState = {
  54. state0: {
  55. html: '<h2>Share a Prezi</h2>' +
  56. '<input id="preziUrl" type="text" ' +
  57. 'placeholder="e.g. ' +
  58. 'http://prezi.com/wz7vhjycl7e6/my-prezi" autofocus>',
  59. persistent: false,
  60. buttons: { "Share": true , "Cancel": false},
  61. defaultButton: 1,
  62. submit: function(e,v,m,f){
  63. e.preventDefault();
  64. if(v)
  65. {
  66. var preziUrl = document.getElementById('preziUrl');
  67. if (preziUrl.value)
  68. {
  69. var urlValue
  70. = encodeURI(Util.escapeHtml(preziUrl.value));
  71. if (urlValue.indexOf('http://prezi.com/') != 0
  72. && urlValue.indexOf('https://prezi.com/') != 0)
  73. {
  74. $.prompt.goToState('state1');
  75. return false;
  76. }
  77. else {
  78. var presIdTmp = urlValue.substring(
  79. urlValue.indexOf("prezi.com/") + 10);
  80. if (!isAlphanumeric(presIdTmp)
  81. || presIdTmp.indexOf('/') < 2) {
  82. $.prompt.goToState('state1');
  83. return false;
  84. }
  85. else {
  86. connection.emuc
  87. .addPreziToPresence(urlValue, 0);
  88. connection.emuc.sendPresence();
  89. $.prompt.close();
  90. }
  91. }
  92. }
  93. }
  94. else
  95. $.prompt.close();
  96. }
  97. },
  98. state1: {
  99. html: '<h2>Share a Prezi</h2>' +
  100. 'Please provide a correct prezi link.',
  101. persistent: false,
  102. buttons: { "Back": true, "Cancel": false },
  103. defaultButton: 1,
  104. submit:function(e,v,m,f) {
  105. e.preventDefault();
  106. if(v==0)
  107. $.prompt.close();
  108. else
  109. $.prompt.goToState('state0');
  110. }
  111. }
  112. };
  113. var focusPreziUrl = function(e) {
  114. document.getElementById('preziUrl').focus();
  115. };
  116. messageHandler.openDialogWithStates(openPreziState, focusPreziUrl, focusPreziUrl);
  117. }
  118. }
  119. };
  120. /**
  121. * A new presentation has been added.
  122. *
  123. * @param event the event indicating the add of a presentation
  124. * @param jid the jid from which the presentation was added
  125. * @param presUrl url of the presentation
  126. * @param currentSlide the current slide to which we should move
  127. */
  128. function presentationAdded(event, jid, presUrl, currentSlide) {
  129. console.log("presentation added", presUrl);
  130. var presId = getPresentationId(presUrl);
  131. var elementId = 'participant_'
  132. + Strophe.getResourceFromJid(jid)
  133. + '_' + presId;
  134. // We explicitly don't specify the peer jid here, because we don't want
  135. // this video to be dealt with as a peer related one (for example we
  136. // don't want to show a mute/kick menu for this one, etc.).
  137. VideoLayout.addRemoteVideoContainer(null, elementId);
  138. VideoLayout.resizeThumbnails();
  139. var controlsEnabled = false;
  140. if (jid === connection.emuc.myroomjid)
  141. controlsEnabled = true;
  142. setPresentationVisible(true);
  143. $('#largeVideoContainer').hover(
  144. function (event) {
  145. if (Prezi.isPresentationVisible()) {
  146. var reloadButtonRight = window.innerWidth
  147. - $('#presentation>iframe').offset().left
  148. - $('#presentation>iframe').width();
  149. $('#reloadPresentation').css({ right: reloadButtonRight,
  150. display:'inline-block'});
  151. }
  152. },
  153. function (event) {
  154. if (!Prezi.isPresentationVisible())
  155. $('#reloadPresentation').css({display:'none'});
  156. else {
  157. var e = event.toElement || event.relatedTarget;
  158. if (e && e.id != 'reloadPresentation' && e.id != 'header')
  159. $('#reloadPresentation').css({display:'none'});
  160. }
  161. });
  162. preziPlayer = new PreziPlayer(
  163. 'presentation',
  164. {preziId: presId,
  165. width: getPresentationWidth(),
  166. height: getPresentationHeihgt(),
  167. controls: controlsEnabled,
  168. debug: true
  169. });
  170. $('#presentation>iframe').attr('id', preziPlayer.options.preziId);
  171. preziPlayer.on(PreziPlayer.EVENT_STATUS, function(event) {
  172. console.log("prezi status", event.value);
  173. if (event.value == PreziPlayer.STATUS_CONTENT_READY) {
  174. if (jid != connection.emuc.myroomjid)
  175. preziPlayer.flyToStep(currentSlide);
  176. }
  177. });
  178. preziPlayer.on(PreziPlayer.EVENT_CURRENT_STEP, function(event) {
  179. console.log("event value", event.value);
  180. connection.emuc.addCurrentSlideToPresence(event.value);
  181. connection.emuc.sendPresence();
  182. });
  183. $("#" + elementId).css( 'background-image',
  184. 'url(../images/avatarprezi.png)');
  185. $("#" + elementId).click(
  186. function () {
  187. setPresentationVisible(true);
  188. }
  189. );
  190. };
  191. /**
  192. * A presentation has been removed.
  193. *
  194. * @param event the event indicating the remove of a presentation
  195. * @param jid the jid for which the presentation was removed
  196. * @param the url of the presentation
  197. */
  198. function presentationRemoved(event, jid, presUrl) {
  199. console.log('presentation removed', presUrl);
  200. var presId = getPresentationId(presUrl);
  201. setPresentationVisible(false);
  202. $('#participant_'
  203. + Strophe.getResourceFromJid(jid)
  204. + '_' + presId).remove();
  205. $('#presentation>iframe').remove();
  206. if (preziPlayer != null) {
  207. preziPlayer.destroy();
  208. preziPlayer = null;
  209. }
  210. };
  211. /**
  212. * Indicates if the given string is an alphanumeric string.
  213. * Note that some special characters are also allowed (-, _ , /, &, ?, =, ;) for the
  214. * purpose of checking URIs.
  215. */
  216. function isAlphanumeric(unsafeText) {
  217. var regex = /^[a-z0-9-_\/&\?=;]+$/i;
  218. return regex.test(unsafeText);
  219. }
  220. /**
  221. * Returns the presentation id from the given url.
  222. */
  223. function getPresentationId (presUrl) {
  224. var presIdTmp = presUrl.substring(presUrl.indexOf("prezi.com/") + 10);
  225. return presIdTmp.substring(0, presIdTmp.indexOf('/'));
  226. }
  227. /**
  228. * Returns the presentation width.
  229. */
  230. function getPresentationWidth() {
  231. var availableWidth = UIUtil.getAvailableVideoWidth();
  232. var availableHeight = getPresentationHeihgt();
  233. var aspectRatio = 16.0 / 9.0;
  234. if (availableHeight < availableWidth / aspectRatio) {
  235. availableWidth = Math.floor(availableHeight * aspectRatio);
  236. }
  237. return availableWidth;
  238. }
  239. /**
  240. * Returns the presentation height.
  241. */
  242. function getPresentationHeihgt() {
  243. var remoteVideos = $('#remoteVideos');
  244. return window.innerHeight - remoteVideos.outerHeight();
  245. }
  246. /**
  247. * Resizes the presentation iframe.
  248. */
  249. function resize() {
  250. if ($('#presentation>iframe')) {
  251. $('#presentation>iframe').width(getPresentationWidth());
  252. $('#presentation>iframe').height(getPresentationHeihgt());
  253. }
  254. }
  255. /**
  256. * Shows/hides a presentation.
  257. */
  258. function setPresentationVisible(visible) {
  259. var prezi = $('#presentation>iframe');
  260. if (visible) {
  261. // Trigger the video.selected event to indicate a change in the
  262. // large video.
  263. $(document).trigger("video.selected", [true]);
  264. $('#largeVideo').fadeOut(300);
  265. prezi.fadeIn(300, function() {
  266. prezi.css({opacity:'1'});
  267. ToolbarToggler.dockToolbar(true);
  268. VideoLayout.setLargeVideoVisible(false);
  269. });
  270. $('#activeSpeaker').css('visibility', 'hidden');
  271. }
  272. else {
  273. if (prezi.css('opacity') == '1') {
  274. prezi.fadeOut(300, function () {
  275. prezi.css({opacity:'0'});
  276. $('#reloadPresentation').css({display:'none'});
  277. $('#largeVideo').fadeIn(300, function() {
  278. VideoLayout.setLargeVideoVisible(true);
  279. ToolbarToggler.dockToolbar(false);
  280. });
  281. });
  282. }
  283. }
  284. }
  285. /**
  286. * Presentation has been removed.
  287. */
  288. $(document).bind('presentationremoved.muc', presentationRemoved);
  289. /**
  290. * Presentation has been added.
  291. */
  292. $(document).bind('presentationadded.muc', presentationAdded);
  293. /*
  294. * Indicates presentation slide change.
  295. */
  296. $(document).bind('gotoslide.muc', function (event, jid, presUrl, current) {
  297. if (preziPlayer && preziPlayer.getCurrentStep() != current) {
  298. preziPlayer.flyToStep(current);
  299. var animationStepsArray = preziPlayer.getAnimationCountOnSteps();
  300. for (var i = 0; i < parseInt(animationStepsArray[current]); i++) {
  301. preziPlayer.flyToStep(current, i);
  302. }
  303. }
  304. });
  305. /**
  306. * On video selected event.
  307. */
  308. $(document).bind('video.selected', function (event, isPresentation) {
  309. if (!isPresentation && $('#presentation>iframe')) {
  310. setPresentationVisible(false);
  311. }
  312. });
  313. $(window).resize(function () {
  314. resize();
  315. });
  316. module.exports = Prezi;