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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. /* global APP, $, buttonClick, config, lockRoom, interfaceConfig, setSharedKey,
  2. 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 recordingToaster = null;
  16. var buttonHandlers = {
  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. UIUtil.buttonClick("#toolbar_button_fullScreen", "icon-full-screen icon-exit-full-screen");
  49. return Toolbar.toggleFullScreen();
  50. },
  51. "toolbar_button_sip": function () {
  52. return callSipButtonClicked();
  53. },
  54. "toolbar_button_dialpad": function () {
  55. return dialpadButtonClicked();
  56. },
  57. "toolbar_button_settings": function () {
  58. PanelToggler.toggleSettingsMenu();
  59. },
  60. "toolbar_button_hangup": function () {
  61. return hangup();
  62. },
  63. "toolbar_button_login": function () {
  64. Toolbar.authenticateClicked();
  65. },
  66. "toolbar_button_logout": function () {
  67. // Ask for confirmation
  68. messageHandler.openTwoButtonDialog(
  69. "dialog.logoutTitle",
  70. null,
  71. "dialog.logoutQuestion",
  72. null,
  73. false,
  74. "dialog.Yes",
  75. function (evt, yes) {
  76. if (yes) {
  77. APP.xmpp.logout(function (url) {
  78. if (url) {
  79. window.location.href = url;
  80. } else {
  81. hangup();
  82. }
  83. });
  84. }
  85. });
  86. }
  87. };
  88. function hangup() {
  89. APP.xmpp.disposeConference();
  90. if(config.enableWelcomePage) {
  91. setTimeout(function() {
  92. window.localStorage.welcomePageDisabled = false;
  93. window.location.pathname = "/";
  94. }, 10000);
  95. }
  96. var title = APP.translation.generateTranslationHTML(
  97. "dialog.sessTerminated");
  98. var msg = APP.translation.generateTranslationHTML(
  99. "dialog.hungUp");
  100. var button = APP.translation.generateTranslationHTML(
  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. window.location.reload();
  111. return false;
  112. }
  113. );
  114. }
  115. /**
  116. * Starts or stops the recording for the conference.
  117. */
  118. function toggleRecording(predefinedToken) {
  119. APP.xmpp.toggleRecording(function (callback) {
  120. if (predefinedToken) {
  121. callback(UIUtil.escapeHtml(predefinedToken));
  122. return;
  123. }
  124. var msg = APP.translation.generateTranslationHTML(
  125. "dialog.recordingToken");
  126. var token = APP.translation.translateString("dialog.token");
  127. APP.UI.messageHandler.openTwoButtonDialog(null, null, null,
  128. '<h2>' + msg + '</h2>' +
  129. '<input name="recordingToken" type="text" ' +
  130. ' data-i18n="[placeholder]dialog.token" ' +
  131. 'placeholder="' + token + '" autofocus>',
  132. false,
  133. "dialog.Save",
  134. function (e, v, m, f) {
  135. if (v) {
  136. var token = f.recordingToken;
  137. if (token) {
  138. callback(UIUtil.escapeHtml(token));
  139. }
  140. }
  141. },
  142. null,
  143. function () { },
  144. ':input:first'
  145. );
  146. }, Toolbar.setRecordingButtonState);
  147. }
  148. /**
  149. * Locks / unlocks the room.
  150. */
  151. function lockRoom(lock) {
  152. var currentSharedKey = '';
  153. if (lock)
  154. currentSharedKey = sharedKey;
  155. APP.xmpp.lockRoom(currentSharedKey, function (res) {
  156. // password is required
  157. if (sharedKey) {
  158. console.log('set room password');
  159. Toolbar.lockLockButton();
  160. }
  161. else {
  162. console.log('removed room password');
  163. Toolbar.unlockLockButton();
  164. }
  165. }, function (err) {
  166. console.warn('setting password failed', err);
  167. messageHandler.showError("dialog.lockTitle",
  168. "dialog.lockMessage");
  169. Toolbar.setSharedKey('');
  170. }, function () {
  171. console.warn('room passwords not supported');
  172. messageHandler.showError("dialog.warning",
  173. "dialog.passwordNotSupported");
  174. Toolbar.setSharedKey('');
  175. });
  176. }
  177. /**
  178. * Invite participants to conference.
  179. */
  180. function inviteParticipants() {
  181. if (roomUrl === null)
  182. return;
  183. var sharedKeyText = "";
  184. if (sharedKey && sharedKey.length > 0) {
  185. sharedKeyText =
  186. APP.translation.translateString("email.sharedKey",
  187. {sharedKey: sharedKey});
  188. sharedKeyText = sharedKeyText.replace(/\n/g, "%0D%0A");
  189. }
  190. var supportedBrowsers = "Chromium, Google Chrome " +
  191. APP.translation.translateString("email.and") + " Opera";
  192. var conferenceName = roomUrl.substring(roomUrl.lastIndexOf('/') + 1);
  193. var subject = APP.translation.translateString("email.subject",
  194. {appName:interfaceConfig.APP_NAME, conferenceName: conferenceName});
  195. var body = APP.translation.translateString("email.body",
  196. {appName:interfaceConfig.APP_NAME, sharedKeyText: sharedKeyText,
  197. roomUrl: roomUrl, supportedBrowsers: supportedBrowsers});
  198. body = body.replace(/\n/g, "%0D%0A");
  199. if (window.localStorage.displayname) {
  200. body += "%0D%0A%0D%0A" + window.localStorage.displayname;
  201. }
  202. if (interfaceConfig.INVITATION_POWERED_BY) {
  203. body += "%0D%0A%0D%0A--%0D%0Apowered by jitsi.org";
  204. }
  205. window.open("mailto:?subject=" + subject + "&body=" + body, '_blank');
  206. }
  207. function dialpadButtonClicked() {
  208. //TODO show the dialpad box
  209. }
  210. function callSipButtonClicked() {
  211. var defaultNumber
  212. = config.defaultSipNumber ? config.defaultSipNumber : '';
  213. var sipMsg = APP.translation.generateTranslationHTML(
  214. "dialog.sipMsg");
  215. messageHandler.openTwoButtonDialog(null, null, null,
  216. '<h2>' + sipMsg + '</h2>' +
  217. '<input name="sipNumber" type="text"' +
  218. ' value="' + defaultNumber + '" autofocus>',
  219. false,
  220. "dialog.Dial",
  221. function (e, v, m, f) {
  222. if (v) {
  223. var numberInput = f.sipNumber;
  224. if (numberInput) {
  225. APP.xmpp.dial(
  226. numberInput, 'fromnumber', UI.getRoomName(), sharedKey);
  227. }
  228. }
  229. },
  230. null, null, ':input:first'
  231. );
  232. }
  233. var Toolbar = (function (my) {
  234. my.init = function (ui) {
  235. for(var k in buttonHandlers)
  236. $("#" + k).click(buttonHandlers[k]);
  237. UI = ui;
  238. // Update login info
  239. APP.xmpp.addListener(
  240. AuthenticationEvents.IDENTITY_UPDATED,
  241. function (authenticationEnabled, userIdentity) {
  242. var loggedIn = false;
  243. if (userIdentity) {
  244. loggedIn = true;
  245. }
  246. Toolbar.showAuthenticateButton(authenticationEnabled);
  247. if (authenticationEnabled) {
  248. Toolbar.setAuthenticatedIdentity(userIdentity);
  249. Toolbar.showLoginButton(!loggedIn);
  250. Toolbar.showLogoutButton(loggedIn);
  251. }
  252. }
  253. );
  254. };
  255. /**
  256. * Sets shared key
  257. * @param sKey the shared key
  258. */
  259. my.setSharedKey = function (sKey) {
  260. sharedKey = sKey;
  261. };
  262. my.authenticateClicked = function () {
  263. Authentication.focusAuthenticationWindow();
  264. if (!APP.xmpp.isExternalAuthEnabled()) {
  265. Authentication.xmppAuthenticate();
  266. return;
  267. }
  268. // Get authentication URL
  269. if (!APP.xmpp.isMUCJoined()) {
  270. APP.xmpp.getLoginUrl(UI.getRoomName(), function (url) {
  271. // If conference has not been started yet - redirect to login page
  272. window.location.href = url;
  273. });
  274. } else {
  275. APP.xmpp.getPopupLoginUrl(UI.getRoomName(), function (url) {
  276. // Otherwise - open popup with authentication URL
  277. var authenticationWindow = Authentication.createAuthenticationWindow(
  278. function () {
  279. // On popup closed - retry room allocation
  280. APP.xmpp.allocateConferenceFocus(
  281. APP.UI.getRoomName(),
  282. function () { console.info("AUTH DONE"); }
  283. );
  284. }, url);
  285. if (!authenticationWindow) {
  286. messageHandler.openMessageDialog(
  287. null, "dialog.popupError");
  288. }
  289. });
  290. }
  291. };
  292. /**
  293. * Updates the room invite url.
  294. */
  295. my.updateRoomUrl = function (newRoomUrl) {
  296. roomUrl = newRoomUrl;
  297. // If the invite dialog has been already opened we update the information.
  298. var inviteLink = document.getElementById('inviteLinkRef');
  299. if (inviteLink) {
  300. inviteLink.value = roomUrl;
  301. inviteLink.select();
  302. $('#inviteLinkRef').parent()
  303. .find('button[value=true]').prop('disabled', false);
  304. }
  305. };
  306. /**
  307. * Disables and enables some of the buttons.
  308. */
  309. my.setupButtonsFromConfig = function () {
  310. if (config.disablePrezi) {
  311. $("#toolbar_button_prezi").css({display: "none"});
  312. }
  313. };
  314. /**
  315. * Opens the lock room dialog.
  316. */
  317. my.openLockDialog = function () {
  318. // Only the focus is able to set a shared key.
  319. if (!APP.xmpp.isModerator()) {
  320. if (sharedKey) {
  321. messageHandler.openMessageDialog(null,
  322. "dialog.passwordError");
  323. } else {
  324. messageHandler.openMessageDialog(null, "dialog.passwordError2");
  325. }
  326. } else {
  327. if (sharedKey) {
  328. messageHandler.openTwoButtonDialog(null, null,
  329. "dialog.passwordCheck",
  330. null,
  331. false,
  332. "dialog.Remove",
  333. function (e, v) {
  334. if (v) {
  335. Toolbar.setSharedKey('');
  336. lockRoom(false);
  337. }
  338. });
  339. } else {
  340. var msg = APP.translation.generateTranslationHTML(
  341. "dialog.passwordMsg");
  342. var yourPassword = APP.translation.translateString(
  343. "dialog.yourPassword");
  344. messageHandler.openTwoButtonDialog(null, null, null,
  345. '<h2>' + msg + '</h2>' +
  346. '<input name="lockKey" type="text"' +
  347. ' data-i18n="[placeholder]dialog.yourPassword" ' +
  348. 'placeholder="' + yourPassword + '" autofocus>',
  349. false,
  350. "dialog.Save",
  351. function (e, v, m, f) {
  352. if (v) {
  353. var lockKey = f.lockKey;
  354. if (lockKey) {
  355. Toolbar.setSharedKey(
  356. UIUtil.escapeHtml(lockKey));
  357. lockRoom(true);
  358. }
  359. }
  360. },
  361. null, null, 'input:first'
  362. );
  363. }
  364. }
  365. };
  366. /**
  367. * Opens the invite link dialog.
  368. */
  369. my.openLinkDialog = function () {
  370. var inviteAttreibutes;
  371. if (roomUrl === null) {
  372. inviteAttreibutes = 'data-i18n="[value]roomUrlDefaultMsg" value="' +
  373. APP.translation.translateString("roomUrlDefaultMsg") + '"';
  374. } else {
  375. inviteAttreibutes = "value=\"" + encodeURI(roomUrl) + "\"";
  376. }
  377. messageHandler.openTwoButtonDialog("dialog.shareLink",
  378. null, null,
  379. '<input id="inviteLinkRef" type="text" ' +
  380. inviteAttreibutes + ' onclick="this.select();" readonly>',
  381. false,
  382. "dialog.Invite",
  383. function (e, v) {
  384. if (v) {
  385. if (roomUrl) {
  386. inviteParticipants();
  387. }
  388. }
  389. },
  390. function (event) {
  391. if (roomUrl) {
  392. document.getElementById('inviteLinkRef').select();
  393. } else {
  394. if (event && event.target)
  395. $(event.target)
  396. .find('button[value=true]').prop('disabled', true);
  397. }
  398. }
  399. );
  400. };
  401. /**
  402. * Opens the settings dialog.
  403. * FIXME: not used ?
  404. */
  405. my.openSettingsDialog = function () {
  406. var settings1 = APP.translation.generateTranslationHTML(
  407. "dialog.settings1");
  408. var settings2 = APP.translation.generateTranslationHTML(
  409. "dialog.settings2");
  410. var settings3 = APP.translation.generateTranslationHTML(
  411. "dialog.settings3");
  412. var yourPassword = APP.translation.translateString(
  413. "dialog.yourPassword");
  414. messageHandler.openTwoButtonDialog(null,
  415. '<h2>' + settings1 + '</h2>' +
  416. '<input type="checkbox" id="initMuted">' +
  417. settings2 + '<br/>' +
  418. '<input type="checkbox" id="requireNicknames">' +
  419. settings3 +
  420. '<input id="lockKey" type="text" placeholder="' + yourPassword +
  421. '" data-i18n="[placeholder]dialog.yourPassword" autofocus>',
  422. null,
  423. null,
  424. false,
  425. "dialog.Save",
  426. function () {
  427. document.getElementById('lockKey').focus();
  428. },
  429. function (e, v) {
  430. if (v) {
  431. if ($('#initMuted').is(":checked")) {
  432. // it is checked
  433. }
  434. if ($('#requireNicknames').is(":checked")) {
  435. // it is checked
  436. }
  437. /*
  438. var lockKey = document.getElementById('lockKey');
  439. if (lockKey.value) {
  440. setSharedKey(lockKey.value);
  441. lockRoom(true);
  442. }
  443. */
  444. }
  445. }
  446. );
  447. };
  448. /**
  449. * Toggles the application in and out of full screen mode
  450. * (a.k.a. presentation mode in Chrome).
  451. */
  452. my.toggleFullScreen = function () {
  453. var fsElement = document.documentElement;
  454. if (!document.mozFullScreen && !document.webkitIsFullScreen) {
  455. //Enter Full Screen
  456. if (fsElement.mozRequestFullScreen) {
  457. fsElement.mozRequestFullScreen();
  458. }
  459. else {
  460. fsElement.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
  461. }
  462. } else {
  463. //Exit Full Screen
  464. if (document.mozCancelFullScreen) {
  465. document.mozCancelFullScreen();
  466. } else {
  467. document.webkitCancelFullScreen();
  468. }
  469. }
  470. };
  471. /**
  472. * Unlocks the lock button state.
  473. */
  474. my.unlockLockButton = function () {
  475. if ($("#toolbar_button_security").hasClass("icon-security-locked"))
  476. UIUtil.buttonClick("#toolbar_button_security", "icon-security icon-security-locked");
  477. };
  478. /**
  479. * Updates the lock button state to locked.
  480. */
  481. my.lockLockButton = function () {
  482. if ($("#toolbar_button_security").hasClass("icon-security"))
  483. UIUtil.buttonClick("#toolbar_button_security", "icon-security icon-security-locked");
  484. };
  485. /**
  486. * Shows or hides authentication button
  487. * @param show <tt>true</tt> to show or <tt>false</tt> to hide
  488. */
  489. my.showAuthenticateButton = function (show) {
  490. if (show) {
  491. $('#authentication').css({display: "inline"});
  492. }
  493. else {
  494. $('#authentication').css({display: "none"});
  495. }
  496. };
  497. // Shows or hides the 'recording' button.
  498. my.showRecordingButton = function (show) {
  499. if (!config.enableRecording) {
  500. return;
  501. }
  502. if (show) {
  503. $('#toolbar_button_record').css({display: "inline-block"});
  504. }
  505. else {
  506. $('#toolbar_button_record').css({display: "none"});
  507. }
  508. };
  509. // Sets the state of the recording button
  510. my.setRecordingButtonState = function (recordingState) {
  511. var selector = $('#toolbar_button_record');
  512. if (recordingState === 'on') {
  513. selector.removeClass("icon-recEnable");
  514. selector.addClass("icon-recEnable active");
  515. $("#largeVideo").toggleClass("videoMessageFilter", true);
  516. var recordOnKey = "recording.on";
  517. $('#videoConnectionMessage').attr("data-i18n", recordOnKey);
  518. $('#videoConnectionMessage').text(APP.translation.translateString(recordOnKey));
  519. setTimeout(function(){
  520. $("#largeVideo").toggleClass("videoMessageFilter", false);
  521. $('#videoConnectionMessage').css({display: "none"});
  522. }, 1500);
  523. recordingToaster = messageHandler.notify(null, "recording.toaster", null,
  524. null, null, {timeOut: 0, closeButton: null, tapToDismiss: false});
  525. } else if (recordingState === 'off') {
  526. selector.removeClass("icon-recEnable active");
  527. selector.addClass("icon-recEnable");
  528. $("#largeVideo").toggleClass("videoMessageFilter", false);
  529. $('#videoConnectionMessage').css({display: "none"});
  530. if (recordingToaster)
  531. messageHandler.remove(recordingToaster);
  532. } else if (recordingState === 'pending') {
  533. selector.removeClass("icon-recEnable active");
  534. selector.addClass("icon-recEnable");
  535. $("#largeVideo").toggleClass("videoMessageFilter", true);
  536. var recordPendingKey = "recording.pending";
  537. $('#videoConnectionMessage').attr("data-i18n", recordPendingKey);
  538. $('#videoConnectionMessage').text(APP.translation.translateString(recordPendingKey));
  539. $('#videoConnectionMessage').css({display: "block"});
  540. }
  541. };
  542. // checks whether recording is enabled and whether we have params to start automatically recording
  543. my.checkAutoRecord = function () {
  544. if (config.enableRecording && config.autoRecord) {
  545. toggleRecording(config.autoRecordToken);
  546. }
  547. };
  548. // Shows or hides SIP calls button
  549. my.showSipCallButton = function (show) {
  550. if (APP.xmpp.isSipGatewayEnabled() && show) {
  551. $('#toolbar_button_sip').css({display: "inline-block"});
  552. } else {
  553. $('#toolbar_button_sip').css({display: "none"});
  554. }
  555. };
  556. // Shows or hides the dialpad button
  557. my.showDialPadButton = function (show) {
  558. if (show) {
  559. $('#toolbar_button_dialpad').css({display: "inline-block"});
  560. } else {
  561. $('#toolbar_button_dialpad').css({display: "none"});
  562. }
  563. };
  564. /**
  565. * Displays user authenticated identity name(login).
  566. * @param authIdentity identity name to be displayed.
  567. */
  568. my.setAuthenticatedIdentity = function (authIdentity) {
  569. if (authIdentity) {
  570. var selector = $('#toolbar_auth_identity');
  571. selector.css({display: "list-item"});
  572. selector.text(authIdentity);
  573. } else {
  574. $('#toolbar_auth_identity').css({display: "none"});
  575. }
  576. };
  577. /**
  578. * Shows/hides login button.
  579. * @param show <tt>true</tt> to show
  580. */
  581. my.showLoginButton = function (show) {
  582. if (show) {
  583. $('#toolbar_button_login').css({display: "list-item"});
  584. } else {
  585. $('#toolbar_button_login').css({display: "none"});
  586. }
  587. };
  588. /**
  589. * Shows/hides logout button.
  590. * @param show <tt>true</tt> to show
  591. */
  592. my.showLogoutButton = function (show) {
  593. if (show) {
  594. $('#toolbar_button_logout').css({display: "list-item"});
  595. } else {
  596. $('#toolbar_button_logout').css({display: "none"});
  597. }
  598. };
  599. /**
  600. * Sets the state of the button. The button has blue glow if desktop
  601. * streaming is active.
  602. * @param active the state of the desktop streaming.
  603. */
  604. my.changeDesktopSharingButtonState = function (active) {
  605. var button = $("#toolbar_button_desktopsharing");
  606. if (active) {
  607. button.addClass("glow");
  608. } else {
  609. button.removeClass("glow");
  610. }
  611. };
  612. return my;
  613. }(Toolbar || {}));
  614. module.exports = Toolbar;