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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. /* global APP, $, buttonClick, config, lockRoom, interfaceConfig, setSharedKey,
  2. Util */
  3. /* jshint -W101 */
  4. var messageHandler = require("../util/MessageHandler");
  5. var BottomToolbar = require("./BottomToolbar");
  6. var Prezi = require("../prezi/Prezi");
  7. var Etherpad = require("../etherpad/Etherpad");
  8. var PanelToggler = require("../side_pannels/SidePanelToggler");
  9. var Authentication = require("../authentication/Authentication");
  10. var UIUtil = require("../util/UIUtil");
  11. var AuthenticationEvents
  12. = require("../../../service/authentication/AuthenticationEvents");
  13. var roomUrl = null;
  14. var sharedKey = '';
  15. var UI = null;
  16. var recordingToaster = null;
  17. var buttonHandlers = {
  18. "toolbar_button_mute": function () {
  19. return APP.UI.toggleAudio();
  20. },
  21. "toolbar_button_camera": function () {
  22. return APP.UI.toggleVideo();
  23. },
  24. /*"toolbar_button_authentication": function () {
  25. return Toolbar.authenticateClicked();
  26. },*/
  27. "toolbar_button_record": function () {
  28. return toggleRecording();
  29. },
  30. "toolbar_button_security": function () {
  31. return Toolbar.openLockDialog();
  32. },
  33. "toolbar_button_link": function () {
  34. return Toolbar.openLinkDialog();
  35. },
  36. "toolbar_button_chat": function () {
  37. return BottomToolbar.toggleChat();
  38. },
  39. "toolbar_button_prezi": function () {
  40. return Prezi.openPreziDialog();
  41. },
  42. "toolbar_button_etherpad": function () {
  43. return Etherpad.toggleEtherpad(0);
  44. },
  45. "toolbar_button_desktopsharing": function () {
  46. return APP.desktopsharing.toggleScreenSharing();
  47. },
  48. "toolbar_button_fullScreen": function() {
  49. UIUtil.buttonClick("#toolbar_button_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_dialpad": function () {
  56. return dialpadButtonClicked();
  57. },
  58. "toolbar_button_settings": function () {
  59. PanelToggler.toggleSettingsMenu();
  60. },
  61. "toolbar_button_hangup": function () {
  62. return hangup();
  63. },
  64. "toolbar_button_login": function () {
  65. Toolbar.authenticateClicked();
  66. },
  67. "toolbar_button_logout": function () {
  68. // Ask for confirmation
  69. messageHandler.openTwoButtonDialog(
  70. "dialog.logoutTitle",
  71. null,
  72. "dialog.logoutQuestion",
  73. null,
  74. false,
  75. "dialog.Yes",
  76. function (evt, yes) {
  77. if (yes) {
  78. APP.xmpp.logout(function (url) {
  79. if (url) {
  80. window.location.href = url;
  81. } else {
  82. hangup();
  83. }
  84. });
  85. }
  86. });
  87. }
  88. };
  89. function hangup() {
  90. APP.xmpp.disposeConference();
  91. if(config.enableWelcomePage) {
  92. setTimeout(function() {
  93. window.localStorage.welcomePageDisabled = false;
  94. window.location.pathname = "/";
  95. }, 10000);
  96. }
  97. var title = APP.translation.generateTranslationHTML(
  98. "dialog.sessTerminated");
  99. var msg = APP.translation.generateTranslationHTML(
  100. "dialog.hungUp");
  101. var button = APP.translation.generateTranslationHTML(
  102. "dialog.joinAgain");
  103. var buttons = [];
  104. buttons.push({title: button, value: true});
  105. UI.messageHandler.openDialog(
  106. title,
  107. msg,
  108. true,
  109. buttons,
  110. function(event, value, message, formVals) {
  111. window.location.reload();
  112. return false;
  113. }
  114. );
  115. }
  116. /**
  117. * Starts or stops the recording for the conference.
  118. */
  119. function toggleRecording(predefinedToken) {
  120. APP.xmpp.toggleRecording(function (callback) {
  121. if (predefinedToken) {
  122. callback(UIUtil.escapeHtml(predefinedToken));
  123. return;
  124. }
  125. var msg = APP.translation.generateTranslationHTML(
  126. "dialog.recordingToken");
  127. var token = APP.translation.translateString("dialog.token");
  128. APP.UI.messageHandler.openTwoButtonDialog(null, null, null,
  129. '<h2>' + msg + '</h2>' +
  130. '<input name="recordingToken" type="text" ' +
  131. ' data-i18n="[placeholder]dialog.token" ' +
  132. 'placeholder="' + token + '" autofocus>',
  133. false,
  134. "dialog.Save",
  135. function (e, v, m, f) {
  136. if (v) {
  137. var token = f.recordingToken;
  138. if (token) {
  139. callback(UIUtil.escapeHtml(token));
  140. }
  141. }
  142. },
  143. null,
  144. function () { },
  145. ':input:first'
  146. );
  147. }, Toolbar.setRecordingButtonState);
  148. }
  149. /**
  150. * Locks / unlocks the room.
  151. */
  152. function lockRoom(lock) {
  153. var currentSharedKey = '';
  154. if (lock)
  155. currentSharedKey = sharedKey;
  156. APP.xmpp.lockRoom(currentSharedKey, function (res) {
  157. // password is required
  158. if (sharedKey) {
  159. console.log('set room password');
  160. Toolbar.lockLockButton();
  161. }
  162. else {
  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 dialpadButtonClicked() {
  209. //TODO show the dialpad box
  210. }
  211. function callSipButtonClicked() {
  212. var defaultNumber
  213. = config.defaultSipNumber ? config.defaultSipNumber : '';
  214. var sipMsg = APP.translation.generateTranslationHTML(
  215. "dialog.sipMsg");
  216. messageHandler.openTwoButtonDialog(null, null, null,
  217. '<h2>' + sipMsg + '</h2>' +
  218. '<input name="sipNumber" type="text"' +
  219. ' value="' + defaultNumber + '" autofocus>',
  220. false,
  221. "dialog.Dial",
  222. function (e, v, m, f) {
  223. if (v) {
  224. var numberInput = f.sipNumber;
  225. if (numberInput) {
  226. APP.xmpp.dial(
  227. numberInput, 'fromnumber', UI.getRoomName(), sharedKey);
  228. }
  229. }
  230. },
  231. null, null, ':input:first'
  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. Toolbar.showAuthenticateButton(authenticationEnabled);
  248. if (authenticationEnabled) {
  249. Toolbar.setAuthenticatedIdentity(userIdentity);
  250. Toolbar.showLoginButton(!loggedIn);
  251. Toolbar.showLogoutButton(loggedIn);
  252. }
  253. }
  254. );
  255. };
  256. /**
  257. * Sets shared key
  258. * @param sKey the shared key
  259. */
  260. my.setSharedKey = function (sKey) {
  261. sharedKey = sKey;
  262. };
  263. my.authenticateClicked = function () {
  264. Authentication.focusAuthenticationWindow();
  265. if (!APP.xmpp.isExternalAuthEnabled()) {
  266. Authentication.xmppAuthenticate();
  267. return;
  268. }
  269. // Get authentication URL
  270. if (!APP.xmpp.isMUCJoined()) {
  271. APP.xmpp.getLoginUrl(UI.getRoomName(), function (url) {
  272. // If conference has not been started yet - redirect to login page
  273. window.location.href = url;
  274. });
  275. } else {
  276. APP.xmpp.getPopupLoginUrl(UI.getRoomName(), function (url) {
  277. // Otherwise - open popup with authentication URL
  278. var authenticationWindow = Authentication.createAuthenticationWindow(
  279. function () {
  280. // On popup closed - retry room allocation
  281. APP.xmpp.allocateConferenceFocus(
  282. APP.UI.getRoomName(),
  283. function () { console.info("AUTH DONE"); }
  284. );
  285. }, url);
  286. if (!authenticationWindow) {
  287. messageHandler.openMessageDialog(
  288. null, "dialog.popupError");
  289. }
  290. });
  291. }
  292. };
  293. /**
  294. * Updates the room invite url.
  295. */
  296. my.updateRoomUrl = function (newRoomUrl) {
  297. roomUrl = newRoomUrl;
  298. // If the invite dialog has been already opened we update the information.
  299. var inviteLink = document.getElementById('inviteLinkRef');
  300. if (inviteLink) {
  301. inviteLink.value = roomUrl;
  302. inviteLink.select();
  303. $('#inviteLinkRef').parent()
  304. .find('button[value=true]').prop('disabled', false);
  305. }
  306. };
  307. /**
  308. * Disables and enables some of the buttons.
  309. */
  310. my.setupButtonsFromConfig = function () {
  311. if (config.disablePrezi) {
  312. $("#toolbar_button_prezi").css({display: "none"});
  313. }
  314. };
  315. /**
  316. * Opens the lock room dialog.
  317. */
  318. my.openLockDialog = function () {
  319. // Only the focus is able to set a shared key.
  320. if (!APP.xmpp.isModerator()) {
  321. if (sharedKey) {
  322. messageHandler.openMessageDialog(null,
  323. "dialog.passwordError");
  324. } else {
  325. messageHandler.openMessageDialog(null, "dialog.passwordError2");
  326. }
  327. } else {
  328. if (sharedKey) {
  329. messageHandler.openTwoButtonDialog(null, null,
  330. "dialog.passwordCheck",
  331. null,
  332. false,
  333. "dialog.Remove",
  334. function (e, v) {
  335. if (v) {
  336. Toolbar.setSharedKey('');
  337. lockRoom(false);
  338. }
  339. });
  340. } else {
  341. var msg = APP.translation.generateTranslationHTML(
  342. "dialog.passwordMsg");
  343. var yourPassword = APP.translation.translateString(
  344. "dialog.yourPassword");
  345. messageHandler.openTwoButtonDialog(null, null, null,
  346. '<h2>' + msg + '</h2>' +
  347. '<input name="lockKey" type="text"' +
  348. ' data-i18n="[placeholder]dialog.yourPassword" ' +
  349. 'placeholder="' + yourPassword + '" autofocus>',
  350. false,
  351. "dialog.Save",
  352. function (e, v, m, f) {
  353. if (v) {
  354. var lockKey = f.lockKey;
  355. if (lockKey) {
  356. Toolbar.setSharedKey(
  357. UIUtil.escapeHtml(lockKey));
  358. lockRoom(true);
  359. }
  360. }
  361. },
  362. null, null, 'input:first'
  363. );
  364. }
  365. }
  366. };
  367. /**
  368. * Opens the invite link dialog.
  369. */
  370. my.openLinkDialog = function () {
  371. var inviteAttreibutes;
  372. if (roomUrl === null) {
  373. inviteAttreibutes = 'data-i18n="[value]roomUrlDefaultMsg" value="' +
  374. APP.translation.translateString("roomUrlDefaultMsg") + '"';
  375. } else {
  376. inviteAttreibutes = "value=\"" + encodeURI(roomUrl) + "\"";
  377. }
  378. messageHandler.openTwoButtonDialog("dialog.shareLink",
  379. null, null,
  380. '<input id="inviteLinkRef" type="text" ' +
  381. inviteAttreibutes + ' onclick="this.select();" readonly>',
  382. false,
  383. "dialog.Invite",
  384. function (e, v) {
  385. if (v) {
  386. if (roomUrl) {
  387. inviteParticipants();
  388. }
  389. }
  390. },
  391. function (event) {
  392. if (roomUrl) {
  393. document.getElementById('inviteLinkRef').select();
  394. } else {
  395. if (event && event.target)
  396. $(event.target)
  397. .find('button[value=true]').prop('disabled', true);
  398. }
  399. }
  400. );
  401. };
  402. /**
  403. * Opens the settings dialog.
  404. * FIXME: not used ?
  405. */
  406. my.openSettingsDialog = function () {
  407. var settings1 = APP.translation.generateTranslationHTML(
  408. "dialog.settings1");
  409. var settings2 = APP.translation.generateTranslationHTML(
  410. "dialog.settings2");
  411. var settings3 = APP.translation.generateTranslationHTML(
  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 ($("#toolbar_button_security").hasClass("icon-security-locked"))
  477. UIUtil.buttonClick("#toolbar_button_security", "icon-security icon-security-locked");
  478. };
  479. /**
  480. * Updates the lock button state to locked.
  481. */
  482. my.lockLockButton = function () {
  483. if ($("#toolbar_button_security").hasClass("icon-security"))
  484. UIUtil.buttonClick("#toolbar_button_security", "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. $('#toolbar_button_record').css({display: "inline-block"});
  505. }
  506. else {
  507. $('#toolbar_button_record').css({display: "none"});
  508. }
  509. };
  510. // Sets the state of the recording button
  511. my.setRecordingButtonState = function (recordingState) {
  512. var selector = $('#toolbar_button_record');
  513. if (recordingState === 'on') {
  514. selector.removeClass("icon-recEnable");
  515. selector.addClass("icon-recEnable active");
  516. $("#largeVideo").toggleClass("videoMessageFilter", true);
  517. var recordOnKey = "recording.on";
  518. $('#videoConnectionMessage').attr("data-i18n", recordOnKey);
  519. $('#videoConnectionMessage').text(APP.translation.translateString(recordOnKey));
  520. setTimeout(function(){
  521. $("#largeVideo").toggleClass("videoMessageFilter", false);
  522. $('#videoConnectionMessage').css({display: "none"});
  523. }, 1500);
  524. recordingToaster = messageHandler.notify(null, "recording.toaster", null,
  525. null, null, {timeOut: 0, closeButton: null, tapToDismiss: false});
  526. } else if (recordingState === 'off') {
  527. selector.removeClass("icon-recEnable active");
  528. selector.addClass("icon-recEnable");
  529. $("#largeVideo").toggleClass("videoMessageFilter", false);
  530. $('#videoConnectionMessage').css({display: "none"});
  531. if (recordingToaster)
  532. messageHandler.remove(recordingToaster);
  533. } else if (recordingState === 'pending') {
  534. selector.removeClass("icon-recEnable active");
  535. selector.addClass("icon-recEnable");
  536. $("#largeVideo").toggleClass("videoMessageFilter", true);
  537. var recordPendingKey = "recording.pending";
  538. $('#videoConnectionMessage').attr("data-i18n", recordPendingKey);
  539. $('#videoConnectionMessage').text(APP.translation.translateString(recordPendingKey));
  540. $('#videoConnectionMessage').css({display: "block"});
  541. }
  542. };
  543. // checks whether recording is enabled and whether we have params to start automatically recording
  544. my.checkAutoRecord = function () {
  545. if (config.enableRecording && config.autoRecord) {
  546. toggleRecording(config.autoRecordToken);
  547. }
  548. };
  549. // Shows or hides SIP calls button
  550. my.showSipCallButton = function (show) {
  551. if (APP.xmpp.isSipGatewayEnabled() && show) {
  552. $('#toolbar_button_sip').css({display: "inline-block"});
  553. } else {
  554. $('#toolbar_button_sip').css({display: "none"});
  555. }
  556. };
  557. // Shows or hides the dialpad button
  558. my.showDialPadButton = function (show) {
  559. if (show) {
  560. $('#toolbar_button_dialpad').css({display: "inline-block"});
  561. } else {
  562. $('#toolbar_button_dialpad').css({display: "none"});
  563. }
  564. };
  565. /**
  566. * Displays user authenticated identity name(login).
  567. * @param authIdentity identity name to be displayed.
  568. */
  569. my.setAuthenticatedIdentity = function (authIdentity) {
  570. if (authIdentity) {
  571. var selector = $('#toolbar_auth_identity');
  572. selector.css({display: "list-item"});
  573. selector.text(authIdentity);
  574. } else {
  575. $('#toolbar_auth_identity').css({display: "none"});
  576. }
  577. };
  578. /**
  579. * Shows/hides login button.
  580. * @param show <tt>true</tt> to show
  581. */
  582. my.showLoginButton = function (show) {
  583. if (show) {
  584. $('#toolbar_button_login').css({display: "list-item"});
  585. } else {
  586. $('#toolbar_button_login').css({display: "none"});
  587. }
  588. };
  589. /**
  590. * Shows/hides logout button.
  591. * @param show <tt>true</tt> to show
  592. */
  593. my.showLogoutButton = function (show) {
  594. if (show) {
  595. $('#toolbar_button_logout').css({display: "list-item"});
  596. } else {
  597. $('#toolbar_button_logout').css({display: "none"});
  598. }
  599. };
  600. /**
  601. * Sets the state of the button. The button has blue glow if desktop
  602. * streaming is active.
  603. * @param active the state of the desktop streaming.
  604. */
  605. my.changeDesktopSharingButtonState = function (active) {
  606. var button = $("#toolbar_button_desktopsharing");
  607. if (active) {
  608. button.addClass("glow");
  609. } else {
  610. button.removeClass("glow");
  611. }
  612. };
  613. return my;
  614. }(Toolbar || {}));
  615. module.exports = Toolbar;