Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

Toolbar.js 27KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831
  1. /* global APP, $, config, interfaceConfig, JitsiMeetJS */
  2. import UIUtil from '../util/UIUtil';
  3. import UIEvents from '../../../service/UI/UIEvents';
  4. import SideContainerToggler from "../side_pannels/SideContainerToggler";
  5. let roomUrl = null;
  6. let emitter = null;
  7. /**
  8. * Opens the invite link dialog.
  9. */
  10. function openLinkDialog () {
  11. let inviteAttributes;
  12. if (roomUrl === null) {
  13. inviteAttributes = 'data-i18n="[value]roomUrlDefaultMsg" value="' +
  14. APP.translation.translateString("roomUrlDefaultMsg") + '"';
  15. } else {
  16. inviteAttributes = "value=\"" + encodeURI(roomUrl) + "\"";
  17. }
  18. let inviteLinkId = "inviteLinkRef";
  19. let focusInviteLink = function() {
  20. $('#' + inviteLinkId).focus();
  21. $('#' + inviteLinkId).select();
  22. };
  23. let title = APP.translation.generateTranslationHTML("dialog.shareLink");
  24. APP.UI.messageHandler.openTwoButtonDialog(
  25. null, title, null,
  26. '<input id="' + inviteLinkId + '" type="text" '
  27. + inviteAttributes + ' readonly/>',
  28. false, "dialog.copy",
  29. function (e, v) {
  30. if (v && roomUrl) {
  31. JitsiMeetJS.analytics.sendEvent('toolbar.invite.button');
  32. focusInviteLink();
  33. document.execCommand('copy');
  34. }
  35. else {
  36. JitsiMeetJS.analytics.sendEvent('toolbar.invite.cancel');
  37. }
  38. },
  39. function (event) {
  40. if (!roomUrl) {
  41. if (event && event.target) {
  42. $(event.target).find('button[value=true]')
  43. .prop('disabled', true);
  44. }
  45. }
  46. else {
  47. focusInviteLink();
  48. }
  49. },
  50. function (e, v, m, f) {
  51. if(!v && !m && !f)
  52. JitsiMeetJS.analytics.sendEvent('toolbar.invite.close');
  53. },
  54. 'Copy' // Focus Copy button.
  55. );
  56. }
  57. const buttonHandlers = {
  58. "toolbar_button_profile": function () {
  59. JitsiMeetJS.analytics.sendEvent('toolbar.profile.toggled');
  60. emitter.emit(UIEvents.TOGGLE_PROFILE);
  61. },
  62. "toolbar_button_mute": function () {
  63. let sharedVideoManager = APP.UI.getSharedVideoManager();
  64. if (APP.conference.audioMuted) {
  65. // If there's a shared video with the volume "on" and we aren't
  66. // the video owner, we warn the user
  67. // that currently it's not possible to unmute.
  68. if (sharedVideoManager
  69. && sharedVideoManager.isSharedVideoVolumeOn()
  70. && !sharedVideoManager.isSharedVideoOwner()) {
  71. UIUtil.animateShowElement(
  72. $("#unableToUnmutePopup"), true, 5000);
  73. }
  74. else {
  75. JitsiMeetJS.analytics.sendEvent('toolbar.audio.unmuted');
  76. emitter.emit(UIEvents.AUDIO_MUTED, false, true);
  77. }
  78. } else {
  79. JitsiMeetJS.analytics.sendEvent('toolbar.audio.muted');
  80. emitter.emit(UIEvents.AUDIO_MUTED, true, true);
  81. }
  82. },
  83. "toolbar_button_camera": function () {
  84. if (APP.conference.videoMuted) {
  85. JitsiMeetJS.analytics.sendEvent('toolbar.video.enabled');
  86. emitter.emit(UIEvents.VIDEO_MUTED, false);
  87. } else {
  88. JitsiMeetJS.analytics.sendEvent('toolbar.video.disabled');
  89. emitter.emit(UIEvents.VIDEO_MUTED, true);
  90. }
  91. },
  92. "toolbar_button_security": function () {
  93. JitsiMeetJS.analytics.sendEvent('toolbar.lock.clicked');
  94. emitter.emit(UIEvents.ROOM_LOCK_CLICKED);
  95. },
  96. "toolbar_button_link": function () {
  97. JitsiMeetJS.analytics.sendEvent('toolbar.invite.clicked');
  98. openLinkDialog();
  99. },
  100. "toolbar_button_chat": function () {
  101. JitsiMeetJS.analytics.sendEvent('toolbar.chat.toggled');
  102. emitter.emit(UIEvents.TOGGLE_CHAT);
  103. },
  104. "toolbar_contact_list": function () {
  105. JitsiMeetJS.analytics.sendEvent(
  106. 'toolbar.contacts.toggled');
  107. emitter.emit(UIEvents.TOGGLE_CONTACT_LIST);
  108. },
  109. "toolbar_button_etherpad": function () {
  110. JitsiMeetJS.analytics.sendEvent('toolbar.etherpad.clicked');
  111. emitter.emit(UIEvents.ETHERPAD_CLICKED);
  112. },
  113. "toolbar_button_sharedvideo": function () {
  114. JitsiMeetJS.analytics.sendEvent('toolbar.sharedvideo.clicked');
  115. emitter.emit(UIEvents.SHARED_VIDEO_CLICKED);
  116. },
  117. "toolbar_button_desktopsharing": function () {
  118. if (APP.conference.isSharingScreen) {
  119. JitsiMeetJS.analytics.sendEvent('toolbar.screen.disabled');
  120. } else {
  121. JitsiMeetJS.analytics.sendEvent('toolbar.screen.enabled');
  122. }
  123. emitter.emit(UIEvents.TOGGLE_SCREENSHARING);
  124. },
  125. "toolbar_button_fullScreen": function() {
  126. JitsiMeetJS.analytics.sendEvent('toolbar.fullscreen.enabled');
  127. UIUtil.buttonClick("toolbar_button_fullScreen",
  128. "icon-full-screen icon-exit-full-screen");
  129. emitter.emit(UIEvents.FULLSCREEN_TOGGLE);
  130. },
  131. "toolbar_button_sip": function () {
  132. JitsiMeetJS.analytics.sendEvent('toolbar.sip.clicked');
  133. showSipNumberInput();
  134. },
  135. "toolbar_button_dialpad": function () {
  136. JitsiMeetJS.analytics.sendEvent('toolbar.sip.dialpad.clicked');
  137. dialpadButtonClicked();
  138. },
  139. "toolbar_button_settings": function () {
  140. JitsiMeetJS.analytics.sendEvent('toolbar.settings.toggled');
  141. emitter.emit(UIEvents.TOGGLE_SETTINGS);
  142. },
  143. "toolbar_button_hangup": function () {
  144. JitsiMeetJS.analytics.sendEvent('toolbar.hangup');
  145. emitter.emit(UIEvents.HANGUP);
  146. },
  147. "toolbar_button_login": function () {
  148. JitsiMeetJS.analytics.sendEvent('toolbar.authenticate.login.clicked');
  149. emitter.emit(UIEvents.AUTH_CLICKED);
  150. },
  151. "toolbar_button_logout": function () {
  152. JitsiMeetJS.analytics.sendEvent('toolbar.authenticate.logout.clicked');
  153. // Ask for confirmation
  154. APP.UI.messageHandler.openTwoButtonDialog(
  155. "dialog.logoutTitle",
  156. null,
  157. "dialog.logoutQuestion",
  158. null,
  159. false,
  160. "dialog.Yes",
  161. function (evt, yes) {
  162. if (yes) {
  163. emitter.emit(UIEvents.LOGOUT);
  164. }
  165. }
  166. );
  167. },
  168. "toolbar_film_strip": function () {
  169. JitsiMeetJS.analytics.sendEvent(
  170. 'toolbar.filmstrip.toggled');
  171. emitter.emit(UIEvents.TOGGLE_FILM_STRIP);
  172. },
  173. "toolbar_button_raisehand": function () {
  174. JitsiMeetJS.analytics.sendEvent(
  175. 'toolbar.raiseHand.clicked');
  176. APP.conference.maybeToggleRaisedHand();
  177. }
  178. };
  179. const defaultToolbarButtons = {
  180. 'microphone': {
  181. id: 'toolbar_button_mute',
  182. tooltipKey: 'toolbar.mute',
  183. className: "button icon-microphone",
  184. shortcut: 'M',
  185. shortcutAttr: 'mutePopover',
  186. shortcutFunc: function() {
  187. JitsiMeetJS.analytics.sendEvent('shortcut.audiomute.toggled');
  188. APP.conference.toggleAudioMuted();
  189. },
  190. shortcutDescription: "keyboardShortcuts.mute",
  191. popups: [
  192. {
  193. id: "micMutedPopup",
  194. className: "loginmenu",
  195. dataAttr: "[html]toolbar.micMutedPopup"
  196. },
  197. {
  198. id: "unableToUnmutePopup",
  199. className: "loginmenu",
  200. dataAttr: "[html]toolbar.unableToUnmutePopup"
  201. },
  202. {
  203. id: "talkWhileMutedPopup",
  204. className: "loginmenu",
  205. dataAttr: "[html]toolbar.talkWhileMutedPopup"
  206. }
  207. ],
  208. content: "Mute / Unmute",
  209. i18n: "[content]toolbar.mute"
  210. },
  211. 'camera': {
  212. id: 'toolbar_button_camera',
  213. tooltipKey: 'toolbar.videomute',
  214. className: "button icon-camera",
  215. shortcut: 'V',
  216. shortcutAttr: 'toggleVideoPopover',
  217. shortcutFunc: function() {
  218. JitsiMeetJS.analytics.sendEvent('shortcut.videomute.toggled');
  219. APP.conference.toggleVideoMuted();
  220. },
  221. shortcutDescription: "keyboardShortcuts.videoMute",
  222. content: "Start / stop camera",
  223. i18n: "[content]toolbar.videomute"
  224. },
  225. 'desktop': {
  226. id: 'toolbar_button_desktopsharing',
  227. tooltipKey: 'toolbar.sharescreen',
  228. className: 'button icon-share-desktop',
  229. shortcut: 'D',
  230. shortcutAttr: 'toggleDesktopSharingPopover',
  231. shortcutFunc: function() {
  232. JitsiMeetJS.analytics.sendEvent('shortcut.screen.toggled');
  233. APP.conference.toggleScreenSharing();
  234. },
  235. shortcutDescription: 'keyboardShortcuts.toggleScreensharing',
  236. content: 'Share screen',
  237. i18n: '[content]toolbar.sharescreen'
  238. },
  239. 'security': {
  240. id: 'toolbar_button_security',
  241. tooltipKey: 'toolbar.lock'
  242. },
  243. 'invite': {
  244. id: 'toolbar_button_link',
  245. tooltipKey: 'toolbar.invite',
  246. className: 'button icon-link',
  247. content: 'Invite others',
  248. i18n: '[content]toolbar.invite'
  249. },
  250. 'chat': {
  251. id: 'toolbar_button_chat',
  252. tooltipKey: 'toolbar.chat',
  253. shortcut: 'C',
  254. shortcutAttr: 'toggleChatPopover',
  255. shortcutFunc: function() {
  256. JitsiMeetJS.analytics.sendEvent('shortcut.chat.toggled');
  257. APP.UI.toggleChat();
  258. },
  259. shortcutDescription: 'keyboardShortcuts.toggleChat',
  260. sideContainerId: 'chat_container'
  261. },
  262. 'contacts': {
  263. id: 'toolbar_contact_list',
  264. tooltipKey: 'bottomtoolbar.contactlist',
  265. sideContainerId: 'contacts_container'
  266. },
  267. 'profile': {
  268. id: 'toolbar_button_profile',
  269. tooltipKey: 'profile.setDisplayNameLabel',
  270. sideContainerId: 'profile_container'
  271. },
  272. 'etherpad': {
  273. id: 'toolbar_button_etherpad',
  274. tooltipKey: 'toolbar.etherpad',
  275. },
  276. 'fullscreen': {
  277. id: 'toolbar_button_fullScreen',
  278. tooltipKey: 'toolbar.fullscreen',
  279. className: "button icon-full-screen",
  280. shortcut: 'S',
  281. shortcutAttr: 'toggleFullscreenPopover',
  282. shortcutFunc: function() {
  283. JitsiMeetJS.analytics.sendEvent('shortcut.fullscreen.toggled');
  284. APP.UI.toggleFullScreen();
  285. },
  286. shortcutDescription: "keyboardShortcuts.fullScreen",
  287. content: "Enter / Exit Full Screen",
  288. i18n: "[content]toolbar.fullscreen"
  289. },
  290. 'settings': {
  291. id: 'toolbar_button_settings',
  292. tooltipKey: 'toolbar.Settings',
  293. sideContainerId: "settings_container"
  294. },
  295. 'hangup': {
  296. id: 'toolbar_button_hangup',
  297. tooltipKey: 'toolbar.hangup',
  298. className: "button icon-hangup",
  299. content: "Hang Up",
  300. i18n: "[content]toolbar.hangup"
  301. },
  302. 'filmstrip': {
  303. id: 'toolbar_film_strip',
  304. tooltipKey: 'toolbar.filmstrip',
  305. shortcut: "F",
  306. shortcutAttr: "filmstripPopover",
  307. shortcutFunc: function() {
  308. JitsiMeetJS.analytics.sendEvent("shortcut.film.toggled");
  309. APP.UI.toggleFilmStrip();
  310. },
  311. shortcutDescription: "keyboardShortcuts.toggleFilmstrip"
  312. },
  313. 'raisehand': {
  314. id: "toolbar_button_raisehand",
  315. tooltipKey: 'toolbar.raiseHand',
  316. className: "button icon-raised-hand",
  317. shortcut: "R",
  318. shortcutAttr: "raiseHandPopover",
  319. shortcutFunc: function() {
  320. JitsiMeetJS.analytics.sendEvent("shortcut.raisehand.clicked");
  321. APP.conference.maybeToggleRaisedHand();
  322. },
  323. shortcutDescription: "keyboardShortcuts.raiseHand",
  324. content: "Raise Hand",
  325. i18n: "[content]toolbar.raiseHand"
  326. }
  327. };
  328. function dialpadButtonClicked() {
  329. //TODO show the dialpad box
  330. }
  331. function showSipNumberInput () {
  332. let defaultNumber = config.defaultSipNumber
  333. ? config.defaultSipNumber
  334. : '';
  335. let sipMsg = APP.translation.generateTranslationHTML("dialog.sipMsg");
  336. APP.UI.messageHandler.openTwoButtonDialog(
  337. null, null, null,
  338. `<h2>${sipMsg}</h2>
  339. <input
  340. name="sipNumber"
  341. type="text"
  342. value="${defaultNumber}"
  343. autofocus>`,
  344. false, "dialog.Dial",
  345. function (e, v, m, f) {
  346. if (v && f.sipNumber) {
  347. emitter.emit(UIEvents.SIP_DIAL, f.sipNumber);
  348. }
  349. },
  350. null, null, ':input:first'
  351. );
  352. }
  353. const Toolbar = {
  354. init (eventEmitter) {
  355. emitter = eventEmitter;
  356. // The toolbar is enabled by default.
  357. this.enabled = true;
  358. this.toolbarSelector = $("#mainToolbarContainer");
  359. this.extendedToolbarSelector = $("#extendedToolbar");
  360. // First hide all disabled buttons in the extended toolbar.
  361. // TODO: Make the extended toolbar dynamically created.
  362. UIUtil.hideDisabledButtons(defaultToolbarButtons);
  363. // Initialise the main toolbar. The main toolbar will only take into
  364. // account it's own configuration from interface_config.
  365. this._initMainToolbarButtons();
  366. Object.keys(defaultToolbarButtons).forEach(
  367. id => {
  368. if (UIUtil.isButtonEnabled(id)) {
  369. let button = defaultToolbarButtons[id];
  370. let buttonElement = document.getElementById(button.id);
  371. let tooltipPosition
  372. = (interfaceConfig.MAIN_TOOLBAR_BUTTONS
  373. .indexOf(id) > -1)
  374. ? "bottom" : "right";
  375. UIUtil.setTooltip( buttonElement,
  376. button.tooltipKey,
  377. tooltipPosition);
  378. if (button.shortcut)
  379. APP.keyboardshortcut.registerShortcut(
  380. button.shortcut,
  381. button.shortcutAttr,
  382. button.shortcutFunc,
  383. button.shortcutDescription
  384. );
  385. }
  386. }
  387. );
  388. Object.keys(buttonHandlers).forEach(
  389. buttonId => $(`#${buttonId}`).click(function(event) {
  390. !$(this).prop('disabled') && buttonHandlers[buttonId](event);
  391. })
  392. );
  393. APP.UI.addListener(UIEvents.SIDE_TOOLBAR_CONTAINER_TOGGLED,
  394. (containerId, isVisible) => {
  395. Toolbar._handleSideToolbarContainerToggled( containerId,
  396. isVisible);
  397. });
  398. APP.UI.addListener(UIEvents.LOCAL_RAISE_HAND_CHANGED,
  399. (isRaisedHand) => {
  400. this._setToggledState("toolbar_button_raisehand", isRaisedHand);
  401. });
  402. if(!APP.tokenData.isGuest) {
  403. $("#toolbar_button_profile").addClass("unclickable");
  404. UIUtil.removeTooltip(
  405. document.getElementById('toolbar_button_profile'));
  406. }
  407. },
  408. /**
  409. * Enables / disables the toolbar.
  410. * @param {e} set to {true} to enable the toolbar or {false}
  411. * to disable it
  412. */
  413. enable (e) {
  414. this.enabled = e;
  415. if (!e && this.isVisible())
  416. this.hide(false);
  417. },
  418. /**
  419. * Indicates if the bottom toolbar is currently enabled.
  420. * @return {this.enabled}
  421. */
  422. isEnabled() {
  423. return this.enabled;
  424. },
  425. /**
  426. * Updates the room invite url.
  427. */
  428. updateRoomUrl (newRoomUrl) {
  429. roomUrl = newRoomUrl;
  430. // If the invite dialog has been already opened we update the
  431. // information.
  432. let inviteLink = document.getElementById('inviteLinkRef');
  433. if (inviteLink) {
  434. inviteLink.value = roomUrl;
  435. inviteLink.select();
  436. $('#inviteLinkRef').parent()
  437. .find('button[value=true]').prop('disabled', false);
  438. }
  439. },
  440. /**
  441. * Unlocks the lock button state.
  442. */
  443. unlockLockButton () {
  444. if ($("#toolbar_button_security").hasClass("icon-security-locked"))
  445. UIUtil.buttonClick("toolbar_button_security",
  446. "icon-security icon-security-locked");
  447. },
  448. /**
  449. * Updates the lock button state to locked.
  450. */
  451. lockLockButton () {
  452. if ($("#toolbar_button_security").hasClass("icon-security"))
  453. UIUtil.buttonClick("toolbar_button_security",
  454. "icon-security icon-security-locked");
  455. },
  456. /**
  457. * Shows or hides authentication button
  458. * @param show <tt>true</tt> to show or <tt>false</tt> to hide
  459. */
  460. showAuthenticateButton (show) {
  461. if (UIUtil.isButtonEnabled('authentication') && show) {
  462. $('#authentication').css({display: "inline"});
  463. } else {
  464. $('#authentication').css({display: "none"});
  465. }
  466. },
  467. showEtherpadButton () {
  468. if (!$('#toolbar_button_etherpad').is(":visible")) {
  469. $('#toolbar_button_etherpad').css({display: 'inline-block'});
  470. }
  471. },
  472. // Shows or hides the 'shared video' button.
  473. showSharedVideoButton () {
  474. let $element = $('#toolbar_button_sharedvideo');
  475. if (UIUtil.isButtonEnabled('sharedvideo')
  476. && config.disableThirdPartyRequests !== true) {
  477. $element.css({display: "inline-block"});
  478. UIUtil.setTooltip($element.get(0), 'toolbar.sharedvideo', 'right');
  479. } else {
  480. $('#toolbar_button_sharedvideo').css({display: "none"});
  481. }
  482. },
  483. // checks whether desktop sharing is enabled and whether
  484. // we have params to start automatically sharing
  485. checkAutoEnableDesktopSharing () {
  486. if (UIUtil.isButtonEnabled('desktop')
  487. && config.autoEnableDesktopSharing) {
  488. emitter.emit(UIEvents.TOGGLE_SCREENSHARING);
  489. }
  490. },
  491. // Shows or hides SIP calls button
  492. showSipCallButton (show) {
  493. if (APP.conference.sipGatewayEnabled()
  494. && UIUtil.isButtonEnabled('sip') && show) {
  495. $('#toolbar_button_sip').css({display: "inline-block"});
  496. } else {
  497. $('#toolbar_button_sip').css({display: "none"});
  498. }
  499. },
  500. // Shows or hides the dialpad button
  501. showDialPadButton (show) {
  502. if (UIUtil.isButtonEnabled('dialpad') && show) {
  503. $('#toolbar_button_dialpad').css({display: "inline-block"});
  504. } else {
  505. $('#toolbar_button_dialpad').css({display: "none"});
  506. }
  507. },
  508. /**
  509. * Displays user authenticated identity name(login).
  510. * @param authIdentity identity name to be displayed.
  511. */
  512. setAuthenticatedIdentity (authIdentity) {
  513. if (authIdentity) {
  514. let selector = $('#toolbar_auth_identity');
  515. selector.css({display: "list-item"});
  516. selector.text(authIdentity);
  517. } else {
  518. $('#toolbar_auth_identity').css({display: "none"});
  519. }
  520. },
  521. /**
  522. * Shows/hides login button.
  523. * @param show <tt>true</tt> to show
  524. */
  525. showLoginButton (show) {
  526. if (UIUtil.isButtonEnabled('authentication') && show) {
  527. $('#toolbar_button_login').css({display: "list-item"});
  528. } else {
  529. $('#toolbar_button_login').css({display: "none"});
  530. }
  531. },
  532. /**
  533. * Shows/hides logout button.
  534. * @param show <tt>true</tt> to show
  535. */
  536. showLogoutButton (show) {
  537. if (UIUtil.isButtonEnabled('authentication') && show) {
  538. $('#toolbar_button_logout').css({display: "list-item"});
  539. } else {
  540. $('#toolbar_button_logout').css({display: "none"});
  541. }
  542. },
  543. /**
  544. * Update the state of the button. The button has blue glow if desktop
  545. * streaming is active.
  546. */
  547. updateDesktopSharingButtonState () {
  548. this._setToggledState( "toolbar_button_desktopsharing",
  549. APP.conference.isSharingScreen);
  550. },
  551. /**
  552. * Marks video icon as muted or not.
  553. *
  554. * @param {boolean} muted if icon should look like muted or not
  555. */
  556. toggleVideoIcon (muted) {
  557. $('#toolbar_button_camera').toggleClass("icon-camera-disabled", muted);
  558. this._setToggledState("toolbar_button_camera", muted);
  559. },
  560. /**
  561. * Marks video icon as disabled or not.
  562. * @param {boolean} disabled if icon should look like disabled or not
  563. */
  564. disableVideoIcon (disabled) {
  565. var $btn = $('#toolbar_button_camera');
  566. $btn
  567. .prop("disabled", disabled)
  568. .attr("data-i18n", disabled
  569. ? "[content]toolbar.cameraDisabled"
  570. : "[content]toolbar.videomute")
  571. .attr("shortcut", disabled ? "" : "toggleVideoPopover");
  572. disabled
  573. ? $btn.attr("disabled", "disabled")
  574. : $btn.removeAttr("disabled");
  575. APP.translation.translateElement($btn);
  576. disabled && this.toggleVideoIcon(disabled);
  577. },
  578. /**
  579. * Marks audio icon as muted or not.
  580. *
  581. * @param {boolean} muted if icon should look like muted or not
  582. */
  583. toggleAudioIcon(muted) {
  584. $('#toolbar_button_mute').toggleClass("icon-microphone",
  585. !muted).toggleClass("icon-mic-disabled", muted);
  586. this._setToggledState("toolbar_button_mute", muted);
  587. },
  588. /**
  589. * Marks audio icon as disabled or not.
  590. * @param {boolean} disabled if icon should look like disabled or not
  591. */
  592. disableAudioIcon (disabled) {
  593. var $btn = $('#toolbar_button_mute');
  594. $btn
  595. .prop("disabled", disabled)
  596. .attr("data-i18n", disabled
  597. ? "[content]toolbar.micDisabled"
  598. : "[content]toolbar.mute")
  599. .attr("shortcut", disabled ? "" : "mutePopover");
  600. disabled
  601. ? $btn.attr("disabled", "disabled")
  602. : $btn.removeAttr("disabled");
  603. APP.translation.translateElement($btn);
  604. disabled && this.toggleAudioIcon(disabled);
  605. },
  606. /**
  607. * Indicates if the toolbar is currently hovered.
  608. * @return {boolean} true if the toolbar is currently hovered,
  609. * false otherwise
  610. */
  611. isHovered() {
  612. var hovered = false;
  613. this.toolbarSelector.find('*').each(function () {
  614. let id = $(this).attr('id');
  615. if ($(`#${id}:hover`).length > 0) {
  616. hovered = true;
  617. // break each
  618. return false;
  619. }
  620. });
  621. if (hovered)
  622. return true;
  623. if ($("#bottomToolbar:hover").length > 0
  624. || $("#extendedToolbar:hover").length > 0
  625. || SideContainerToggler.isHovered()) {
  626. return true;
  627. }
  628. return false;
  629. },
  630. /**
  631. * Returns true if this toolbar is currently visible, or false otherwise.
  632. * @return <tt>true</tt> if currently visible, <tt>false</tt> - otherwise
  633. */
  634. isVisible() {
  635. return this.toolbarSelector.hasClass("slideInY");
  636. },
  637. /**
  638. * Hides the toolbar with animation or not depending on the animate
  639. * parameter.
  640. */
  641. hide() {
  642. this.toolbarSelector.toggleClass("slideInY").toggleClass("slideOutY");
  643. let slideInAnimation = (SideContainerToggler.isVisible)
  644. ? "slideInExtX"
  645. : "slideInX";
  646. let slideOutAnimation = (SideContainerToggler.isVisible)
  647. ? "slideOutExtX"
  648. : "slideOutX";
  649. this.extendedToolbarSelector.toggleClass(slideInAnimation)
  650. .toggleClass(slideOutAnimation);
  651. },
  652. /**
  653. * Shows the toolbar with animation or not depending on the animate
  654. * parameter.
  655. */
  656. show() {
  657. if (this.toolbarSelector.hasClass("slideOutY"))
  658. this.toolbarSelector.toggleClass("slideOutY");
  659. let slideInAnimation = (SideContainerToggler.isVisible)
  660. ? "slideInExtX"
  661. : "slideInX";
  662. let slideOutAnimation = (SideContainerToggler.isVisible)
  663. ? "slideOutExtX"
  664. : "slideOutX";
  665. if (this.extendedToolbarSelector.hasClass(slideOutAnimation))
  666. this.extendedToolbarSelector.toggleClass(slideOutAnimation);
  667. this.toolbarSelector.toggleClass("slideInY");
  668. this.extendedToolbarSelector.toggleClass(slideInAnimation);
  669. },
  670. registerClickListeners(listener) {
  671. $('#mainToolbarContainer').click(listener);
  672. $("#extendedToolbar").click(listener);
  673. },
  674. /**
  675. * Handles the side toolbar toggle.
  676. */
  677. _handleSideToolbarContainerToggled(containerId) {
  678. Object.keys(defaultToolbarButtons).forEach(
  679. id => {
  680. if (!UIUtil.isButtonEnabled(id))
  681. return;
  682. var button = defaultToolbarButtons[id];
  683. if (button.sideContainerId
  684. && button.sideContainerId === containerId) {
  685. UIUtil.buttonClick(button.id, "selected");
  686. return;
  687. }
  688. }
  689. );
  690. },
  691. /**
  692. * Initialise main toolbar buttons.
  693. */
  694. _initMainToolbarButtons() {
  695. interfaceConfig.MAIN_TOOLBAR_BUTTONS.forEach((value, index) => {
  696. if (value && value in defaultToolbarButtons) {
  697. let button = defaultToolbarButtons[value];
  698. this._addMainToolbarButton(
  699. button,
  700. (index === 0),
  701. (index === interfaceConfig.MAIN_TOOLBAR_BUTTONS.length -1));
  702. }
  703. });
  704. },
  705. /**
  706. * Adds the given button to the main (top) toolbar.
  707. *
  708. * @param {Object} the button to add.
  709. * @param {boolean} isFirst indicates if this is the first button in the
  710. * toolbar
  711. * @param {boolean} isLast indicates if this is the last button in the
  712. * toolbar
  713. */
  714. _addMainToolbarButton(button, isFirst, isLast) {
  715. let buttonElement = document.createElement("a");
  716. if (button.className)
  717. buttonElement.className = button.className
  718. + ((isFirst) ? " first" : "")
  719. + ((isLast) ? " last" : "");
  720. buttonElement.id = button.id;
  721. if (button.shortcutAttr)
  722. buttonElement.setAttribute("shortcut", button.shortcutAttr);
  723. if (button.content)
  724. buttonElement.setAttribute("content", button.content);
  725. if (button.i18n)
  726. buttonElement.setAttribute("data-i18n", button.i18n);
  727. buttonElement.setAttribute("data-container", "body");
  728. buttonElement.setAttribute("data-placement", "bottom");
  729. this._addPopups(buttonElement, button.popups);
  730. document.getElementById("mainToolbar")
  731. .appendChild(buttonElement);
  732. },
  733. _addPopups(buttonElement, popups = []) {
  734. popups.forEach((popup) => {
  735. let popupElement = document.createElement("ul");
  736. popupElement.id = popup.id;
  737. popupElement.className = popup.className;
  738. let liElement = document.createElement("li");
  739. liElement.setAttribute("data-i18n", popup.dataAttr);
  740. popupElement.appendChild(liElement);
  741. buttonElement.appendChild(popupElement);
  742. });
  743. },
  744. /**
  745. * Sets the toggled state of the given element depending on the isToggled
  746. * parameter.
  747. *
  748. * @param elementId the element identifier
  749. * @param isToggled indicates if the element should be toggled or untoggled
  750. */
  751. _setToggledState(elementId, isToggled) {
  752. $("#" + elementId).toggleClass("toggled", isToggled);
  753. }
  754. };
  755. export default Toolbar;