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.

Toolbar.js 21KB

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