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 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  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. console.log("TOGGLED", containerId, isVisible);
  287. Toolbar.handleSideToolbarContainerToggled( containerId,
  288. isVisible);
  289. });
  290. },
  291. /**
  292. * Enables / disables the toolbar.
  293. * @param {e} set to {true} to enable the toolbar or {false}
  294. * to disable it
  295. */
  296. enable (e) {
  297. this.enabled = e;
  298. if (!e && this.isVisible())
  299. this.hide(false);
  300. },
  301. /**
  302. * Indicates if the bottom toolbar is currently enabled.
  303. * @return {this.enabled}
  304. */
  305. isEnabled() {
  306. return this.enabled;
  307. },
  308. /**
  309. * Updates the room invite url.
  310. */
  311. updateRoomUrl (newRoomUrl) {
  312. roomUrl = newRoomUrl;
  313. // If the invite dialog has been already opened we update the
  314. // information.
  315. let inviteLink = document.getElementById('inviteLinkRef');
  316. if (inviteLink) {
  317. inviteLink.value = roomUrl;
  318. inviteLink.select();
  319. $('#inviteLinkRef').parent()
  320. .find('button[value=true]').prop('disabled', false);
  321. }
  322. },
  323. /**
  324. * Unlocks the lock button state.
  325. */
  326. unlockLockButton () {
  327. if ($("#toolbar_button_security").hasClass("icon-security-locked"))
  328. UIUtil.buttonClick("#toolbar_button_security",
  329. "icon-security icon-security-locked");
  330. },
  331. /**
  332. * Updates the lock button state to locked.
  333. */
  334. lockLockButton () {
  335. if ($("#toolbar_button_security").hasClass("icon-security"))
  336. UIUtil.buttonClick("#toolbar_button_security",
  337. "icon-security icon-security-locked");
  338. },
  339. /**
  340. * Shows or hides authentication button
  341. * @param show <tt>true</tt> to show or <tt>false</tt> to hide
  342. */
  343. showAuthenticateButton (show) {
  344. if (UIUtil.isButtonEnabled('authentication') && show) {
  345. $('#authentication').css({display: "inline"});
  346. } else {
  347. $('#authentication').css({display: "none"});
  348. }
  349. },
  350. showEtherpadButton () {
  351. if (!$('#toolbar_button_etherpad').is(":visible")) {
  352. $('#toolbar_button_etherpad').css({display: 'inline-block'});
  353. }
  354. },
  355. // Shows or hides the 'shared video' button.
  356. showSharedVideoButton () {
  357. if (UIUtil.isButtonEnabled('sharedvideo')
  358. && config.disableThirdPartyRequests !== true) {
  359. $('#toolbar_button_sharedvideo').css({display: "inline-block"});
  360. } else {
  361. $('#toolbar_button_sharedvideo').css({display: "none"});
  362. }
  363. },
  364. // checks whether desktop sharing is enabled and whether
  365. // we have params to start automatically sharing
  366. checkAutoEnableDesktopSharing () {
  367. if (UIUtil.isButtonEnabled('desktop')
  368. && config.autoEnableDesktopSharing) {
  369. emitter.emit(UIEvents.TOGGLE_SCREENSHARING);
  370. }
  371. },
  372. // Shows or hides SIP calls button
  373. showSipCallButton (show) {
  374. if (APP.conference.sipGatewayEnabled()
  375. && UIUtil.isButtonEnabled('sip') && show) {
  376. $('#toolbar_button_sip').css({display: "inline-block"});
  377. } else {
  378. $('#toolbar_button_sip').css({display: "none"});
  379. }
  380. },
  381. // Shows or hides the dialpad button
  382. showDialPadButton (show) {
  383. if (UIUtil.isButtonEnabled('dialpad') && show) {
  384. $('#toolbar_button_dialpad').css({display: "inline-block"});
  385. } else {
  386. $('#toolbar_button_dialpad').css({display: "none"});
  387. }
  388. },
  389. /**
  390. * Displays user authenticated identity name(login).
  391. * @param authIdentity identity name to be displayed.
  392. */
  393. setAuthenticatedIdentity (authIdentity) {
  394. if (authIdentity) {
  395. let selector = $('#toolbar_auth_identity');
  396. selector.css({display: "list-item"});
  397. selector.text(authIdentity);
  398. } else {
  399. $('#toolbar_auth_identity').css({display: "none"});
  400. }
  401. },
  402. /**
  403. * Shows/hides login button.
  404. * @param show <tt>true</tt> to show
  405. */
  406. showLoginButton (show) {
  407. if (UIUtil.isButtonEnabled('authentication') && show) {
  408. $('#toolbar_button_login').css({display: "list-item"});
  409. } else {
  410. $('#toolbar_button_login').css({display: "none"});
  411. }
  412. },
  413. /**
  414. * Shows/hides logout button.
  415. * @param show <tt>true</tt> to show
  416. */
  417. showLogoutButton (show) {
  418. if (UIUtil.isButtonEnabled('authentication') && show) {
  419. $('#toolbar_button_logout').css({display: "list-item"});
  420. } else {
  421. $('#toolbar_button_logout').css({display: "none"});
  422. }
  423. },
  424. /**
  425. * Update the state of the button. The button has blue glow if desktop
  426. * streaming is active.
  427. */
  428. updateDesktopSharingButtonState () {
  429. let button = $("#toolbar_button_desktopsharing");
  430. if (APP.conference.isSharingScreen) {
  431. button.addClass("glow");
  432. } else {
  433. button.removeClass("glow");
  434. }
  435. },
  436. /**
  437. * Marks video icon as muted or not.
  438. * @param {boolean} muted if icon should look like muted or not
  439. */
  440. markVideoIconAsMuted (muted) {
  441. $('#toolbar_button_camera').toggleClass("icon-camera-disabled", muted);
  442. },
  443. /**
  444. * Marks video icon as disabled or not.
  445. * @param {boolean} disabled if icon should look like disabled or not
  446. */
  447. markVideoIconAsDisabled (disabled) {
  448. var $btn = $('#toolbar_button_camera');
  449. $btn
  450. .prop("disabled", disabled)
  451. .attr("data-i18n", disabled
  452. ? "[content]toolbar.cameraDisabled"
  453. : "[content]toolbar.videomute")
  454. .attr("shortcut", disabled ? "" : "toggleVideoPopover");
  455. disabled
  456. ? $btn.attr("disabled", "disabled")
  457. : $btn.removeAttr("disabled");
  458. APP.translation.translateElement($btn);
  459. disabled && this.markVideoIconAsMuted(disabled);
  460. },
  461. /**
  462. * Marks audio icon as muted or not.
  463. * @param {boolean} muted if icon should look like muted or not
  464. */
  465. markAudioIconAsMuted (muted) {
  466. $('#toolbar_button_mute').toggleClass("icon-microphone",
  467. !muted).toggleClass("icon-mic-disabled", muted);
  468. },
  469. /**
  470. * Marks audio icon as disabled or not.
  471. * @param {boolean} disabled if icon should look like disabled or not
  472. */
  473. markAudioIconAsDisabled (disabled) {
  474. var $btn = $('#toolbar_button_mute');
  475. $btn
  476. .prop("disabled", disabled)
  477. .attr("data-i18n", disabled
  478. ? "[content]toolbar.micDisabled"
  479. : "[content]toolbar.mute")
  480. .attr("shortcut", disabled ? "" : "mutePopover");
  481. disabled
  482. ? $btn.attr("disabled", "disabled")
  483. : $btn.removeAttr("disabled");
  484. APP.translation.translateElement($btn);
  485. disabled && this.markAudioIconAsMuted(disabled);
  486. },
  487. /**
  488. * Indicates if the toolbar is currently hovered.
  489. * @return {boolean} true if the toolbar is currently hovered,
  490. * false otherwise
  491. */
  492. isHovered() {
  493. var hovered = false;
  494. this.toolbarSelector.find('*').each(function () {
  495. let id = $(this).attr('id');
  496. if ($(`#${id}:hover`).length > 0) {
  497. hovered = true;
  498. // break each
  499. return false;
  500. }
  501. });
  502. if (hovered)
  503. return true;
  504. if ($("#bottomToolbar:hover").length > 0
  505. || $("#extendedToolbar:hover").length > 0
  506. || SideContainerToggler.isVisible()) {
  507. return true;
  508. }
  509. return false;
  510. },
  511. /**
  512. * Returns true if this toolbar is currently visible, or false otherwise.
  513. * @return <tt>true</tt> if currently visible, <tt>false</tt> - otherwise
  514. */
  515. isVisible() {
  516. return this.toolbarSelector.hasClass("slideInY");
  517. },
  518. /**
  519. * Hides the toolbar with animation or not depending on the animate
  520. * parameter.
  521. */
  522. hide() {
  523. this.toolbarSelector.toggleClass("slideInY").toggleClass("slideOutY");
  524. this.extendedToolbarSelector.toggleClass("slideInX")
  525. .toggleClass("slideOutX");
  526. },
  527. /**
  528. * Shows the toolbar with animation or not depending on the animate
  529. * parameter.
  530. */
  531. show() {
  532. if (this.toolbarSelector.hasClass("slideOutY"))
  533. this.toolbarSelector.toggleClass("slideOutY");
  534. if (this.extendedToolbarSelector.hasClass("slideOutX"))
  535. this.extendedToolbarSelector.toggleClass("slideOutX");
  536. this.toolbarSelector.toggleClass("slideInY");
  537. this.extendedToolbarSelector.toggleClass("slideInX");
  538. },
  539. /**
  540. *
  541. */
  542. handleSideToolbarContainerToggled(containerId, isVisible) {
  543. Object.keys(defaultToolbarButtons).forEach(
  544. id => {
  545. if (!UIUtil.isButtonEnabled(id))
  546. return;
  547. var button = defaultToolbarButtons[id];
  548. if (button.sideContainerId
  549. && button.sideContainerId === containerId) {
  550. UIUtil.buttonClick(button.id, "selected");
  551. }
  552. }
  553. );
  554. }
  555. };
  556. export default Toolbar;