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. 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. APP.translation.translateString("email.sharedKey",
  188. {sharedKey: sharedKey});
  189. sharedKeyText = sharedKeyText.replace(/\n/g, "%0D%0A");
  190. }
  191. var supportedBrowsers = "Chromium, Google Chrome " +
  192. APP.translation.translateString("email.and") + " Opera";
  193. var conferenceName = roomUrl.substring(roomUrl.lastIndexOf('/') + 1);
  194. var subject = APP.translation.translateString("email.subject",
  195. {appName:interfaceConfig.APP_NAME, conferenceName: conferenceName});
  196. var body = APP.translation.translateString("email.body",
  197. {appName:interfaceConfig.APP_NAME, sharedKeyText: sharedKeyText,
  198. roomUrl: roomUrl, supportedBrowsers: supportedBrowsers});
  199. body = body.replace(/\n/g, "%0D%0A");
  200. if (window.localStorage.displayname) {
  201. body += "%0D%0A%0D%0A" + window.localStorage.displayname;
  202. }
  203. if (interfaceConfig.INVITATION_POWERED_BY) {
  204. body += "%0D%0A%0D%0A--%0D%0Apowered by jitsi.org";
  205. }
  206. window.open("mailto:?subject=" + subject + "&body=" + body, '_blank');
  207. }
  208. function callSipButtonClicked()
  209. {
  210. var defaultNumber
  211. = config.defaultSipNumber ? config.defaultSipNumber : '';
  212. var sipMsg = APP.translation.generateTranslatonHTML(
  213. "dialog.sipMsg");
  214. messageHandler.openTwoButtonDialog(null, null, null,
  215. '<h2>' + sipMsg + '</h2>' +
  216. '<input id="sipNumber" type="text"' +
  217. ' value="' + defaultNumber + '" autofocus>',
  218. false,
  219. "dialog.Dial",
  220. function (e, v, m, f) {
  221. if (v) {
  222. var numberInput = document.getElementById('sipNumber');
  223. if (numberInput.value) {
  224. APP.xmpp.dial(numberInput.value, 'fromnumber',
  225. UI.getRoomName(), sharedKey);
  226. }
  227. }
  228. },
  229. function (event) {
  230. document.getElementById('sipNumber').focus();
  231. }
  232. );
  233. }
  234. var Toolbar = (function (my) {
  235. my.init = function (ui) {
  236. for(var k in buttonHandlers)
  237. $("#" + k).click(buttonHandlers[k]);
  238. UI = ui;
  239. // Update login info
  240. APP.xmpp.addListener(
  241. AuthenticationEvents.IDENTITY_UPDATED,
  242. function (authenticationEnabled, userIdentity) {
  243. var loggedIn = false;
  244. if (userIdentity) {
  245. loggedIn = true;
  246. }
  247. //FIXME: XMPP authentication need improvements for "live" login
  248. if (!APP.xmpp.isExternalAuthEnabled() && !loggedIn)
  249. {
  250. authenticationEnabled = false;
  251. }
  252. Toolbar.showAuthenticateButton(authenticationEnabled);
  253. if (authenticationEnabled) {
  254. Toolbar.setAuthenticatedIdentity(userIdentity);
  255. Toolbar.showLoginButton(!loggedIn);
  256. Toolbar.showLogoutButton(loggedIn);
  257. }
  258. }
  259. );
  260. },
  261. /**
  262. * Sets shared key
  263. * @param sKey the shared key
  264. */
  265. my.setSharedKey = function (sKey) {
  266. sharedKey = sKey;
  267. };
  268. my.authenticateClicked = function () {
  269. Authentication.focusAuthenticationWindow();
  270. // Get authentication URL
  271. if (!APP.xmpp.getMUCJoined()) {
  272. APP.xmpp.getLoginUrl(UI.getRoomName(), function (url) {
  273. // If conference has not been started yet - redirect to login page
  274. window.location.href = url;
  275. });
  276. } else {
  277. APP.xmpp.getPopupLoginUrl(UI.getRoomName(), function (url) {
  278. // Otherwise - open popup with authentication URL
  279. var authenticationWindow = Authentication.createAuthenticationWindow(
  280. function () {
  281. // On popup closed - retry room allocation
  282. APP.xmpp.allocateConferenceFocus(
  283. APP.UI.getRoomName(),
  284. function () { console.info("AUTH DONE"); }
  285. );
  286. }, url);
  287. if (!authenticationWindow) {
  288. messageHandler.openMessageDialog(
  289. null, "dialog.popupError");
  290. }
  291. });
  292. }
  293. };
  294. /**
  295. * Updates the room invite url.
  296. */
  297. my.updateRoomUrl = function (newRoomUrl) {
  298. roomUrl = newRoomUrl;
  299. // If the invite dialog has been already opened we update the information.
  300. var inviteLink = document.getElementById('inviteLinkRef');
  301. if (inviteLink) {
  302. inviteLink.value = roomUrl;
  303. inviteLink.select();
  304. document.getElementById('jqi_state0_buttonInvite').disabled = false;
  305. }
  306. };
  307. /**
  308. * Disables and enables some of the buttons.
  309. */
  310. my.setupButtonsFromConfig = function () {
  311. if (config.disablePrezi)
  312. {
  313. $("#prezi_button").css({display: "none"});
  314. }
  315. };
  316. /**
  317. * Opens the lock room dialog.
  318. */
  319. my.openLockDialog = function () {
  320. // Only the focus is able to set a shared key.
  321. if (!APP.xmpp.isModerator()) {
  322. if (sharedKey) {
  323. messageHandler.openMessageDialog(null,
  324. "dialog.passwordError");
  325. } else {
  326. messageHandler.openMessageDialog(null, "dialog.passwordError2");
  327. }
  328. } else {
  329. if (sharedKey) {
  330. messageHandler.openTwoButtonDialog(null, null,
  331. "dialog.passwordCheck",
  332. null,
  333. false,
  334. "dialog.Remove",
  335. function (e, v) {
  336. if (v) {
  337. Toolbar.setSharedKey('');
  338. lockRoom(false);
  339. }
  340. });
  341. } else {
  342. var msg = APP.translation.generateTranslatonHTML(
  343. "dialog.passwordMsg");
  344. var yourPassword = APP.translation.translateString(
  345. "dialog.yourPassword");
  346. messageHandler.openTwoButtonDialog(null, null, null,
  347. '<h2>' + msg + '</h2>' +
  348. '<input id="lockKey" type="text"' +
  349. ' data-i18n="[placeholder]dialog.yourPassword" ' +
  350. 'placeholder="' + yourPassword + '" autofocus>',
  351. false,
  352. "dialog.Save",
  353. function (e, v) {
  354. if (v) {
  355. var lockKey = document.getElementById('lockKey');
  356. if (lockKey.value) {
  357. Toolbar.setSharedKey(UIUtil.escapeHtml(lockKey.value));
  358. lockRoom(true);
  359. }
  360. }
  361. },
  362. function () {
  363. document.getElementById('lockKey').focus();
  364. }
  365. );
  366. }
  367. }
  368. };
  369. /**
  370. * Opens the invite link dialog.
  371. */
  372. my.openLinkDialog = function () {
  373. var inviteAttreibutes;
  374. if (roomUrl === null) {
  375. inviteAttreibutes = 'data-i18n="[value]roomUrlDefaultMsg" value="' +
  376. APP.translation.translateString("roomUrlDefaultMsg") + '"';
  377. } else {
  378. inviteAttreibutes = "value=\"" + encodeURI(roomUrl) + "\"";
  379. }
  380. messageHandler.openTwoButtonDialog("dialog.shareLink",
  381. null, null,
  382. '<input id="inviteLinkRef" type="text" ' +
  383. inviteAttreibutes + ' onclick="this.select();" readonly>',
  384. false,
  385. "dialog.Invite",
  386. function (e, v) {
  387. if (v) {
  388. if (roomUrl) {
  389. inviteParticipants();
  390. }
  391. }
  392. },
  393. function () {
  394. if (roomUrl) {
  395. document.getElementById('inviteLinkRef').select();
  396. } else {
  397. document.getElementById('jqi_state0_buttonInvite')
  398. .disabled = true;
  399. }
  400. }
  401. );
  402. };
  403. /**
  404. * Opens the settings dialog.
  405. */
  406. my.openSettingsDialog = function () {
  407. var settings1 = APP.translation.generateTranslatonHTML(
  408. "dialog.settings1");
  409. var settings2 = APP.translation.generateTranslatonHTML(
  410. "dialog.settings2");
  411. var settings3 = APP.translation.generateTranslatonHTML(
  412. "dialog.settings3");
  413. var yourPassword = APP.translation.translateString(
  414. "dialog.yourPassword");
  415. messageHandler.openTwoButtonDialog(null,
  416. '<h2>' + settings1 + '</h2>' +
  417. '<input type="checkbox" id="initMuted">' +
  418. settings2 + '<br/>' +
  419. '<input type="checkbox" id="requireNicknames">' +
  420. settings3 +
  421. '<input id="lockKey" type="text" placeholder="' + yourPassword +
  422. '" data-i18n="[placeholder]dialog.yourPassword" autofocus>',
  423. null,
  424. null,
  425. false,
  426. "dialog.Save",
  427. function () {
  428. document.getElementById('lockKey').focus();
  429. },
  430. function (e, v) {
  431. if (v) {
  432. if ($('#initMuted').is(":checked")) {
  433. // it is checked
  434. }
  435. if ($('#requireNicknames').is(":checked")) {
  436. // it is checked
  437. }
  438. /*
  439. var lockKey = document.getElementById('lockKey');
  440. if (lockKey.value) {
  441. setSharedKey(lockKey.value);
  442. lockRoom(true);
  443. }
  444. */
  445. }
  446. }
  447. );
  448. };
  449. /**
  450. * Toggles the application in and out of full screen mode
  451. * (a.k.a. presentation mode in Chrome).
  452. */
  453. my.toggleFullScreen = function () {
  454. var fsElement = document.documentElement;
  455. if (!document.mozFullScreen && !document.webkitIsFullScreen) {
  456. //Enter Full Screen
  457. if (fsElement.mozRequestFullScreen) {
  458. fsElement.mozRequestFullScreen();
  459. }
  460. else {
  461. fsElement.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
  462. }
  463. } else {
  464. //Exit Full Screen
  465. if (document.mozCancelFullScreen) {
  466. document.mozCancelFullScreen();
  467. } else {
  468. document.webkitCancelFullScreen();
  469. }
  470. }
  471. };
  472. /**
  473. * Unlocks the lock button state.
  474. */
  475. my.unlockLockButton = function () {
  476. if ($("#lockIcon").hasClass("icon-security-locked"))
  477. UIUtil.buttonClick("#lockIcon", "icon-security icon-security-locked");
  478. };
  479. /**
  480. * Updates the lock button state to locked.
  481. */
  482. my.lockLockButton = function () {
  483. if ($("#lockIcon").hasClass("icon-security"))
  484. UIUtil.buttonClick("#lockIcon", "icon-security icon-security-locked");
  485. };
  486. /**
  487. * Shows or hides authentication button
  488. * @param show <tt>true</tt> to show or <tt>false</tt> to hide
  489. */
  490. my.showAuthenticateButton = function (show) {
  491. if (show) {
  492. $('#authentication').css({display: "inline"});
  493. }
  494. else {
  495. $('#authentication').css({display: "none"});
  496. }
  497. };
  498. // Shows or hides the 'recording' button.
  499. my.showRecordingButton = function (show) {
  500. if (!config.enableRecording) {
  501. return;
  502. }
  503. if (show) {
  504. $('#recording').css({display: "inline"});
  505. }
  506. else {
  507. $('#recording').css({display: "none"});
  508. }
  509. };
  510. // Sets the state of the recording button
  511. my.setRecordingButtonState = function (isRecording) {
  512. if (isRecording) {
  513. $('#recordButton').removeClass("icon-recEnable");
  514. $('#recordButton').addClass("icon-recEnable active");
  515. } else {
  516. $('#recordButton').removeClass("icon-recEnable active");
  517. $('#recordButton').addClass("icon-recEnable");
  518. }
  519. };
  520. // Shows or hides SIP calls button
  521. my.showSipCallButton = function (show) {
  522. if (APP.xmpp.isSipGatewayEnabled() && show) {
  523. $('#sipCallButton').css({display: "inline-block"});
  524. } else {
  525. $('#sipCallButton').css({display: "none"});
  526. }
  527. };
  528. /**
  529. * Displays user authenticated identity name(login).
  530. * @param authIdentity identity name to be displayed.
  531. */
  532. my.setAuthenticatedIdentity = function (authIdentity) {
  533. if (authIdentity) {
  534. $('#toolbar_auth_identity').css({display: "list-item"});
  535. $('#toolbar_auth_identity').text(authIdentity);
  536. } else {
  537. $('#toolbar_auth_identity').css({display: "none"});
  538. }
  539. };
  540. /**
  541. * Shows/hides login button.
  542. * @param show <tt>true</tt> to show
  543. */
  544. my.showLoginButton = function (show) {
  545. if (show) {
  546. $('#toolbar_button_login').css({display: "list-item"});
  547. } else {
  548. $('#toolbar_button_login').css({display: "none"});
  549. }
  550. };
  551. /**
  552. * Shows/hides logout button.
  553. * @param show <tt>true</tt> to show
  554. */
  555. my.showLogoutButton = function (show) {
  556. if (show) {
  557. $('#toolbar_button_logout').css({display: "list-item"});
  558. } else {
  559. $('#toolbar_button_logout').css({display: "none"});
  560. }
  561. };
  562. /**
  563. * Sets the state of the button. The button has blue glow if desktop
  564. * streaming is active.
  565. * @param active the state of the desktop streaming.
  566. */
  567. my.changeDesktopSharingButtonState = function (active) {
  568. var button = $("#desktopsharing > a");
  569. if (active)
  570. {
  571. button.addClass("glow");
  572. }
  573. else
  574. {
  575. button.removeClass("glow");
  576. }
  577. };
  578. return my;
  579. }(Toolbar || {}));
  580. module.exports = Toolbar;