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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  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. var token = APP.translation.translateString("dialog.token");
  124. APP.UI.messageHandler.openTwoButtonDialog(null, null, null,
  125. '<h2>' + msg + '</h2>' +
  126. '<input id="recordingToken" type="text" ' +
  127. ' data-i18n="[placeholder]dialog.token" ' +
  128. 'placeholder="' + token + '" autofocus>',
  129. false,
  130. "dialog.Save",
  131. function (e, v, m, f) {
  132. if (v) {
  133. var token = document.getElementById('recordingToken');
  134. if (token.value) {
  135. callback(UIUtil.escapeHtml(token.value));
  136. }
  137. }
  138. },
  139. function (event) {
  140. document.getElementById('recordingToken').focus();
  141. },
  142. function () {
  143. }
  144. );
  145. }, Toolbar.setRecordingButtonState, Toolbar.setRecordingButtonState);
  146. }
  147. /**
  148. * Locks / unlocks the room.
  149. */
  150. function lockRoom(lock) {
  151. var currentSharedKey = '';
  152. if (lock)
  153. currentSharedKey = sharedKey;
  154. APP.xmpp.lockRoom(currentSharedKey, function (res) {
  155. // password is required
  156. if (sharedKey)
  157. {
  158. console.log('set room password');
  159. Toolbar.lockLockButton();
  160. }
  161. else
  162. {
  163. console.log('removed room password');
  164. Toolbar.unlockLockButton();
  165. }
  166. }, function (err) {
  167. console.warn('setting password failed', err);
  168. messageHandler.showError("dialog.lockTitle",
  169. "dialog.lockMessage");
  170. Toolbar.setSharedKey('');
  171. }, function () {
  172. console.warn('room passwords not supported');
  173. messageHandler.showError("dialog.warning",
  174. "dialog.passwordNotSupported");
  175. Toolbar.setSharedKey('');
  176. });
  177. };
  178. /**
  179. * Invite participants to conference.
  180. */
  181. function inviteParticipants() {
  182. if (roomUrl === null)
  183. return;
  184. var sharedKeyText = "";
  185. if (sharedKey && sharedKey.length > 0) {
  186. sharedKeyText =
  187. "This conference is password protected. Please use the " +
  188. "following pin when joining:%0D%0A%0D%0A" +
  189. sharedKey + "%0D%0A%0D%0A";
  190. }
  191. var conferenceName = roomUrl.substring(roomUrl.lastIndexOf('/') + 1);
  192. var subject = "Invitation to a " + interfaceConfig.APP_NAME + " (" + conferenceName + ")";
  193. var body = "Hey there, I%27d like to invite you to a " + interfaceConfig.APP_NAME +
  194. " conference I%27ve just set up.%0D%0A%0D%0A" +
  195. "Please click on the following link in order" +
  196. " to join the conference.%0D%0A%0D%0A" +
  197. roomUrl +
  198. "%0D%0A%0D%0A" +
  199. sharedKeyText +
  200. "Note that " + interfaceConfig.APP_NAME + " is currently" +
  201. " only supported by Chromium," +
  202. " Google Chrome and Opera, so you need" +
  203. " to be using one of these browsers.%0D%0A%0D%0A" +
  204. "Talk to you in a sec!";
  205. if (window.localStorage.displayname) {
  206. body += "%0D%0A%0D%0A" + window.localStorage.displayname;
  207. }
  208. if (interfaceConfig.INVITATION_POWERED_BY) {
  209. body += "%0D%0A%0D%0A--%0D%0Apowered by jitsi.org";
  210. }
  211. window.open("mailto:?subject=" + subject + "&body=" + body, '_blank');
  212. }
  213. function callSipButtonClicked()
  214. {
  215. var defaultNumber
  216. = config.defaultSipNumber ? config.defaultSipNumber : '';
  217. var sipMsg = APP.translation.generateTranslatonHTML(
  218. "dialog.sipMsg");
  219. messageHandler.openTwoButtonDialog(null, null, null,
  220. '<h2>' + sipMsg + '</h2>' +
  221. '<input id="sipNumber" type="text"' +
  222. ' value="' + defaultNumber + '" autofocus>',
  223. false,
  224. "dialog.Dial",
  225. function (e, v, m, f) {
  226. if (v) {
  227. var numberInput = document.getElementById('sipNumber');
  228. if (numberInput.value) {
  229. APP.xmpp.dial(numberInput.value, 'fromnumber',
  230. UI.getRoomName(), sharedKey);
  231. }
  232. }
  233. },
  234. function (event) {
  235. document.getElementById('sipNumber').focus();
  236. }
  237. );
  238. }
  239. var Toolbar = (function (my) {
  240. my.init = function (ui) {
  241. for(var k in buttonHandlers)
  242. $("#" + k).click(buttonHandlers[k]);
  243. UI = ui;
  244. // Update login info
  245. APP.xmpp.addListener(
  246. AuthenticationEvents.IDENTITY_UPDATED,
  247. function (authenticationEnabled, userIdentity) {
  248. var loggedIn = false;
  249. if (userIdentity) {
  250. loggedIn = true;
  251. }
  252. //FIXME: XMPP authentication need improvements for "live" login
  253. if (!APP.xmpp.isExternalAuthEnabled() && !loggedIn)
  254. {
  255. authenticationEnabled = false;
  256. }
  257. Toolbar.showAuthenticateButton(authenticationEnabled);
  258. if (authenticationEnabled) {
  259. Toolbar.setAuthenticatedIdentity(userIdentity);
  260. Toolbar.showLoginButton(!loggedIn);
  261. Toolbar.showLogoutButton(loggedIn);
  262. }
  263. }
  264. );
  265. },
  266. /**
  267. * Sets shared key
  268. * @param sKey the shared key
  269. */
  270. my.setSharedKey = function (sKey) {
  271. sharedKey = sKey;
  272. };
  273. my.authenticateClicked = function () {
  274. Authentication.focusAuthenticationWindow();
  275. // Get authentication URL
  276. if (!APP.xmpp.getMUCJoined()) {
  277. APP.xmpp.getLoginUrl(UI.getRoomName(), function (url) {
  278. // If conference has not been started yet - redirect to login page
  279. window.location.href = url;
  280. });
  281. } else {
  282. APP.xmpp.getPopupLoginUrl(UI.getRoomName(), function (url) {
  283. // Otherwise - open popup with authentication URL
  284. var authenticationWindow = Authentication.createAuthenticationWindow(
  285. function () {
  286. // On popup closed - retry room allocation
  287. APP.xmpp.allocateConferenceFocus(
  288. APP.UI.getRoomName(),
  289. function () { console.info("AUTH DONE"); }
  290. );
  291. }, url);
  292. if (!authenticationWindow) {
  293. messageHandler.openMessageDialog(
  294. null, "dialog.popupError");
  295. }
  296. });
  297. }
  298. };
  299. /**
  300. * Updates the room invite url.
  301. */
  302. my.updateRoomUrl = function (newRoomUrl) {
  303. roomUrl = newRoomUrl;
  304. // If the invite dialog has been already opened we update the information.
  305. var inviteLink = document.getElementById('inviteLinkRef');
  306. if (inviteLink) {
  307. inviteLink.value = roomUrl;
  308. inviteLink.select();
  309. document.getElementById('jqi_state0_buttonInvite').disabled = false;
  310. }
  311. };
  312. /**
  313. * Disables and enables some of the buttons.
  314. */
  315. my.setupButtonsFromConfig = function () {
  316. if (config.disablePrezi)
  317. {
  318. $("#prezi_button").css({display: "none"});
  319. }
  320. };
  321. /**
  322. * Opens the lock room dialog.
  323. */
  324. my.openLockDialog = function () {
  325. // Only the focus is able to set a shared key.
  326. if (!APP.xmpp.isModerator()) {
  327. if (sharedKey) {
  328. messageHandler.openMessageDialog(null,
  329. "dialog.passwordError");
  330. } else {
  331. messageHandler.openMessageDialog(null, "dialog.passwordError2");
  332. }
  333. } else {
  334. if (sharedKey) {
  335. messageHandler.openTwoButtonDialog(null, null,
  336. "dialog.passwordCheck",
  337. null,
  338. false,
  339. "dialog.Remove",
  340. function (e, v) {
  341. if (v) {
  342. Toolbar.setSharedKey('');
  343. lockRoom(false);
  344. }
  345. });
  346. } else {
  347. var msg = APP.translation.generateTranslatonHTML(
  348. "dialog.passwordMsg");
  349. var yourPassword = APP.translation.translateString(
  350. "dialog.yourPassword");
  351. messageHandler.openTwoButtonDialog(null, null, null,
  352. '<h2>' + msg + '</h2>' +
  353. '<input id="lockKey" type="text"' +
  354. ' data-i18n="[placeholder]dialog.yourPassword" ' +
  355. 'placeholder="' + yourPassword + '" autofocus>',
  356. false,
  357. "dialog.Save",
  358. function (e, v) {
  359. if (v) {
  360. var lockKey = document.getElementById('lockKey');
  361. if (lockKey.value) {
  362. Toolbar.setSharedKey(UIUtil.escapeHtml(lockKey.value));
  363. lockRoom(true);
  364. }
  365. }
  366. },
  367. function () {
  368. document.getElementById('lockKey').focus();
  369. }
  370. );
  371. }
  372. }
  373. };
  374. /**
  375. * Opens the invite link dialog.
  376. */
  377. my.openLinkDialog = function () {
  378. var inviteLink;
  379. if (roomUrl === null) {
  380. inviteLink = "Your conference is currently being created...";
  381. } else {
  382. inviteLink = encodeURI(roomUrl);
  383. }
  384. messageHandler.openTwoButtonDialog("dialog.shareLink",
  385. null, null,
  386. '<input id="inviteLinkRef" type="text" value="' +
  387. inviteLink + '" onclick="this.select();" readonly>',
  388. false,
  389. "dialog.Invite",
  390. function (e, v) {
  391. if (v) {
  392. if (roomUrl) {
  393. inviteParticipants();
  394. }
  395. }
  396. },
  397. function () {
  398. if (roomUrl) {
  399. document.getElementById('inviteLinkRef').select();
  400. } else {
  401. document.getElementById('jqi_state0_buttonInvite')
  402. .disabled = true;
  403. }
  404. }
  405. );
  406. };
  407. /**
  408. * Opens the settings dialog.
  409. */
  410. my.openSettingsDialog = function () {
  411. var settings1 = APP.translation.generateTranslatonHTML(
  412. "dialog.settings1");
  413. var settings2 = APP.translation.generateTranslatonHTML(
  414. "dialog.settings2");
  415. var settings3 = APP.translation.generateTranslatonHTML(
  416. "dialog.settings3");
  417. var yourPassword = APP.translation.translateString(
  418. "dialog.yourPassword");
  419. messageHandler.openTwoButtonDialog(null,
  420. '<h2>' + settings1 + '</h2>' +
  421. '<input type="checkbox" id="initMuted">' +
  422. settings2 + '<br/>' +
  423. '<input type="checkbox" id="requireNicknames">' +
  424. settings3 +
  425. '<input id="lockKey" type="text" placeholder="' + yourPassword +
  426. '" data-i18n="[placeholder]dialog.yourPassword" autofocus>',
  427. null,
  428. null,
  429. false,
  430. "dialog.Save",
  431. function () {
  432. document.getElementById('lockKey').focus();
  433. },
  434. function (e, v) {
  435. if (v) {
  436. if ($('#initMuted').is(":checked")) {
  437. // it is checked
  438. }
  439. if ($('#requireNicknames').is(":checked")) {
  440. // it is checked
  441. }
  442. /*
  443. var lockKey = document.getElementById('lockKey');
  444. if (lockKey.value) {
  445. setSharedKey(lockKey.value);
  446. lockRoom(true);
  447. }
  448. */
  449. }
  450. }
  451. );
  452. };
  453. /**
  454. * Toggles the application in and out of full screen mode
  455. * (a.k.a. presentation mode in Chrome).
  456. */
  457. my.toggleFullScreen = function () {
  458. var fsElement = document.documentElement;
  459. if (!document.mozFullScreen && !document.webkitIsFullScreen) {
  460. //Enter Full Screen
  461. if (fsElement.mozRequestFullScreen) {
  462. fsElement.mozRequestFullScreen();
  463. }
  464. else {
  465. fsElement.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
  466. }
  467. } else {
  468. //Exit Full Screen
  469. if (document.mozCancelFullScreen) {
  470. document.mozCancelFullScreen();
  471. } else {
  472. document.webkitCancelFullScreen();
  473. }
  474. }
  475. };
  476. /**
  477. * Unlocks the lock button state.
  478. */
  479. my.unlockLockButton = function () {
  480. if ($("#lockIcon").hasClass("icon-security-locked"))
  481. UIUtil.buttonClick("#lockIcon", "icon-security icon-security-locked");
  482. };
  483. /**
  484. * Updates the lock button state to locked.
  485. */
  486. my.lockLockButton = function () {
  487. if ($("#lockIcon").hasClass("icon-security"))
  488. UIUtil.buttonClick("#lockIcon", "icon-security icon-security-locked");
  489. };
  490. /**
  491. * Shows or hides authentication button
  492. * @param show <tt>true</tt> to show or <tt>false</tt> to hide
  493. */
  494. my.showAuthenticateButton = function (show) {
  495. if (show) {
  496. $('#authentication').css({display: "inline"});
  497. }
  498. else {
  499. $('#authentication').css({display: "none"});
  500. }
  501. };
  502. // Shows or hides the 'recording' button.
  503. my.showRecordingButton = function (show) {
  504. if (!config.enableRecording) {
  505. return;
  506. }
  507. if (show) {
  508. $('#recording').css({display: "inline"});
  509. }
  510. else {
  511. $('#recording').css({display: "none"});
  512. }
  513. };
  514. // Sets the state of the recording button
  515. my.setRecordingButtonState = function (isRecording) {
  516. if (isRecording) {
  517. $('#recordButton').removeClass("icon-recEnable");
  518. $('#recordButton').addClass("icon-recEnable active");
  519. } else {
  520. $('#recordButton').removeClass("icon-recEnable active");
  521. $('#recordButton').addClass("icon-recEnable");
  522. }
  523. };
  524. // Shows or hides SIP calls button
  525. my.showSipCallButton = function (show) {
  526. if (APP.xmpp.isSipGatewayEnabled() && show) {
  527. $('#sipCallButton').css({display: "inline-block"});
  528. } else {
  529. $('#sipCallButton').css({display: "none"});
  530. }
  531. };
  532. /**
  533. * Displays user authenticated identity name(login).
  534. * @param authIdentity identity name to be displayed.
  535. */
  536. my.setAuthenticatedIdentity = function (authIdentity) {
  537. if (authIdentity) {
  538. $('#toolbar_auth_identity').css({display: "list-item"});
  539. $('#toolbar_auth_identity').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. {
  575. button.addClass("glow");
  576. }
  577. else
  578. {
  579. button.removeClass("glow");
  580. }
  581. };
  582. return my;
  583. }(Toolbar || {}));
  584. module.exports = Toolbar;