Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

Toolbar.js 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  1. /* global APP, $, buttonClick, config, lockRoom, interfaceConfig, setSharedKey,
  2. Util */
  3. var messageHandler = require("../util/MessageHandler");
  4. var BottomToolbar = require("./BottomToolbar");
  5. var Prezi = require("../prezi/Prezi");
  6. var Etherpad = require("../etherpad/Etherpad");
  7. var PanelToggler = require("../side_pannels/SidePanelToggler");
  8. var Authentication = require("../authentication/Authentication");
  9. var UIUtil = require("../util/UIUtil");
  10. var AuthenticationEvents
  11. = require("../../../service/authentication/AuthenticationEvents");
  12. var roomUrl = null;
  13. var sharedKey = '';
  14. var UI = null;
  15. var buttonHandlers = {
  16. "toolbar_button_mute": function () {
  17. return APP.UI.toggleAudio();
  18. },
  19. "toolbar_button_camera": function () {
  20. return APP.UI.toggleVideo();
  21. },
  22. /*"toolbar_button_authentication": function () {
  23. return Toolbar.authenticateClicked();
  24. },*/
  25. "toolbar_button_record": function () {
  26. return toggleRecording();
  27. },
  28. "toolbar_button_security": function () {
  29. return Toolbar.openLockDialog();
  30. },
  31. "toolbar_button_link": function () {
  32. return Toolbar.openLinkDialog();
  33. },
  34. "toolbar_button_chat": function () {
  35. return BottomToolbar.toggleChat();
  36. },
  37. "toolbar_button_prezi": function () {
  38. return Prezi.openPreziDialog();
  39. },
  40. "toolbar_button_etherpad": function () {
  41. return Etherpad.toggleEtherpad(0);
  42. },
  43. "toolbar_button_desktopsharing": function () {
  44. return APP.desktopsharing.toggleScreenSharing();
  45. },
  46. "toolbar_button_fullScreen": function() {
  47. UIUtil.buttonClick("#fullScreen", "icon-full-screen icon-exit-full-screen");
  48. return Toolbar.toggleFullScreen();
  49. },
  50. "toolbar_button_sip": function () {
  51. return callSipButtonClicked();
  52. },
  53. "toolbar_button_dialpad": function () {
  54. return dialpadButtonClicked();
  55. },
  56. "toolbar_button_settings": function () {
  57. PanelToggler.toggleSettingsMenu();
  58. },
  59. "toolbar_button_hangup": function () {
  60. return hangup();
  61. },
  62. "toolbar_button_login": function () {
  63. Toolbar.authenticateClicked();
  64. },
  65. "toolbar_button_logout": function () {
  66. // Ask for confirmation
  67. messageHandler.openTwoButtonDialog(
  68. "dialog.logoutTitle",
  69. null,
  70. "dialog.logoutQuestion",
  71. null,
  72. false,
  73. "dialog.Yes",
  74. function (evt, yes) {
  75. if (yes) {
  76. APP.xmpp.logout(function (url) {
  77. if (url) {
  78. window.location.href = url;
  79. } else {
  80. hangup();
  81. }
  82. });
  83. }
  84. });
  85. }
  86. };
  87. function hangup() {
  88. APP.xmpp.disposeConference();
  89. if(config.enableWelcomePage) {
  90. setTimeout(function() {
  91. window.localStorage.welcomePageDisabled = false;
  92. window.location.pathname = "/";
  93. }, 10000);
  94. }
  95. var title = APP.translation.generateTranslationHTML(
  96. "dialog.sessTerminated");
  97. var msg = APP.translation.generateTranslationHTML(
  98. "dialog.hungUp");
  99. var button = APP.translation.generateTranslationHTML(
  100. "dialog.joinAgain");
  101. var buttons = [];
  102. buttons.push({title: button, value: true});
  103. UI.messageHandler.openDialog(
  104. title,
  105. msg,
  106. true,
  107. buttons,
  108. function(event, value, message, formVals) {
  109. window.location.reload();
  110. return false;
  111. }
  112. );
  113. }
  114. /**
  115. * Starts or stops the recording for the conference.
  116. */
  117. function toggleRecording() {
  118. APP.xmpp.toggleRecording(function (callback) {
  119. var msg = APP.translation.generateTranslationHTML(
  120. "dialog.recordingToken");
  121. var token = APP.translation.translateString("dialog.token");
  122. APP.UI.messageHandler.openTwoButtonDialog(null, null, null,
  123. '<h2>' + msg + '</h2>' +
  124. '<input name="recordingToken" type="text" ' +
  125. ' data-i18n="[placeholder]dialog.token" ' +
  126. 'placeholder="' + token + '" autofocus>',
  127. false,
  128. "dialog.Save",
  129. function (e, v, m, f) {
  130. if (v) {
  131. var token = f.recordingToken;
  132. if (token) {
  133. callback(UIUtil.escapeHtml(token));
  134. }
  135. }
  136. },
  137. null,
  138. function () { },
  139. ':input:first'
  140. );
  141. }, Toolbar.setRecordingButtonState, Toolbar.setRecordingButtonState);
  142. }
  143. /**
  144. * Locks / unlocks the room.
  145. */
  146. function lockRoom(lock) {
  147. var currentSharedKey = '';
  148. if (lock)
  149. currentSharedKey = sharedKey;
  150. APP.xmpp.lockRoom(currentSharedKey, function (res) {
  151. // password is required
  152. if (sharedKey) {
  153. console.log('set room password');
  154. Toolbar.lockLockButton();
  155. }
  156. else {
  157. console.log('removed room password');
  158. Toolbar.unlockLockButton();
  159. }
  160. }, function (err) {
  161. console.warn('setting password failed', err);
  162. messageHandler.showError("dialog.lockTitle",
  163. "dialog.lockMessage");
  164. Toolbar.setSharedKey('');
  165. }, function () {
  166. console.warn('room passwords not supported');
  167. messageHandler.showError("dialog.warning",
  168. "dialog.passwordNotSupported");
  169. Toolbar.setSharedKey('');
  170. });
  171. }
  172. /**
  173. * Invite participants to conference.
  174. */
  175. function inviteParticipants() {
  176. if (roomUrl === null)
  177. return;
  178. var sharedKeyText = "";
  179. if (sharedKey && sharedKey.length > 0) {
  180. sharedKeyText =
  181. APP.translation.translateString("email.sharedKey",
  182. {sharedKey: sharedKey});
  183. sharedKeyText = sharedKeyText.replace(/\n/g, "%0D%0A");
  184. }
  185. var supportedBrowsers = "Chromium, Google Chrome " +
  186. APP.translation.translateString("email.and") + " Opera";
  187. var conferenceName = roomUrl.substring(roomUrl.lastIndexOf('/') + 1);
  188. var subject = APP.translation.translateString("email.subject",
  189. {appName:interfaceConfig.APP_NAME, conferenceName: conferenceName});
  190. var body = APP.translation.translateString("email.body",
  191. {appName:interfaceConfig.APP_NAME, sharedKeyText: sharedKeyText,
  192. roomUrl: roomUrl, supportedBrowsers: supportedBrowsers});
  193. body = body.replace(/\n/g, "%0D%0A");
  194. if (window.localStorage.displayname) {
  195. body += "%0D%0A%0D%0A" + window.localStorage.displayname;
  196. }
  197. if (interfaceConfig.INVITATION_POWERED_BY) {
  198. body += "%0D%0A%0D%0A--%0D%0Apowered by jitsi.org";
  199. }
  200. window.open("mailto:?subject=" + subject + "&body=" + body, '_blank');
  201. }
  202. function dialpadButtonClicked() {
  203. //TODO show the dialpad box
  204. }
  205. function callSipButtonClicked() {
  206. var defaultNumber
  207. = config.defaultSipNumber ? config.defaultSipNumber : '';
  208. var sipMsg = APP.translation.generateTranslationHTML(
  209. "dialog.sipMsg");
  210. messageHandler.openTwoButtonDialog(null, null, null,
  211. '<h2>' + sipMsg + '</h2>' +
  212. '<input name="sipNumber" type="text"' +
  213. ' value="' + defaultNumber + '" autofocus>',
  214. false,
  215. "dialog.Dial",
  216. function (e, v, m, f) {
  217. if (v) {
  218. var numberInput = f.sipNumber;
  219. if (numberInput) {
  220. APP.xmpp.dial(
  221. numberInput, 'fromnumber', UI.getRoomName(), sharedKey);
  222. }
  223. }
  224. },
  225. null, null, ':input:first'
  226. );
  227. }
  228. var Toolbar = (function (my) {
  229. my.init = function (ui) {
  230. for(var k in buttonHandlers)
  231. $("#" + k).click(buttonHandlers[k]);
  232. UI = ui;
  233. // Update login info
  234. APP.xmpp.addListener(
  235. AuthenticationEvents.IDENTITY_UPDATED,
  236. function (authenticationEnabled, userIdentity) {
  237. var loggedIn = false;
  238. if (userIdentity) {
  239. loggedIn = true;
  240. }
  241. Toolbar.showAuthenticateButton(authenticationEnabled);
  242. if (authenticationEnabled) {
  243. Toolbar.setAuthenticatedIdentity(userIdentity);
  244. Toolbar.showLoginButton(!loggedIn);
  245. Toolbar.showLogoutButton(loggedIn);
  246. }
  247. }
  248. );
  249. };
  250. /**
  251. * Sets shared key
  252. * @param sKey the shared key
  253. */
  254. my.setSharedKey = function (sKey) {
  255. sharedKey = sKey;
  256. };
  257. my.authenticateClicked = function () {
  258. Authentication.focusAuthenticationWindow();
  259. if (!APP.xmpp.isExternalAuthEnabled()) {
  260. Authentication.xmppAuthenticate();
  261. return;
  262. }
  263. // Get authentication URL
  264. if (!APP.xmpp.isMUCJoined()) {
  265. APP.xmpp.getLoginUrl(UI.getRoomName(), function (url) {
  266. // If conference has not been started yet - redirect to login page
  267. window.location.href = url;
  268. });
  269. } else {
  270. APP.xmpp.getPopupLoginUrl(UI.getRoomName(), function (url) {
  271. // Otherwise - open popup with authentication URL
  272. var authenticationWindow = Authentication.createAuthenticationWindow(
  273. function () {
  274. // On popup closed - retry room allocation
  275. APP.xmpp.allocateConferenceFocus(
  276. APP.UI.getRoomName(),
  277. function () { console.info("AUTH DONE"); }
  278. );
  279. }, url);
  280. if (!authenticationWindow) {
  281. messageHandler.openMessageDialog(
  282. null, "dialog.popupError");
  283. }
  284. });
  285. }
  286. };
  287. /**
  288. * Updates the room invite url.
  289. */
  290. my.updateRoomUrl = function (newRoomUrl) {
  291. roomUrl = newRoomUrl;
  292. // If the invite dialog has been already opened we update the information.
  293. var inviteLink = document.getElementById('inviteLinkRef');
  294. if (inviteLink) {
  295. inviteLink.value = roomUrl;
  296. inviteLink.select();
  297. $('#inviteLinkRef').parent()
  298. .find('button[value=true]').prop('disabled', false);
  299. }
  300. };
  301. /**
  302. * Disables and enables some of the buttons.
  303. */
  304. my.setupButtonsFromConfig = function () {
  305. if (config.disablePrezi) {
  306. $("#prezi_button").css({display: "none"});
  307. }
  308. };
  309. /**
  310. * Opens the lock room dialog.
  311. */
  312. my.openLockDialog = function () {
  313. // Only the focus is able to set a shared key.
  314. if (!APP.xmpp.isModerator()) {
  315. if (sharedKey) {
  316. messageHandler.openMessageDialog(null,
  317. "dialog.passwordError");
  318. } else {
  319. messageHandler.openMessageDialog(null, "dialog.passwordError2");
  320. }
  321. } else {
  322. if (sharedKey) {
  323. messageHandler.openTwoButtonDialog(null, null,
  324. "dialog.passwordCheck",
  325. null,
  326. false,
  327. "dialog.Remove",
  328. function (e, v) {
  329. if (v) {
  330. Toolbar.setSharedKey('');
  331. lockRoom(false);
  332. }
  333. });
  334. } else {
  335. var msg = APP.translation.generateTranslationHTML(
  336. "dialog.passwordMsg");
  337. var yourPassword = APP.translation.translateString(
  338. "dialog.yourPassword");
  339. messageHandler.openTwoButtonDialog(null, null, null,
  340. '<h2>' + msg + '</h2>' +
  341. '<input name="lockKey" type="text"' +
  342. ' data-i18n="[placeholder]dialog.yourPassword" ' +
  343. 'placeholder="' + yourPassword + '" autofocus>',
  344. false,
  345. "dialog.Save",
  346. function (e, v, m, f) {
  347. if (v) {
  348. var lockKey = f.lockKey;
  349. if (lockKey) {
  350. Toolbar.setSharedKey(
  351. UIUtil.escapeHtml(lockKey));
  352. lockRoom(true);
  353. }
  354. }
  355. },
  356. null, null, 'input:first'
  357. );
  358. }
  359. }
  360. };
  361. /**
  362. * Opens the invite link dialog.
  363. */
  364. my.openLinkDialog = function () {
  365. var inviteAttreibutes;
  366. if (roomUrl === null) {
  367. inviteAttreibutes = 'data-i18n="[value]roomUrlDefaultMsg" value="' +
  368. APP.translation.translateString("roomUrlDefaultMsg") + '"';
  369. } else {
  370. inviteAttreibutes = "value=\"" + encodeURI(roomUrl) + "\"";
  371. }
  372. messageHandler.openTwoButtonDialog("dialog.shareLink",
  373. null, null,
  374. '<input id="inviteLinkRef" type="text" ' +
  375. inviteAttreibutes + ' onclick="this.select();" readonly>',
  376. false,
  377. "dialog.Invite",
  378. function (e, v) {
  379. if (v) {
  380. if (roomUrl) {
  381. inviteParticipants();
  382. }
  383. }
  384. },
  385. function (event) {
  386. if (roomUrl) {
  387. document.getElementById('inviteLinkRef').select();
  388. } else {
  389. if (event && event.target)
  390. $(event.target)
  391. .find('button[value=true]').prop('disabled', true);
  392. }
  393. }
  394. );
  395. };
  396. /**
  397. * Opens the settings dialog.
  398. * FIXME: not used ?
  399. */
  400. my.openSettingsDialog = function () {
  401. var settings1 = APP.translation.generateTranslationHTML(
  402. "dialog.settings1");
  403. var settings2 = APP.translation.generateTranslationHTML(
  404. "dialog.settings2");
  405. var settings3 = APP.translation.generateTranslationHTML(
  406. "dialog.settings3");
  407. var yourPassword = APP.translation.translateString(
  408. "dialog.yourPassword");
  409. messageHandler.openTwoButtonDialog(null,
  410. '<h2>' + settings1 + '</h2>' +
  411. '<input type="checkbox" id="initMuted">' +
  412. settings2 + '<br/>' +
  413. '<input type="checkbox" id="requireNicknames">' +
  414. settings3 +
  415. '<input id="lockKey" type="text" placeholder="' + yourPassword +
  416. '" data-i18n="[placeholder]dialog.yourPassword" autofocus>',
  417. null,
  418. null,
  419. false,
  420. "dialog.Save",
  421. function () {
  422. document.getElementById('lockKey').focus();
  423. },
  424. function (e, v) {
  425. if (v) {
  426. if ($('#initMuted').is(":checked")) {
  427. // it is checked
  428. }
  429. if ($('#requireNicknames').is(":checked")) {
  430. // it is checked
  431. }
  432. /*
  433. var lockKey = document.getElementById('lockKey');
  434. if (lockKey.value) {
  435. setSharedKey(lockKey.value);
  436. lockRoom(true);
  437. }
  438. */
  439. }
  440. }
  441. );
  442. };
  443. /**
  444. * Toggles the application in and out of full screen mode
  445. * (a.k.a. presentation mode in Chrome).
  446. */
  447. my.toggleFullScreen = function () {
  448. var fsElement = document.documentElement;
  449. if (!document.mozFullScreen && !document.webkitIsFullScreen) {
  450. //Enter Full Screen
  451. if (fsElement.mozRequestFullScreen) {
  452. fsElement.mozRequestFullScreen();
  453. }
  454. else {
  455. fsElement.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
  456. }
  457. } else {
  458. //Exit Full Screen
  459. if (document.mozCancelFullScreen) {
  460. document.mozCancelFullScreen();
  461. } else {
  462. document.webkitCancelFullScreen();
  463. }
  464. }
  465. };
  466. /**
  467. * Unlocks the lock button state.
  468. */
  469. my.unlockLockButton = function () {
  470. if ($("#lockIcon").hasClass("icon-security-locked"))
  471. UIUtil.buttonClick("#lockIcon", "icon-security icon-security-locked");
  472. };
  473. /**
  474. * Updates the lock button state to locked.
  475. */
  476. my.lockLockButton = function () {
  477. if ($("#lockIcon").hasClass("icon-security"))
  478. UIUtil.buttonClick("#lockIcon", "icon-security icon-security-locked");
  479. };
  480. /**
  481. * Shows or hides authentication button
  482. * @param show <tt>true</tt> to show or <tt>false</tt> to hide
  483. */
  484. my.showAuthenticateButton = function (show) {
  485. if (show) {
  486. $('#authentication').css({display: "inline"});
  487. }
  488. else {
  489. $('#authentication').css({display: "none"});
  490. }
  491. };
  492. // Shows or hides the 'recording' button.
  493. my.showRecordingButton = function (show) {
  494. if (!config.enableRecording) {
  495. return;
  496. }
  497. if (show) {
  498. $('#recording').css({display: "inline"});
  499. }
  500. else {
  501. $('#recording').css({display: "none"});
  502. }
  503. };
  504. // Sets the state of the recording button
  505. my.setRecordingButtonState = function (isRecording) {
  506. var selector = $('#recordButton');
  507. if (isRecording) {
  508. selector.removeClass("icon-recEnable");
  509. selector.addClass("icon-recEnable active");
  510. } else {
  511. selector.removeClass("icon-recEnable active");
  512. selector.addClass("icon-recEnable");
  513. }
  514. };
  515. // Shows or hides SIP calls button
  516. my.showSipCallButton = function (show) {
  517. if (APP.xmpp.isSipGatewayEnabled() && show) {
  518. $('#sipCallButton').css({display: "inline-block"});
  519. } else {
  520. $('#sipCallButton').css({display: "none"});
  521. }
  522. };
  523. // Shows or hides the dialpad button
  524. my.showDialPadButton = function (show) {
  525. if (show) {
  526. $('#dialPadButton').css({display: "inline-block"});
  527. } else {
  528. $('#dialPadButton').css({display: "none"});
  529. }
  530. };
  531. /**
  532. * Displays user authenticated identity name(login).
  533. * @param authIdentity identity name to be displayed.
  534. */
  535. my.setAuthenticatedIdentity = function (authIdentity) {
  536. if (authIdentity) {
  537. var selector = $('#toolbar_auth_identity');
  538. selector.css({display: "list-item"});
  539. selector.text(authIdentity);
  540. } else {
  541. $('#toolbar_auth_identity').css({display: "none"});
  542. }
  543. };
  544. /**
  545. * Shows/hides login button.
  546. * @param show <tt>true</tt> to show
  547. */
  548. my.showLoginButton = function (show) {
  549. if (show) {
  550. $('#toolbar_button_login').css({display: "list-item"});
  551. } else {
  552. $('#toolbar_button_login').css({display: "none"});
  553. }
  554. };
  555. /**
  556. * Shows/hides logout button.
  557. * @param show <tt>true</tt> to show
  558. */
  559. my.showLogoutButton = function (show) {
  560. if (show) {
  561. $('#toolbar_button_logout').css({display: "list-item"});
  562. } else {
  563. $('#toolbar_button_logout').css({display: "none"});
  564. }
  565. };
  566. /**
  567. * Sets the state of the button. The button has blue glow if desktop
  568. * streaming is active.
  569. * @param active the state of the desktop streaming.
  570. */
  571. my.changeDesktopSharingButtonState = function (active) {
  572. var button = $("#desktopsharing > a");
  573. if (active) {
  574. button.addClass("glow");
  575. } else {
  576. button.removeClass("glow");
  577. }
  578. };
  579. return my;
  580. }(Toolbar || {}));
  581. module.exports = Toolbar;