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

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