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

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