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 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  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. "dialog.logoutTitle",
  68. null,
  69. "dialog.logoutQuestion",
  70. null,
  71. false,
  72. "dialog.Yes",
  73. function (evt, yes) {
  74. if (yes) {
  75. APP.xmpp.logout(function (url) {
  76. if (url) {
  77. window.location.href = url;
  78. } else {
  79. hangup();
  80. }
  81. });
  82. }
  83. });
  84. }
  85. };
  86. function hangup() {
  87. APP.xmpp.disposeConference();
  88. if(config.enableWelcomePage)
  89. {
  90. setTimeout(function()
  91. {
  92. window.localStorage.welcomePageDisabled = false;
  93. window.location.pathname = "/";
  94. }, 10000);
  95. }
  96. var title = APP.translation.generateTranslatonHTML(
  97. "dialog.sessTerminated");
  98. var msg = APP.translation.generateTranslatonHTML(
  99. "dialog.hungUp");
  100. var button = APP.translation.generateTranslatonHTML(
  101. "dialog.joinAgain");
  102. var buttons = {};
  103. buttons.joinAgain = {title: button, value: true};
  104. UI.messageHandler.openDialog(
  105. title,
  106. msg,
  107. true,
  108. buttons,
  109. function(event, value, message, formVals)
  110. {
  111. window.location.reload();
  112. return false;
  113. }
  114. );
  115. }
  116. /**
  117. * Starts or stops the recording for the conference.
  118. */
  119. function toggleRecording() {
  120. APP.xmpp.toggleRecording(function (callback) {
  121. var msg = APP.translation.generateTranslatonHTML(
  122. "dialog.recordingToken");
  123. APP.UI.messageHandler.openTwoButtonDialog(null, null, null,
  124. '<h2>' + msg + '</h2>' +
  125. '<input id="recordingToken" type="text" ' +
  126. 'placeholder="token" autofocus>',
  127. false,
  128. "dialog.Save",
  129. function (e, v, m, f) {
  130. if (v) {
  131. var token = document.getElementById('recordingToken');
  132. if (token.value) {
  133. callback(UIUtil.escapeHtml(token.value));
  134. }
  135. }
  136. },
  137. function (event) {
  138. document.getElementById('recordingToken').focus();
  139. },
  140. function () {
  141. }
  142. );
  143. }, Toolbar.setRecordingButtonState, Toolbar.setRecordingButtonState);
  144. }
  145. /**
  146. * Locks / unlocks the room.
  147. */
  148. function lockRoom(lock) {
  149. var currentSharedKey = '';
  150. if (lock)
  151. currentSharedKey = sharedKey;
  152. APP.xmpp.lockRoom(currentSharedKey, function (res) {
  153. // password is required
  154. if (sharedKey)
  155. {
  156. console.log('set room password');
  157. Toolbar.lockLockButton();
  158. }
  159. else
  160. {
  161. console.log('removed room password');
  162. Toolbar.unlockLockButton();
  163. }
  164. }, function (err) {
  165. console.warn('setting password failed', err);
  166. messageHandler.showError("dialog.lockTitle",
  167. "dialog.lockMessage");
  168. Toolbar.setSharedKey('');
  169. }, function () {
  170. console.warn('room passwords not supported');
  171. messageHandler.showError("dialog.warning",
  172. "dialog.passwordNotSupported");
  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");
  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, "dialog.popupError");
  293. }
  294. });
  295. }
  296. };
  297. /**
  298. * Updates the room invite url.
  299. */
  300. my.updateRoomUrl = function (newRoomUrl) {
  301. roomUrl = newRoomUrl;
  302. // If the invite dialog has been already opened we update the information.
  303. var inviteLink = document.getElementById('inviteLinkRef');
  304. if (inviteLink) {
  305. inviteLink.value = roomUrl;
  306. inviteLink.select();
  307. document.getElementById('jqi_state0_buttonInvite').disabled = false;
  308. }
  309. };
  310. /**
  311. * Disables and enables some of the buttons.
  312. */
  313. my.setupButtonsFromConfig = function () {
  314. if (config.disablePrezi)
  315. {
  316. $("#prezi_button").css({display: "none"});
  317. }
  318. };
  319. /**
  320. * Opens the lock room dialog.
  321. */
  322. my.openLockDialog = function () {
  323. // Only the focus is able to set a shared key.
  324. if (!APP.xmpp.isModerator()) {
  325. if (sharedKey) {
  326. messageHandler.openMessageDialog(null,
  327. "dialog.passwordError");
  328. } else {
  329. messageHandler.openMessageDialog(null, "dialog.passwordError2");
  330. }
  331. } else {
  332. if (sharedKey) {
  333. messageHandler.openTwoButtonDialog(null, null,
  334. "dialog.passwordCheck",
  335. null,
  336. false,
  337. "dialog.Remove",
  338. function (e, v) {
  339. if (v) {
  340. Toolbar.setSharedKey('');
  341. lockRoom(false);
  342. }
  343. });
  344. } else {
  345. var msg = APP.translation.generateTranslatonHTML(
  346. "dialog.passwordMsg");
  347. var yourPassword = APP.translation.translateString(
  348. "dialog.yourPassword");
  349. messageHandler.openTwoButtonDialog(null, null, null,
  350. '<h2>' + msg + '</h2>' +
  351. '<input id="lockKey" type="text"' +
  352. 'placeholder="' + yourPassword + '" autofocus>',
  353. false,
  354. "dialog.Save",
  355. function (e, v) {
  356. if (v) {
  357. var lockKey = document.getElementById('lockKey');
  358. if (lockKey.value) {
  359. Toolbar.setSharedKey(UIUtil.escapeHtml(lockKey.value));
  360. lockRoom(true);
  361. }
  362. }
  363. },
  364. function () {
  365. document.getElementById('lockKey').focus();
  366. }
  367. );
  368. }
  369. }
  370. };
  371. /**
  372. * Opens the invite link dialog.
  373. */
  374. my.openLinkDialog = function () {
  375. var inviteLink;
  376. if (roomUrl === null) {
  377. inviteLink = "Your conference is currently being created...";
  378. } else {
  379. inviteLink = encodeURI(roomUrl);
  380. }
  381. messageHandler.openTwoButtonDialog("dialog.shareLink",
  382. null, null,
  383. '<input id="inviteLinkRef" type="text" value="' +
  384. inviteLink + '" onclick="this.select();" readonly>',
  385. false,
  386. "dialog.Invite",
  387. function (e, v) {
  388. if (v) {
  389. if (roomUrl) {
  390. inviteParticipants();
  391. }
  392. }
  393. },
  394. function () {
  395. if (roomUrl) {
  396. document.getElementById('inviteLinkRef').select();
  397. } else {
  398. document.getElementById('jqi_state0_buttonInvite')
  399. .disabled = true;
  400. }
  401. }
  402. );
  403. };
  404. /**
  405. * Opens the settings dialog.
  406. */
  407. my.openSettingsDialog = function () {
  408. var settings1 = APP.translation.generateTranslatonHTML(
  409. "dialog.settings1");
  410. var settings2 = APP.translation.generateTranslatonHTML(
  411. "dialog.settings2");
  412. var settings3 = APP.translation.generateTranslatonHTML(
  413. "dialog.settings3");
  414. var yourPassword = APP.translation.translateString(
  415. "dialog.yourPassword");
  416. messageHandler.openTwoButtonDialog(null,
  417. '<h2>' + settings1 + '</h2>' +
  418. '<input type="checkbox" id="initMuted">' +
  419. settings2 + '<br/>' +
  420. '<input type="checkbox" id="requireNicknames">' +
  421. settings3 +
  422. '<input id="lockKey" type="text" placeholder="' + yourPassword +
  423. '" data-i18n="[placeholder]dialog.yourPassword" autofocus>',
  424. null,
  425. null,
  426. false,
  427. "dialog.Save",
  428. function () {
  429. document.getElementById('lockKey').focus();
  430. },
  431. function (e, v) {
  432. if (v) {
  433. if ($('#initMuted').is(":checked")) {
  434. // it is checked
  435. }
  436. if ($('#requireNicknames').is(":checked")) {
  437. // it is checked
  438. }
  439. /*
  440. var lockKey = document.getElementById('lockKey');
  441. if (lockKey.value) {
  442. setSharedKey(lockKey.value);
  443. lockRoom(true);
  444. }
  445. */
  446. }
  447. }
  448. );
  449. };
  450. /**
  451. * Toggles the application in and out of full screen mode
  452. * (a.k.a. presentation mode in Chrome).
  453. */
  454. my.toggleFullScreen = function () {
  455. var fsElement = document.documentElement;
  456. if (!document.mozFullScreen && !document.webkitIsFullScreen) {
  457. //Enter Full Screen
  458. if (fsElement.mozRequestFullScreen) {
  459. fsElement.mozRequestFullScreen();
  460. }
  461. else {
  462. fsElement.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
  463. }
  464. } else {
  465. //Exit Full Screen
  466. if (document.mozCancelFullScreen) {
  467. document.mozCancelFullScreen();
  468. } else {
  469. document.webkitCancelFullScreen();
  470. }
  471. }
  472. };
  473. /**
  474. * Unlocks the lock button state.
  475. */
  476. my.unlockLockButton = function () {
  477. if ($("#lockIcon").hasClass("icon-security-locked"))
  478. UIUtil.buttonClick("#lockIcon", "icon-security icon-security-locked");
  479. };
  480. /**
  481. * Updates the lock button state to locked.
  482. */
  483. my.lockLockButton = function () {
  484. if ($("#lockIcon").hasClass("icon-security"))
  485. UIUtil.buttonClick("#lockIcon", "icon-security icon-security-locked");
  486. };
  487. /**
  488. * Shows or hides authentication button
  489. * @param show <tt>true</tt> to show or <tt>false</tt> to hide
  490. */
  491. my.showAuthenticateButton = function (show) {
  492. if (show) {
  493. $('#authentication').css({display: "inline"});
  494. }
  495. else {
  496. $('#authentication').css({display: "none"});
  497. }
  498. };
  499. // Shows or hides the 'recording' button.
  500. my.showRecordingButton = function (show) {
  501. if (!config.enableRecording) {
  502. return;
  503. }
  504. if (show) {
  505. $('#recording').css({display: "inline"});
  506. }
  507. else {
  508. $('#recording').css({display: "none"});
  509. }
  510. };
  511. // Sets the state of the recording button
  512. my.setRecordingButtonState = function (isRecording) {
  513. if (isRecording) {
  514. $('#recordButton').removeClass("icon-recEnable");
  515. $('#recordButton').addClass("icon-recEnable active");
  516. } else {
  517. $('#recordButton').removeClass("icon-recEnable active");
  518. $('#recordButton').addClass("icon-recEnable");
  519. }
  520. };
  521. // Shows or hides SIP calls button
  522. my.showSipCallButton = function (show) {
  523. if (APP.xmpp.isSipGatewayEnabled() && show) {
  524. $('#sipCallButton').css({display: "inline-block"});
  525. } else {
  526. $('#sipCallButton').css({display: "none"});
  527. }
  528. };
  529. /**
  530. * Displays user authenticated identity name(login).
  531. * @param authIdentity identity name to be displayed.
  532. */
  533. my.setAuthenticatedIdentity = function (authIdentity) {
  534. if (authIdentity) {
  535. $('#toolbar_auth_identity').css({display: "list-item"});
  536. $('#toolbar_auth_identity').text(authIdentity);
  537. } else {
  538. $('#toolbar_auth_identity').css({display: "none"});
  539. }
  540. };
  541. /**
  542. * Shows/hides login button.
  543. * @param show <tt>true</tt> to show
  544. */
  545. my.showLoginButton = function (show) {
  546. if (show) {
  547. $('#toolbar_button_login').css({display: "list-item"});
  548. } else {
  549. $('#toolbar_button_login').css({display: "none"});
  550. }
  551. };
  552. /**
  553. * Shows/hides logout button.
  554. * @param show <tt>true</tt> to show
  555. */
  556. my.showLogoutButton = function (show) {
  557. if (show) {
  558. $('#toolbar_button_logout').css({display: "list-item"});
  559. } else {
  560. $('#toolbar_button_logout').css({display: "none"});
  561. }
  562. };
  563. /**
  564. * Sets the state of the button. The button has blue glow if desktop
  565. * streaming is active.
  566. * @param active the state of the desktop streaming.
  567. */
  568. my.changeDesktopSharingButtonState = function (active) {
  569. var button = $("#desktopsharing > a");
  570. if (active)
  571. {
  572. button.addClass("glow");
  573. }
  574. else
  575. {
  576. button.removeClass("glow");
  577. }
  578. };
  579. return my;
  580. }(Toolbar || {}));
  581. module.exports = Toolbar;