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

Toolbar.js 29KB

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