Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

Toolbar.js 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  1. /* global APP, $, config, interfaceConfig, JitsiMeetJS */
  2. /* jshint -W101 */
  3. import UIUtil from '../util/UIUtil';
  4. import UIEvents from '../../../service/UI/UIEvents';
  5. import KeyboardShortcut from '../../keyboardshortcut/KeyboardShortcut';
  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_button_etherpad": function () {
  91. JitsiMeetJS.analytics.sendEvent('toolbar.etherpad.clicked');
  92. emitter.emit(UIEvents.ETHERPAD_CLICKED);
  93. },
  94. "toolbar_button_sharedvideo": function () {
  95. JitsiMeetJS.analytics.sendEvent('toolbar.sharedvideo.clicked');
  96. emitter.emit(UIEvents.SHARED_VIDEO_CLICKED);
  97. },
  98. "toolbar_button_desktopsharing": function () {
  99. if (APP.conference.isSharingScreen) {
  100. JitsiMeetJS.analytics.sendEvent('toolbar.screen.disabled');
  101. } else {
  102. JitsiMeetJS.analytics.sendEvent('toolbar.screen.enabled');
  103. }
  104. emitter.emit(UIEvents.TOGGLE_SCREENSHARING);
  105. },
  106. "toolbar_button_fullScreen": function() {
  107. JitsiMeetJS.analytics.sendEvent('toolbar.fullscreen.enabled');
  108. UIUtil.buttonClick("#toolbar_button_fullScreen",
  109. "icon-full-screen icon-exit-full-screen");
  110. emitter.emit(UIEvents.FULLSCREEN_TOGGLE);
  111. },
  112. "toolbar_button_sip": function () {
  113. JitsiMeetJS.analytics.sendEvent('toolbar.sip.clicked');
  114. showSipNumberInput();
  115. },
  116. "toolbar_button_dialpad": function () {
  117. JitsiMeetJS.analytics.sendEvent('toolbar.sip.dialpad.clicked');
  118. dialpadButtonClicked();
  119. },
  120. "toolbar_button_settings": function () {
  121. JitsiMeetJS.analytics.sendEvent('toolbar.settings.toggled');
  122. emitter.emit(UIEvents.TOGGLE_SETTINGS);
  123. },
  124. "toolbar_button_hangup": function () {
  125. JitsiMeetJS.analytics.sendEvent('toolbar.hangup');
  126. emitter.emit(UIEvents.HANGUP);
  127. },
  128. "toolbar_button_login": function () {
  129. JitsiMeetJS.analytics.sendEvent('toolbar.authenticate.login.clicked');
  130. emitter.emit(UIEvents.AUTH_CLICKED);
  131. },
  132. "toolbar_button_logout": function () {
  133. JitsiMeetJS.analytics.sendEvent('toolbar.authenticate.logout.clicked');
  134. // Ask for confirmation
  135. APP.UI.messageHandler.openTwoButtonDialog(
  136. "dialog.logoutTitle",
  137. null,
  138. "dialog.logoutQuestion",
  139. null,
  140. false,
  141. "dialog.Yes",
  142. function (evt, yes) {
  143. if (yes) {
  144. emitter.emit(UIEvents.LOGOUT);
  145. }
  146. }
  147. );
  148. }
  149. };
  150. const defaultToolbarButtons = {
  151. 'microphone': {
  152. id: '#toolbar_button_mute',
  153. shortcut: 'M',
  154. shortcutAttr: 'mutePopover',
  155. shortcutFunc: function() {
  156. JitsiMeetJS.analytics.sendEvent('shortcut.audiomute.toggled');
  157. APP.conference.toggleAudioMuted();
  158. },
  159. shortcutDescription: "keyboardShortcuts.mute"
  160. },
  161. 'camera': {
  162. id: '#toolbar_button_camera',
  163. shortcut: 'V',
  164. shortcutAttr: 'toggleVideoPopover',
  165. shortcutFunc: function() {
  166. JitsiMeetJS.analytics.sendEvent('shortcut.videomute.toggled');
  167. APP.conference.toggleVideoMuted();
  168. },
  169. shortcutDescription: "keyboardShortcuts.videoMute"
  170. },
  171. 'desktop': {
  172. id: '#toolbar_button_desktopsharing',
  173. shortcut: 'D',
  174. shortcutAttr: 'toggleDesktopSharingPopover',
  175. shortcutFunc: function() {
  176. JitsiMeetJS.analytics.sendEvent('shortcut.screen.toggled');
  177. APP.conference.toggleScreenSharing();
  178. },
  179. shortcutDescription: "keyboardShortcuts.toggleScreensharing"
  180. },
  181. 'security': {
  182. id: '#toolbar_button_security'
  183. },
  184. 'invite': {
  185. id: '#toolbar_button_link'
  186. },
  187. 'chat': {
  188. id: '#toolbar_button_chat',
  189. shortcut: 'C',
  190. shortcutAttr: 'toggleChatPopover',
  191. shortcutFunc: function() {
  192. JitsiMeetJS.analytics.sendEvent('shortcut.chat.toggled');
  193. APP.UI.toggleChat();
  194. },
  195. shortcutDescription: "keyboardShortcuts.toggleChat"
  196. },
  197. 'etherpad': {
  198. id: '#toolbar_button_etherpad'
  199. },
  200. 'fullscreen': {
  201. id: '#toolbar_button_fullScreen'
  202. },
  203. 'settings': {
  204. id: '#toolbar_button_settings'
  205. },
  206. 'hangup': {
  207. id: '#toolbar_button_hangup'
  208. }
  209. };
  210. function dialpadButtonClicked() {
  211. //TODO show the dialpad box
  212. }
  213. function showSipNumberInput () {
  214. let defaultNumber = config.defaultSipNumber
  215. ? config.defaultSipNumber
  216. : '';
  217. let sipMsg = APP.translation.generateTranslationHTML("dialog.sipMsg");
  218. APP.UI.messageHandler.openTwoButtonDialog(
  219. null, null, null,
  220. `<h2>${sipMsg}</h2>
  221. <input name="sipNumber" type="text" value="${defaultNumber}" autofocus>`,
  222. false, "dialog.Dial",
  223. function (e, v, m, f) {
  224. if (v && f.sipNumber) {
  225. emitter.emit(UIEvents.SIP_DIAL, f.sipNumber);
  226. }
  227. },
  228. null, null, ':input:first'
  229. );
  230. }
  231. const Toolbar = {
  232. init (eventEmitter) {
  233. emitter = eventEmitter;
  234. // The toolbar is enabled by default.
  235. this.enabled = true;
  236. this.toolbarSelector = $("#header");
  237. UIUtil.hideDisabledButtons(defaultToolbarButtons);
  238. Object.keys(defaultToolbarButtons).forEach(
  239. id => {
  240. if (UIUtil.isButtonEnabled(id)) {
  241. var button = defaultToolbarButtons[id];
  242. if (button.shortcut)
  243. KeyboardShortcut.registerShortcut(
  244. button.shortcut,
  245. button.shortcutAttr,
  246. button.shortcutFunc,
  247. button.shortcutDescription
  248. );
  249. }
  250. }
  251. );
  252. Object.keys(buttonHandlers).forEach(
  253. buttonId => $(`#${buttonId}`).click(function(event) {
  254. !$(this).prop('disabled') && buttonHandlers[buttonId](event);
  255. })
  256. );
  257. },
  258. /**
  259. * Enables / disables the toolbar.
  260. * @param {e} set to {true} to enable the toolbar or {false}
  261. * to disable it
  262. */
  263. enable (e) {
  264. this.enabled = e;
  265. if (!e && this.isVisible())
  266. this.hide(false);
  267. },
  268. /**
  269. * Indicates if the bottom toolbar is currently enabled.
  270. * @return {this.enabled}
  271. */
  272. isEnabled() {
  273. return this.enabled;
  274. },
  275. /**
  276. * Updates the room invite url.
  277. */
  278. updateRoomUrl (newRoomUrl) {
  279. roomUrl = newRoomUrl;
  280. // If the invite dialog has been already opened we update the
  281. // information.
  282. let inviteLink = document.getElementById('inviteLinkRef');
  283. if (inviteLink) {
  284. inviteLink.value = roomUrl;
  285. inviteLink.select();
  286. $('#inviteLinkRef').parent()
  287. .find('button[value=true]').prop('disabled', false);
  288. }
  289. },
  290. /**
  291. * Unlocks the lock button state.
  292. */
  293. unlockLockButton () {
  294. if ($("#toolbar_button_security").hasClass("icon-security-locked"))
  295. UIUtil.buttonClick("#toolbar_button_security",
  296. "icon-security icon-security-locked");
  297. },
  298. /**
  299. * Updates the lock button state to locked.
  300. */
  301. lockLockButton () {
  302. if ($("#toolbar_button_security").hasClass("icon-security"))
  303. UIUtil.buttonClick("#toolbar_button_security",
  304. "icon-security icon-security-locked");
  305. },
  306. /**
  307. * Shows or hides authentication button
  308. * @param show <tt>true</tt> to show or <tt>false</tt> to hide
  309. */
  310. showAuthenticateButton (show) {
  311. if (UIUtil.isButtonEnabled('authentication') && show) {
  312. $('#authentication').css({display: "inline"});
  313. } else {
  314. $('#authentication').css({display: "none"});
  315. }
  316. },
  317. showEtherpadButton () {
  318. if (!$('#toolbar_button_etherpad').is(":visible")) {
  319. $('#toolbar_button_etherpad').css({display: 'inline-block'});
  320. }
  321. },
  322. // Shows or hides the 'shared video' button.
  323. showSharedVideoButton () {
  324. if (UIUtil.isButtonEnabled('sharedvideo')
  325. && config.disableThirdPartyRequests !== true) {
  326. $('#toolbar_button_sharedvideo').css({display: "inline-block"});
  327. } else {
  328. $('#toolbar_button_sharedvideo').css({display: "none"});
  329. }
  330. },
  331. // checks whether desktop sharing is enabled and whether
  332. // we have params to start automatically sharing
  333. checkAutoEnableDesktopSharing () {
  334. if (UIUtil.isButtonEnabled('desktop')
  335. && config.autoEnableDesktopSharing) {
  336. emitter.emit(UIEvents.TOGGLE_SCREENSHARING);
  337. }
  338. },
  339. // Shows or hides SIP calls button
  340. showSipCallButton (show) {
  341. if (APP.conference.sipGatewayEnabled()
  342. && UIUtil.isButtonEnabled('sip') && show) {
  343. $('#toolbar_button_sip').css({display: "inline-block"});
  344. } else {
  345. $('#toolbar_button_sip').css({display: "none"});
  346. }
  347. },
  348. // Shows or hides the dialpad button
  349. showDialPadButton (show) {
  350. if (UIUtil.isButtonEnabled('dialpad') && show) {
  351. $('#toolbar_button_dialpad').css({display: "inline-block"});
  352. } else {
  353. $('#toolbar_button_dialpad').css({display: "none"});
  354. }
  355. },
  356. /**
  357. * Displays user authenticated identity name(login).
  358. * @param authIdentity identity name to be displayed.
  359. */
  360. setAuthenticatedIdentity (authIdentity) {
  361. if (authIdentity) {
  362. let selector = $('#toolbar_auth_identity');
  363. selector.css({display: "list-item"});
  364. selector.text(authIdentity);
  365. } else {
  366. $('#toolbar_auth_identity').css({display: "none"});
  367. }
  368. },
  369. /**
  370. * Shows/hides login button.
  371. * @param show <tt>true</tt> to show
  372. */
  373. showLoginButton (show) {
  374. if (UIUtil.isButtonEnabled('authentication') && show) {
  375. $('#toolbar_button_login').css({display: "list-item"});
  376. } else {
  377. $('#toolbar_button_login').css({display: "none"});
  378. }
  379. },
  380. /**
  381. * Shows/hides logout button.
  382. * @param show <tt>true</tt> to show
  383. */
  384. showLogoutButton (show) {
  385. if (UIUtil.isButtonEnabled('authentication') && show) {
  386. $('#toolbar_button_logout').css({display: "list-item"});
  387. } else {
  388. $('#toolbar_button_logout').css({display: "none"});
  389. }
  390. },
  391. /**
  392. * Update the state of the button. The button has blue glow if desktop
  393. * streaming is active.
  394. */
  395. updateDesktopSharingButtonState () {
  396. let button = $("#toolbar_button_desktopsharing");
  397. if (APP.conference.isSharingScreen) {
  398. button.addClass("glow");
  399. } else {
  400. button.removeClass("glow");
  401. }
  402. },
  403. /**
  404. * Marks video icon as muted or not.
  405. * @param {boolean} muted if icon should look like muted or not
  406. */
  407. markVideoIconAsMuted (muted) {
  408. $('#toolbar_button_camera').toggleClass("icon-camera-disabled", muted);
  409. },
  410. /**
  411. * Marks video icon as disabled or not.
  412. * @param {boolean} disabled if icon should look like disabled or not
  413. */
  414. markVideoIconAsDisabled (disabled) {
  415. var $btn = $('#toolbar_button_camera');
  416. $btn
  417. .prop("disabled", disabled)
  418. .attr("data-i18n", disabled
  419. ? "[content]toolbar.cameraDisabled"
  420. : "[content]toolbar.videomute")
  421. .attr("shortcut", disabled ? "" : "toggleVideoPopover");
  422. disabled
  423. ? $btn.attr("disabled", "disabled")
  424. : $btn.removeAttr("disabled");
  425. APP.translation.translateElement($btn);
  426. disabled && this.markVideoIconAsMuted(disabled);
  427. },
  428. /**
  429. * Marks audio icon as muted or not.
  430. * @param {boolean} muted if icon should look like muted or not
  431. */
  432. markAudioIconAsMuted (muted) {
  433. $('#toolbar_button_mute').toggleClass("icon-microphone",
  434. !muted).toggleClass("icon-mic-disabled", muted);
  435. },
  436. /**
  437. * Marks audio icon as disabled or not.
  438. * @param {boolean} disabled if icon should look like disabled or not
  439. */
  440. markAudioIconAsDisabled (disabled) {
  441. var $btn = $('#toolbar_button_mute');
  442. $btn
  443. .prop("disabled", disabled)
  444. .attr("data-i18n", disabled
  445. ? "[content]toolbar.micDisabled"
  446. : "[content]toolbar.mute")
  447. .attr("shortcut", disabled ? "" : "mutePopover");
  448. disabled
  449. ? $btn.attr("disabled", "disabled")
  450. : $btn.removeAttr("disabled");
  451. APP.translation.translateElement($btn);
  452. disabled && this.markAudioIconAsMuted(disabled);
  453. },
  454. /**
  455. * Indicates if the toolbar is currently hovered.
  456. * @return {boolean} true if the toolbar is currently hovered,
  457. * false otherwise
  458. */
  459. isHovered() {
  460. var hovered = false;
  461. this.toolbarSelector.find('*').each(function () {
  462. let id = $(this).attr('id');
  463. if ($(`#${id}:hover`).length > 0) {
  464. hovered = true;
  465. // break each
  466. return false;
  467. }
  468. });
  469. if (hovered)
  470. return true;
  471. if ($("#bottomToolbar:hover").length > 0) {
  472. return true;
  473. }
  474. return false;
  475. },
  476. /**
  477. * Returns true if this toolbar is currently visible, or false otherwise.
  478. * @return <tt>true</tt> if currently visible, <tt>false</tt> - otherwise
  479. */
  480. isVisible() {
  481. return this.toolbarSelector.is(":visible");
  482. },
  483. /**
  484. * Hides the toolbar with animation or not depending on the animate
  485. * parameter.
  486. */
  487. hide() {
  488. this.toolbarSelector.hide(
  489. "slide", { direction: "up", duration: 300});
  490. },
  491. /**
  492. * Shows the toolbar with animation or not depending on the animate
  493. * parameter.
  494. */
  495. show() {
  496. this.toolbarSelector.show(
  497. "slide", { direction: "up", duration: 300});
  498. }
  499. };
  500. export default Toolbar;