Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

Toolbar.js 29KB

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