您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Toolbar.js 28KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860
  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. document.querySelector('#authenticationContainer')
  404. .classList.toggle('hide', !show);
  405. },
  406. showEtherpadButton () {
  407. if (!$('#toolbar_button_etherpad').is(":visible")) {
  408. $('#toolbar_button_etherpad').css({display: 'inline-block'});
  409. }
  410. },
  411. // Shows or hides the 'shared video' button.
  412. showSharedVideoButton () {
  413. if (!UIUtil.isButtonEnabled('sharedvideo')) {
  414. return;
  415. }
  416. var el = document.querySelector('#toolbar_button_sharedvideo');
  417. UIUtil.setTooltip(el, 'toolbar.sharedvideo', 'right');
  418. el.classList.toggle('hide', config.disableThirdPartyRequests === true);
  419. },
  420. // checks whether desktop sharing is enabled and whether
  421. // we have params to start automatically sharing
  422. checkAutoEnableDesktopSharing () {
  423. if (UIUtil.isButtonEnabled('desktop')
  424. && config.autoEnableDesktopSharing) {
  425. emitter.emit(UIEvents.TOGGLE_SCREENSHARING);
  426. }
  427. },
  428. // Shows or hides SIP calls button
  429. showSipCallButton (show) {
  430. if (!UIUtil.isButtonEnabled('sip')) {
  431. return;
  432. }
  433. document.querySelector('#toolbar_button_sip').classList
  434. .toggle('hide', !(show && APP.conference.sipGatewayEnabled()));
  435. },
  436. // Shows or hides the dialpad button
  437. showDialPadButton (show) {
  438. if (!UIUtil.isButtonEnabled('dialpad')) {
  439. return;
  440. }
  441. document.querySelector('#toolbar_button_dialpad')
  442. .classList.toggle('hide', !show);
  443. },
  444. /**
  445. * Displays user authenticated identity name(login).
  446. * @param authIdentity identity name to be displayed.
  447. */
  448. setAuthenticatedIdentity (authIdentity) {
  449. let selector = $('#toolbar_auth_identity');
  450. selector.text(authIdentity ? authIdentity : '');
  451. selector.get(0).classList.toggle('hide', !authIdentity);
  452. },
  453. /**
  454. * Shows/hides login button.
  455. * @param show <tt>true</tt> to show
  456. */
  457. showLoginButton (show) {
  458. document.querySelector('#toolbar_button_login')
  459. .classList.toggle('hide', !show);
  460. },
  461. /**
  462. * Shows/hides logout button.
  463. * @param show <tt>true</tt> to show
  464. */
  465. showLogoutButton (show) {
  466. document.querySelector('#toolbar_button_logout')
  467. .classList.toggle('hide', !show);
  468. },
  469. /**
  470. * Update the state of the button. The button has blue glow if desktop
  471. * streaming is active.
  472. */
  473. updateDesktopSharingButtonState () {
  474. this._setToggledState( "toolbar_button_desktopsharing",
  475. APP.conference.isSharingScreen);
  476. },
  477. /**
  478. * Marks video icon as muted or not.
  479. *
  480. * @param {boolean} muted if icon should look like muted or not
  481. */
  482. toggleVideoIcon (muted) {
  483. $('#toolbar_button_camera').toggleClass("icon-camera-disabled", muted);
  484. this._setToggledState("toolbar_button_camera", muted);
  485. },
  486. /**
  487. * Enables / disables audio toolbar button.
  488. *
  489. * @param {boolean} enabled indicates if the button should be enabled
  490. * or disabled
  491. */
  492. setVideoIconEnabled (enabled) {
  493. this._setMediaIconEnabled(
  494. '#toolbar_button_camera',
  495. enabled,
  496. /* data-i18n attribute value */
  497. `[content]toolbar.${enabled ? 'videomute' : 'cameraDisabled'}`,
  498. /* shortcut attribute value */
  499. 'toggleVideoPopover');
  500. enabled || this.toggleVideoIcon(!enabled);
  501. },
  502. /**
  503. * Enables/disables the toolbar button associated with a specific media such
  504. * as audio or video.
  505. *
  506. * @param {string} btn - The jQuery selector <tt>string</tt> which
  507. * identifies the toolbar button to be enabled/disabled.
  508. * @param {boolean} enabled - <tt>true</tt> to enable the specified
  509. * <tt>btn</tt> or <tt>false</tt> to disable it.
  510. * @param {string} dataI18n - The value to assign to the <tt>data-i18n</tt>
  511. * attribute of the specified <tt>btn</tt>.
  512. * @param {string} shortcut - The value, if any, to assign to the
  513. * <tt>shortcut</tt> attribute of the specified <tt>btn</tt> if the toolbar
  514. * button is enabled.
  515. */
  516. _setMediaIconEnabled(btn, enabled, dataI18n, shortcut) {
  517. const $btn = $(btn);
  518. $btn
  519. .prop('disabled', !enabled)
  520. .attr('data-i18n', dataI18n)
  521. .attr('shortcut', enabled && shortcut ? shortcut : '');
  522. enabled
  523. ? $btn.removeAttr('disabled')
  524. : $btn.attr('disabled', 'disabled');
  525. APP.translation.translateElement($btn);
  526. },
  527. /**
  528. * Marks audio icon as muted or not.
  529. *
  530. * @param {boolean} muted if icon should look like muted or not
  531. */
  532. toggleAudioIcon(muted) {
  533. $('#toolbar_button_mute')
  534. .toggleClass("icon-microphone", !muted)
  535. .toggleClass("icon-mic-disabled", muted);
  536. this._setToggledState("toolbar_button_mute", muted);
  537. },
  538. /**
  539. * Enables / disables audio toolbar button.
  540. *
  541. * @param {boolean} enabled indicates if the button should be enabled
  542. * or disabled
  543. */
  544. setAudioIconEnabled (enabled) {
  545. this._setMediaIconEnabled(
  546. '#toolbar_button_mute',
  547. enabled,
  548. /* data-i18n attribute value */
  549. `[content]toolbar.${enabled ? 'mute' : 'micDisabled'}`,
  550. /* shortcut attribute value */
  551. 'mutePopover');
  552. enabled || this.toggleAudioIcon(!enabled);
  553. },
  554. /**
  555. * Indicates if the toolbar is currently hovered.
  556. * @return {boolean} true if the toolbar is currently hovered,
  557. * false otherwise
  558. */
  559. isHovered() {
  560. var hovered = false;
  561. this.toolbarSelector.find('*').each(function () {
  562. let id = $(this).attr('id');
  563. if ($(`#${id}:hover`).length > 0) {
  564. hovered = true;
  565. // break each
  566. return false;
  567. }
  568. });
  569. if (hovered)
  570. return true;
  571. if ($("#bottomToolbar:hover").length > 0
  572. || $("#extendedToolbar:hover").length > 0
  573. || SideContainerToggler.isHovered()) {
  574. return true;
  575. }
  576. return false;
  577. },
  578. /**
  579. * Returns true if this toolbar is currently visible, or false otherwise.
  580. * @return <tt>true</tt> if currently visible, <tt>false</tt> - otherwise
  581. */
  582. isVisible() {
  583. return this.toolbarSelector.hasClass("fadeIn");
  584. },
  585. /**
  586. * Hides the toolbar with animation or not depending on the animate
  587. * parameter.
  588. */
  589. hide() {
  590. this.toolbarSelector
  591. .removeClass("fadeIn")
  592. .addClass("fadeOut");
  593. let slideInAnimation = (SideContainerToggler.isVisible)
  594. ? "slideInExtX"
  595. : "slideInX";
  596. let slideOutAnimation = (SideContainerToggler.isVisible)
  597. ? "slideOutExtX"
  598. : "slideOutX";
  599. this.extendedToolbarSelector.toggleClass(slideInAnimation)
  600. .toggleClass(slideOutAnimation);
  601. },
  602. /**
  603. * Shows the toolbar with animation or not depending on the animate
  604. * parameter.
  605. */
  606. show() {
  607. if (this.toolbarSelector.hasClass("fadeOut")) {
  608. this.toolbarSelector.removeClass("fadeOut");
  609. }
  610. let slideInAnimation = (SideContainerToggler.isVisible)
  611. ? "slideInExtX"
  612. : "slideInX";
  613. let slideOutAnimation = (SideContainerToggler.isVisible)
  614. ? "slideOutExtX"
  615. : "slideOutX";
  616. if (this.extendedToolbarSelector.hasClass(slideOutAnimation)) {
  617. this.extendedToolbarSelector.toggleClass(slideOutAnimation);
  618. }
  619. this.toolbarSelector.addClass("fadeIn");
  620. this.extendedToolbarSelector.toggleClass(slideInAnimation);
  621. },
  622. registerClickListeners(listener) {
  623. $('#mainToolbarContainer').click(listener);
  624. $("#extendedToolbar").click(listener);
  625. },
  626. /**
  627. * Handles the side toolbar toggle.
  628. *
  629. * @param {string} containerId the identifier of the container element
  630. */
  631. _handleSideToolbarContainerToggled(containerId) {
  632. Object.keys(defaultToolbarButtons).forEach(
  633. id => {
  634. if (!UIUtil.isButtonEnabled(id))
  635. return;
  636. var button = defaultToolbarButtons[id];
  637. if (button.sideContainerId
  638. && button.sideContainerId === containerId) {
  639. UIUtil.buttonClick(button.id, "selected");
  640. return;
  641. }
  642. }
  643. );
  644. },
  645. /**
  646. * Handles full screen toggled.
  647. *
  648. * @param {boolean} isFullScreen indicates if we're currently in full
  649. * screen mode
  650. */
  651. _handleFullScreenToggled(isFullScreen) {
  652. let element
  653. = document.getElementById("toolbar_button_fullScreen");
  654. element.className = isFullScreen
  655. ? element.className
  656. .replace("icon-full-screen", "icon-exit-full-screen")
  657. : element.className
  658. .replace("icon-exit-full-screen", "icon-full-screen");
  659. Toolbar._setToggledState("toolbar_button_fullScreen", isFullScreen);
  660. },
  661. /**
  662. * Initialise toolbar buttons.
  663. */
  664. _initToolbarButtons() {
  665. interfaceConfig.TOOLBAR_BUTTONS.forEach((value, index) => {
  666. let place = getToolbarButtonPlace(value);
  667. if (value && value in defaultToolbarButtons) {
  668. let button = defaultToolbarButtons[value];
  669. this._addToolbarButton(
  670. button,
  671. place,
  672. (interfaceConfig.MAIN_TOOLBAR_SPLITTER_INDEX !== undefined
  673. && index
  674. === interfaceConfig.MAIN_TOOLBAR_SPLITTER_INDEX));
  675. }
  676. });
  677. },
  678. /**
  679. * Adds the given button to the main (top) or extended (left) toolbar.
  680. *
  681. * @param {Object} the button to add.
  682. * @param {boolean} isFirst indicates if this is the first button in the
  683. * toolbar
  684. * @param {boolean} isLast indicates if this is the last button in the
  685. * toolbar
  686. * @param {boolean} isSplitter if this button is a splitter button for
  687. * the dialog, which means that a special splitter style will be applied
  688. */
  689. _addToolbarButton(button, place, isSplitter) {
  690. const places = {
  691. main: 'mainToolbar',
  692. extended: 'extendedToolbarButtons'
  693. };
  694. let id = places[place];
  695. let buttonElement = document.createElement("a");
  696. if (button.className) {
  697. buttonElement.className = button.className;
  698. }
  699. if (isSplitter) {
  700. let splitter = document.createElement('span');
  701. splitter.className = 'toolbar__splitter';
  702. document.getElementById(id).appendChild(splitter);
  703. }
  704. buttonElement.id = button.id;
  705. if (button.html)
  706. buttonElement.innerHTML = button.html;
  707. //TODO: remove it after UI.updateDTMFSupport fix
  708. if (button.hidden)
  709. buttonElement.style.display = 'none';
  710. if (button.shortcutAttr)
  711. buttonElement.setAttribute("shortcut", button.shortcutAttr);
  712. if (button.content)
  713. buttonElement.setAttribute("content", button.content);
  714. if (button.i18n)
  715. buttonElement.setAttribute("data-i18n", button.i18n);
  716. buttonElement.setAttribute("data-container", "body");
  717. buttonElement.setAttribute("data-placement", "bottom");
  718. this._addPopups(buttonElement, button.popups);
  719. document.getElementById(id)
  720. .appendChild(buttonElement);
  721. },
  722. _addPopups(buttonElement, popups = []) {
  723. popups.forEach((popup) => {
  724. let popupElement = document.createElement("ul");
  725. popupElement.id = popup.id;
  726. popupElement.className = popup.className;
  727. let liElement = document.createElement("li");
  728. liElement.setAttribute("data-i18n", popup.dataAttr);
  729. popupElement.appendChild(liElement);
  730. buttonElement.appendChild(popupElement);
  731. });
  732. },
  733. /**
  734. * Sets the toggled state of the given element depending on the isToggled
  735. * parameter.
  736. *
  737. * @param elementId the element identifier
  738. * @param isToggled indicates if the element should be toggled or untoggled
  739. */
  740. _setToggledState(elementId, isToggled) {
  741. $("#" + elementId).toggleClass("toggled", isToggled);
  742. },
  743. /**
  744. * Sets Shortcuts and Tooltips for all toolbar buttons
  745. *
  746. * @private
  747. */
  748. _setShortcutsAndTooltips() {
  749. Object.keys(defaultToolbarButtons).forEach(
  750. id => {
  751. if (UIUtil.isButtonEnabled(id)) {
  752. let button = defaultToolbarButtons[id];
  753. let buttonElement = document.getElementById(button.id);
  754. if (!buttonElement) return false;
  755. let tooltipPosition
  756. = (interfaceConfig.MAIN_TOOLBAR_BUTTONS
  757. .indexOf(id) > -1)
  758. ? "bottom" : "right";
  759. UIUtil.setTooltip( buttonElement,
  760. button.tooltipKey,
  761. tooltipPosition);
  762. if (button.shortcut)
  763. APP.keyboardshortcut.registerShortcut(
  764. button.shortcut,
  765. button.shortcutAttr,
  766. button.shortcutFunc,
  767. button.shortcutDescription
  768. );
  769. }
  770. }
  771. );
  772. },
  773. /**
  774. * Sets Handlers for all toolbar buttons
  775. *
  776. * @private
  777. */
  778. _setButtonHandlers() {
  779. Object.keys(buttonHandlers).forEach(
  780. buttonId => $(`#${buttonId}`).click(function(event) {
  781. !$(this).prop('disabled') && buttonHandlers[buttonId](event);
  782. })
  783. );
  784. }
  785. };
  786. export default Toolbar;