You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Toolbar.js 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. /* global APP, $, config, interfaceConfig, JitsiMeetJS */
  2. /* jshint -W101 */
  3. import UIUtil from '../util/UIUtil';
  4. import UIEvents from '../../../service/UI/UIEvents';
  5. import SideContainerToggler from "../side_pannels/SideContainerToggler";
  6. let roomUrl = null;
  7. let emitter = null;
  8. /**
  9. * Opens the invite link dialog.
  10. */
  11. function openLinkDialog () {
  12. let inviteAttributes;
  13. if (roomUrl === null) {
  14. inviteAttributes = 'data-i18n="[value]roomUrlDefaultMsg" value="' +
  15. APP.translation.translateString("roomUrlDefaultMsg") + '"';
  16. } else {
  17. inviteAttributes = "value=\"" + encodeURI(roomUrl) + "\"";
  18. }
  19. APP.UI.messageHandler.openTwoButtonDialog(
  20. "dialog.shareLink", null, null,
  21. `<input id="inviteLinkRef" type="text" ${inviteAttributes} onclick="this.select();" readonly>`,
  22. false, "dialog.Invite",
  23. function (e, v) {
  24. if (v && roomUrl) {
  25. JitsiMeetJS.analytics.sendEvent('toolbar.invite.button');
  26. emitter.emit(UIEvents.USER_INVITED, roomUrl);
  27. }
  28. else {
  29. JitsiMeetJS.analytics.sendEvent('toolbar.invite.cancel');
  30. }
  31. },
  32. function (event) {
  33. if (roomUrl) {
  34. document.getElementById('inviteLinkRef').select();
  35. } else {
  36. if (event && event.target) {
  37. $(event.target).find('button[value=true]').prop('disabled', true);
  38. }
  39. }
  40. },
  41. function (e, v, m, f) {
  42. if(!v && !m && !f)
  43. JitsiMeetJS.analytics.sendEvent('toolbar.invite.close');
  44. }
  45. );
  46. }
  47. const buttonHandlers = {
  48. "toolbar_button_mute": function () {
  49. let sharedVideoManager = APP.UI.getSharedVideoManager();
  50. if (APP.conference.audioMuted) {
  51. // If there's a shared video with the volume "on" and we aren't
  52. // the video owner, we warn the user
  53. // that currently it's not possible to unmute.
  54. if (sharedVideoManager
  55. && sharedVideoManager.isSharedVideoVolumeOn()
  56. && !sharedVideoManager.isSharedVideoOwner()) {
  57. UIUtil.animateShowElement(
  58. $("#unableToUnmutePopup"), true, 5000);
  59. }
  60. else {
  61. JitsiMeetJS.analytics.sendEvent('toolbar.audio.unmuted');
  62. emitter.emit(UIEvents.AUDIO_MUTED, false, true);
  63. }
  64. } else {
  65. JitsiMeetJS.analytics.sendEvent('toolbar.audio.muted');
  66. emitter.emit(UIEvents.AUDIO_MUTED, true, true);
  67. }
  68. },
  69. "toolbar_button_camera": function () {
  70. if (APP.conference.videoMuted) {
  71. JitsiMeetJS.analytics.sendEvent('toolbar.video.enabled');
  72. emitter.emit(UIEvents.VIDEO_MUTED, false);
  73. } else {
  74. JitsiMeetJS.analytics.sendEvent('toolbar.video.disabled');
  75. emitter.emit(UIEvents.VIDEO_MUTED, true);
  76. }
  77. },
  78. "toolbar_button_security": function () {
  79. JitsiMeetJS.analytics.sendEvent('toolbar.lock.clicked');
  80. emitter.emit(UIEvents.ROOM_LOCK_CLICKED);
  81. },
  82. "toolbar_button_link": function () {
  83. JitsiMeetJS.analytics.sendEvent('toolbar.invite.clicked');
  84. openLinkDialog();
  85. },
  86. "toolbar_button_chat": function () {
  87. JitsiMeetJS.analytics.sendEvent('toolbar.chat.toggled');
  88. emitter.emit(UIEvents.TOGGLE_CHAT);
  89. },
  90. "toolbar_contact_list": function () {
  91. JitsiMeetJS.analytics.sendEvent(
  92. 'toolbar.contacts.toggled');
  93. emitter.emit(UIEvents.TOGGLE_CONTACT_LIST);
  94. },
  95. "toolbar_button_etherpad": function () {
  96. JitsiMeetJS.analytics.sendEvent('toolbar.etherpad.clicked');
  97. emitter.emit(UIEvents.ETHERPAD_CLICKED);
  98. },
  99. "toolbar_button_sharedvideo": function () {
  100. JitsiMeetJS.analytics.sendEvent('toolbar.sharedvideo.clicked');
  101. emitter.emit(UIEvents.SHARED_VIDEO_CLICKED);
  102. },
  103. "toolbar_button_desktopsharing": function () {
  104. if (APP.conference.isSharingScreen) {
  105. JitsiMeetJS.analytics.sendEvent('toolbar.screen.disabled');
  106. } else {
  107. JitsiMeetJS.analytics.sendEvent('toolbar.screen.enabled');
  108. }
  109. emitter.emit(UIEvents.TOGGLE_SCREENSHARING);
  110. },
  111. "toolbar_button_fullScreen": function() {
  112. JitsiMeetJS.analytics.sendEvent('toolbar.fullscreen.enabled');
  113. UIUtil.buttonClick("#toolbar_button_fullScreen",
  114. "icon-full-screen icon-exit-full-screen");
  115. emitter.emit(UIEvents.FULLSCREEN_TOGGLE);
  116. },
  117. "toolbar_button_sip": function () {
  118. JitsiMeetJS.analytics.sendEvent('toolbar.sip.clicked');
  119. showSipNumberInput();
  120. },
  121. "toolbar_button_dialpad": function () {
  122. JitsiMeetJS.analytics.sendEvent('toolbar.sip.dialpad.clicked');
  123. dialpadButtonClicked();
  124. },
  125. "toolbar_button_settings": function () {
  126. JitsiMeetJS.analytics.sendEvent('toolbar.settings.toggled');
  127. emitter.emit(UIEvents.TOGGLE_SETTINGS);
  128. },
  129. "toolbar_button_hangup": function () {
  130. JitsiMeetJS.analytics.sendEvent('toolbar.hangup');
  131. emitter.emit(UIEvents.HANGUP);
  132. },
  133. "toolbar_button_login": function () {
  134. JitsiMeetJS.analytics.sendEvent('toolbar.authenticate.login.clicked');
  135. emitter.emit(UIEvents.AUTH_CLICKED);
  136. },
  137. "toolbar_button_logout": function () {
  138. JitsiMeetJS.analytics.sendEvent('toolbar.authenticate.logout.clicked');
  139. // Ask for confirmation
  140. APP.UI.messageHandler.openTwoButtonDialog(
  141. "dialog.logoutTitle",
  142. null,
  143. "dialog.logoutQuestion",
  144. null,
  145. false,
  146. "dialog.Yes",
  147. function (evt, yes) {
  148. if (yes) {
  149. emitter.emit(UIEvents.LOGOUT);
  150. }
  151. }
  152. );
  153. },
  154. "toolbar_film_strip": function () {
  155. JitsiMeetJS.analytics.sendEvent(
  156. 'bottomtoolbar.filmstrip.toggled');
  157. emitter.emit(UIEvents.TOGGLE_FILM_STRIP);
  158. }
  159. };
  160. const defaultToolbarButtons = {
  161. 'microphone': {
  162. id: '#toolbar_button_mute',
  163. shortcut: 'M',
  164. shortcutAttr: 'mutePopover',
  165. shortcutFunc: function() {
  166. JitsiMeetJS.analytics.sendEvent('shortcut.audiomute.toggled');
  167. APP.conference.toggleAudioMuted();
  168. },
  169. shortcutDescription: "keyboardShortcuts.mute"
  170. },
  171. 'camera': {
  172. id: '#toolbar_button_camera',
  173. shortcut: 'V',
  174. shortcutAttr: 'toggleVideoPopover',
  175. shortcutFunc: function() {
  176. JitsiMeetJS.analytics.sendEvent('shortcut.videomute.toggled');
  177. APP.conference.toggleVideoMuted();
  178. },
  179. shortcutDescription: "keyboardShortcuts.videoMute"
  180. },
  181. 'desktop': {
  182. id: '#toolbar_button_desktopsharing',
  183. shortcut: 'D',
  184. shortcutAttr: 'toggleDesktopSharingPopover',
  185. shortcutFunc: function() {
  186. JitsiMeetJS.analytics.sendEvent('shortcut.screen.toggled');
  187. APP.conference.toggleScreenSharing();
  188. },
  189. shortcutDescription: "keyboardShortcuts.toggleScreensharing"
  190. },
  191. 'security': {
  192. id: '#toolbar_button_security'
  193. },
  194. 'invite': {
  195. id: '#toolbar_button_link'
  196. },
  197. 'chat': {
  198. id: '#toolbar_button_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. },
  208. 'contacts': {
  209. id: '#toolbar_contact_list',
  210. sideContainerId: "contacts_container"
  211. },
  212. 'etherpad': {
  213. id: '#toolbar_button_etherpad'
  214. },
  215. 'fullscreen': {
  216. id: '#toolbar_button_fullScreen'
  217. },
  218. 'settings': {
  219. id: '#toolbar_button_settings',
  220. sideContainerId: "settings_container"
  221. },
  222. 'hangup': {
  223. id: '#toolbar_button_hangup'
  224. },
  225. 'filmstrip': {
  226. id: '#toolbar_film_strip',
  227. shortcut: "F",
  228. shortcutAttr: "filmstripPopover",
  229. shortcutFunc: function() {
  230. JitsiMeetJS.analytics.sendEvent("shortcut.film.toggled");
  231. APP.UI.toggleFilmStrip();
  232. },
  233. shortcutDescription: "keyboardShortcuts.toggleFilmstrip"
  234. }
  235. };
  236. function dialpadButtonClicked() {
  237. //TODO show the dialpad box
  238. }
  239. function showSipNumberInput () {
  240. let defaultNumber = config.defaultSipNumber
  241. ? config.defaultSipNumber
  242. : '';
  243. let sipMsg = APP.translation.generateTranslationHTML("dialog.sipMsg");
  244. APP.UI.messageHandler.openTwoButtonDialog(
  245. null, null, null,
  246. `<h2>${sipMsg}</h2>
  247. <input name="sipNumber" type="text" value="${defaultNumber}" autofocus>`,
  248. false, "dialog.Dial",
  249. function (e, v, m, f) {
  250. if (v && f.sipNumber) {
  251. emitter.emit(UIEvents.SIP_DIAL, f.sipNumber);
  252. }
  253. },
  254. null, null, ':input:first'
  255. );
  256. }
  257. const Toolbar = {
  258. init (eventEmitter) {
  259. emitter = eventEmitter;
  260. // The toolbar is enabled by default.
  261. this.enabled = true;
  262. this.toolbarSelector = $("#mainToolbarContainer");
  263. this.extendedToolbarSelector = $("#extendedToolbar");
  264. UIUtil.hideDisabledButtons(defaultToolbarButtons);
  265. Object.keys(defaultToolbarButtons).forEach(
  266. id => {
  267. if (UIUtil.isButtonEnabled(id)) {
  268. var button = defaultToolbarButtons[id];
  269. if (button.shortcut)
  270. APP.keyboardshortcut.registerShortcut(
  271. button.shortcut,
  272. button.shortcutAttr,
  273. button.shortcutFunc,
  274. button.shortcutDescription
  275. );
  276. }
  277. }
  278. );
  279. Object.keys(buttonHandlers).forEach(
  280. buttonId => $(`#${buttonId}`).click(function(event) {
  281. !$(this).prop('disabled') && buttonHandlers[buttonId](event);
  282. })
  283. );
  284. APP.UI.addListener(UIEvents.SIDE_TOOLBAR_CONTAINER_TOGGLED,
  285. function(containerId, isVisible) {
  286. Toolbar._handleSideToolbarContainerToggled( containerId,
  287. isVisible);
  288. });
  289. },
  290. /**
  291. * Enables / disables the toolbar.
  292. * @param {e} set to {true} to enable the toolbar or {false}
  293. * to disable it
  294. */
  295. enable (e) {
  296. this.enabled = e;
  297. if (!e && this.isVisible())
  298. this.hide(false);
  299. },
  300. /**
  301. * Indicates if the bottom toolbar is currently enabled.
  302. * @return {this.enabled}
  303. */
  304. isEnabled() {
  305. return this.enabled;
  306. },
  307. /**
  308. * Updates the room invite url.
  309. */
  310. updateRoomUrl (newRoomUrl) {
  311. roomUrl = newRoomUrl;
  312. // If the invite dialog has been already opened we update the
  313. // information.
  314. let inviteLink = document.getElementById('inviteLinkRef');
  315. if (inviteLink) {
  316. inviteLink.value = roomUrl;
  317. inviteLink.select();
  318. $('#inviteLinkRef').parent()
  319. .find('button[value=true]').prop('disabled', false);
  320. }
  321. },
  322. /**
  323. * Unlocks the lock button state.
  324. */
  325. unlockLockButton () {
  326. if ($("#toolbar_button_security").hasClass("icon-security-locked"))
  327. UIUtil.buttonClick("#toolbar_button_security",
  328. "icon-security icon-security-locked");
  329. },
  330. /**
  331. * Updates the lock button state to locked.
  332. */
  333. lockLockButton () {
  334. if ($("#toolbar_button_security").hasClass("icon-security"))
  335. UIUtil.buttonClick("#toolbar_button_security",
  336. "icon-security icon-security-locked");
  337. },
  338. /**
  339. * Shows or hides authentication button
  340. * @param show <tt>true</tt> to show or <tt>false</tt> to hide
  341. */
  342. showAuthenticateButton (show) {
  343. if (UIUtil.isButtonEnabled('authentication') && show) {
  344. $('#authentication').css({display: "inline"});
  345. } else {
  346. $('#authentication').css({display: "none"});
  347. }
  348. },
  349. showEtherpadButton () {
  350. if (!$('#toolbar_button_etherpad').is(":visible")) {
  351. $('#toolbar_button_etherpad').css({display: 'inline-block'});
  352. }
  353. },
  354. // Shows or hides the 'shared video' button.
  355. showSharedVideoButton () {
  356. if (UIUtil.isButtonEnabled('sharedvideo')
  357. && config.disableThirdPartyRequests !== true) {
  358. $('#toolbar_button_sharedvideo').css({display: "inline-block"});
  359. } else {
  360. $('#toolbar_button_sharedvideo').css({display: "none"});
  361. }
  362. },
  363. // checks whether desktop sharing is enabled and whether
  364. // we have params to start automatically sharing
  365. checkAutoEnableDesktopSharing () {
  366. if (UIUtil.isButtonEnabled('desktop')
  367. && config.autoEnableDesktopSharing) {
  368. emitter.emit(UIEvents.TOGGLE_SCREENSHARING);
  369. }
  370. },
  371. // Shows or hides SIP calls button
  372. showSipCallButton (show) {
  373. if (APP.conference.sipGatewayEnabled()
  374. && UIUtil.isButtonEnabled('sip') && show) {
  375. $('#toolbar_button_sip').css({display: "inline-block"});
  376. } else {
  377. $('#toolbar_button_sip').css({display: "none"});
  378. }
  379. },
  380. // Shows or hides the dialpad button
  381. showDialPadButton (show) {
  382. if (UIUtil.isButtonEnabled('dialpad') && show) {
  383. $('#toolbar_button_dialpad').css({display: "inline-block"});
  384. } else {
  385. $('#toolbar_button_dialpad').css({display: "none"});
  386. }
  387. },
  388. /**
  389. * Displays user authenticated identity name(login).
  390. * @param authIdentity identity name to be displayed.
  391. */
  392. setAuthenticatedIdentity (authIdentity) {
  393. if (authIdentity) {
  394. let selector = $('#toolbar_auth_identity');
  395. selector.css({display: "list-item"});
  396. selector.text(authIdentity);
  397. } else {
  398. $('#toolbar_auth_identity').css({display: "none"});
  399. }
  400. },
  401. /**
  402. * Shows/hides login button.
  403. * @param show <tt>true</tt> to show
  404. */
  405. showLoginButton (show) {
  406. if (UIUtil.isButtonEnabled('authentication') && show) {
  407. $('#toolbar_button_login').css({display: "list-item"});
  408. } else {
  409. $('#toolbar_button_login').css({display: "none"});
  410. }
  411. },
  412. /**
  413. * Shows/hides logout button.
  414. * @param show <tt>true</tt> to show
  415. */
  416. showLogoutButton (show) {
  417. if (UIUtil.isButtonEnabled('authentication') && show) {
  418. $('#toolbar_button_logout').css({display: "list-item"});
  419. } else {
  420. $('#toolbar_button_logout').css({display: "none"});
  421. }
  422. },
  423. /**
  424. * Update the state of the button. The button has blue glow if desktop
  425. * streaming is active.
  426. */
  427. updateDesktopSharingButtonState () {
  428. let button = $("#toolbar_button_desktopsharing");
  429. if (APP.conference.isSharingScreen) {
  430. button.addClass("glow");
  431. } else {
  432. button.removeClass("glow");
  433. }
  434. },
  435. /**
  436. * Marks video icon as muted or not.
  437. * @param {boolean} muted if icon should look like muted or not
  438. */
  439. markVideoIconAsMuted (muted) {
  440. $('#toolbar_button_camera').toggleClass("icon-camera-disabled", muted);
  441. },
  442. /**
  443. * Marks video icon as disabled or not.
  444. * @param {boolean} disabled if icon should look like disabled or not
  445. */
  446. markVideoIconAsDisabled (disabled) {
  447. var $btn = $('#toolbar_button_camera');
  448. $btn
  449. .prop("disabled", disabled)
  450. .attr("data-i18n", disabled
  451. ? "[content]toolbar.cameraDisabled"
  452. : "[content]toolbar.videomute")
  453. .attr("shortcut", disabled ? "" : "toggleVideoPopover");
  454. disabled
  455. ? $btn.attr("disabled", "disabled")
  456. : $btn.removeAttr("disabled");
  457. APP.translation.translateElement($btn);
  458. disabled && this.markVideoIconAsMuted(disabled);
  459. },
  460. /**
  461. * Marks audio icon as muted or not.
  462. * @param {boolean} muted if icon should look like muted or not
  463. */
  464. markAudioIconAsMuted (muted) {
  465. $('#toolbar_button_mute').toggleClass("icon-microphone",
  466. !muted).toggleClass("icon-mic-disabled", muted);
  467. },
  468. /**
  469. * Marks audio icon as disabled or not.
  470. * @param {boolean} disabled if icon should look like disabled or not
  471. */
  472. markAudioIconAsDisabled (disabled) {
  473. var $btn = $('#toolbar_button_mute');
  474. $btn
  475. .prop("disabled", disabled)
  476. .attr("data-i18n", disabled
  477. ? "[content]toolbar.micDisabled"
  478. : "[content]toolbar.mute")
  479. .attr("shortcut", disabled ? "" : "mutePopover");
  480. disabled
  481. ? $btn.attr("disabled", "disabled")
  482. : $btn.removeAttr("disabled");
  483. APP.translation.translateElement($btn);
  484. disabled && this.markAudioIconAsMuted(disabled);
  485. },
  486. /**
  487. * Indicates if the toolbar is currently hovered.
  488. * @return {boolean} true if the toolbar is currently hovered,
  489. * false otherwise
  490. */
  491. isHovered() {
  492. var hovered = false;
  493. this.toolbarSelector.find('*').each(function () {
  494. let id = $(this).attr('id');
  495. if ($(`#${id}:hover`).length > 0) {
  496. hovered = true;
  497. // break each
  498. return false;
  499. }
  500. });
  501. if (hovered)
  502. return true;
  503. if ($("#bottomToolbar:hover").length > 0
  504. || $("#extendedToolbar:hover").length > 0
  505. || SideContainerToggler.isHovered()) {
  506. return true;
  507. }
  508. return false;
  509. },
  510. /**
  511. * Returns true if this toolbar is currently visible, or false otherwise.
  512. * @return <tt>true</tt> if currently visible, <tt>false</tt> - otherwise
  513. */
  514. isVisible() {
  515. return this.toolbarSelector.hasClass("slideInY");
  516. },
  517. /**
  518. * Hides the toolbar with animation or not depending on the animate
  519. * parameter.
  520. */
  521. hide() {
  522. this.toolbarSelector.toggleClass("slideInY").toggleClass("slideOutY");
  523. let slideInAnimation = (SideContainerToggler.isVisible)
  524. ? "slideInExtX"
  525. : "slideInX";
  526. let slideOutAnimation = (SideContainerToggler.isVisible)
  527. ? "slideOutExtX"
  528. : "slideOutX";
  529. this.extendedToolbarSelector.toggleClass(slideInAnimation)
  530. .toggleClass(slideOutAnimation);
  531. },
  532. /**
  533. * Shows the toolbar with animation or not depending on the animate
  534. * parameter.
  535. */
  536. show() {
  537. if (this.toolbarSelector.hasClass("slideOutY"))
  538. this.toolbarSelector.toggleClass("slideOutY");
  539. let slideInAnimation = (SideContainerToggler.isVisible)
  540. ? "slideInExtX"
  541. : "slideInX";
  542. let slideOutAnimation = (SideContainerToggler.isVisible)
  543. ? "slideOutExtX"
  544. : "slideOutX";
  545. if (this.extendedToolbarSelector.hasClass(slideOutAnimation))
  546. this.extendedToolbarSelector.toggleClass(slideOutAnimation);
  547. this.toolbarSelector.toggleClass("slideInY");
  548. this.extendedToolbarSelector.toggleClass(slideInAnimation);
  549. },
  550. registerClickListeners(listener) {
  551. $('#mainToolbarContainer').click(listener);
  552. $("#extendedToolbar").click(listener);
  553. },
  554. /**
  555. * Handles the side toolbar toggle.
  556. */
  557. _handleSideToolbarContainerToggled(containerId, isVisible) {
  558. Object.keys(defaultToolbarButtons).forEach(
  559. id => {
  560. if (!UIUtil.isButtonEnabled(id))
  561. return;
  562. var button = defaultToolbarButtons[id];
  563. if (button.sideContainerId
  564. && button.sideContainerId === containerId) {
  565. UIUtil.buttonClick(button.id, "selected");
  566. }
  567. }
  568. );
  569. }
  570. };
  571. export default Toolbar;