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

Toolbar.js 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. /* global APP, $, config, interfaceConfig, JitsiMeetJS */
  2. /* jshint -W101 */
  3. import UIUtil from '../util/UIUtil';
  4. import UIEvents from '../../../service/UI/UIEvents';
  5. import ExtendedToolbarToggler from "../side_pannels/ExtendedToolbarToggler.js";
  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. },
  207. 'contacts': {
  208. id: '#toolbar_contact_list'
  209. },
  210. 'etherpad': {
  211. id: '#toolbar_button_etherpad'
  212. },
  213. 'fullscreen': {
  214. id: '#toolbar_button_fullScreen'
  215. },
  216. 'settings': {
  217. id: '#toolbar_button_settings'
  218. },
  219. 'hangup': {
  220. id: '#toolbar_button_hangup'
  221. },
  222. 'filmstrip': {
  223. id: '#toolbar_film_strip',
  224. shortcut: "F",
  225. shortcutAttr: "filmstripPopover",
  226. shortcutFunc: function() {
  227. JitsiMeetJS.analytics.sendEvent("shortcut.film.toggled");
  228. APP.UI.toggleFilmStrip();
  229. },
  230. shortcutDescription: "keyboardShortcuts.toggleFilmstrip"
  231. }
  232. };
  233. function dialpadButtonClicked() {
  234. //TODO show the dialpad box
  235. }
  236. function showSipNumberInput () {
  237. let defaultNumber = config.defaultSipNumber
  238. ? config.defaultSipNumber
  239. : '';
  240. let sipMsg = APP.translation.generateTranslationHTML("dialog.sipMsg");
  241. APP.UI.messageHandler.openTwoButtonDialog(
  242. null, null, null,
  243. `<h2>${sipMsg}</h2>
  244. <input name="sipNumber" type="text" value="${defaultNumber}" autofocus>`,
  245. false, "dialog.Dial",
  246. function (e, v, m, f) {
  247. if (v && f.sipNumber) {
  248. emitter.emit(UIEvents.SIP_DIAL, f.sipNumber);
  249. }
  250. },
  251. null, null, ':input:first'
  252. );
  253. }
  254. const Toolbar = {
  255. init (eventEmitter) {
  256. emitter = eventEmitter;
  257. // The toolbar is enabled by default.
  258. this.enabled = true;
  259. this.toolbarSelector = $("#mainToolbarContainer");
  260. this.extendedToolbarSelector = $("#extendedToolbar");
  261. UIUtil.hideDisabledButtons(defaultToolbarButtons);
  262. Object.keys(defaultToolbarButtons).forEach(
  263. id => {
  264. if (UIUtil.isButtonEnabled(id)) {
  265. var button = defaultToolbarButtons[id];
  266. if (button.shortcut)
  267. APP.keyboardshortcut.registerShortcut(
  268. button.shortcut,
  269. button.shortcutAttr,
  270. button.shortcutFunc,
  271. button.shortcutDescription
  272. );
  273. }
  274. }
  275. );
  276. Object.keys(buttonHandlers).forEach(
  277. buttonId => $(`#${buttonId}`).click(function(event) {
  278. !$(this).prop('disabled') && buttonHandlers[buttonId](event);
  279. })
  280. );
  281. },
  282. /**
  283. * Enables / disables the toolbar.
  284. * @param {e} set to {true} to enable the toolbar or {false}
  285. * to disable it
  286. */
  287. enable (e) {
  288. this.enabled = e;
  289. if (!e && this.isVisible())
  290. this.hide(false);
  291. },
  292. /**
  293. * Indicates if the bottom toolbar is currently enabled.
  294. * @return {this.enabled}
  295. */
  296. isEnabled() {
  297. return this.enabled;
  298. },
  299. /**
  300. * Updates the room invite url.
  301. */
  302. updateRoomUrl (newRoomUrl) {
  303. roomUrl = newRoomUrl;
  304. // If the invite dialog has been already opened we update the
  305. // information.
  306. let inviteLink = document.getElementById('inviteLinkRef');
  307. if (inviteLink) {
  308. inviteLink.value = roomUrl;
  309. inviteLink.select();
  310. $('#inviteLinkRef').parent()
  311. .find('button[value=true]').prop('disabled', false);
  312. }
  313. },
  314. /**
  315. * Unlocks the lock button state.
  316. */
  317. unlockLockButton () {
  318. if ($("#toolbar_button_security").hasClass("icon-security-locked"))
  319. UIUtil.buttonClick("#toolbar_button_security",
  320. "icon-security icon-security-locked");
  321. },
  322. /**
  323. * Updates the lock button state to locked.
  324. */
  325. lockLockButton () {
  326. if ($("#toolbar_button_security").hasClass("icon-security"))
  327. UIUtil.buttonClick("#toolbar_button_security",
  328. "icon-security icon-security-locked");
  329. },
  330. /**
  331. * Shows or hides authentication button
  332. * @param show <tt>true</tt> to show or <tt>false</tt> to hide
  333. */
  334. showAuthenticateButton (show) {
  335. if (UIUtil.isButtonEnabled('authentication') && show) {
  336. $('#authentication').css({display: "inline"});
  337. } else {
  338. $('#authentication').css({display: "none"});
  339. }
  340. },
  341. showEtherpadButton () {
  342. if (!$('#toolbar_button_etherpad').is(":visible")) {
  343. $('#toolbar_button_etherpad').css({display: 'inline-block'});
  344. }
  345. },
  346. // Shows or hides the 'shared video' button.
  347. showSharedVideoButton () {
  348. if (UIUtil.isButtonEnabled('sharedvideo')
  349. && config.disableThirdPartyRequests !== true) {
  350. $('#toolbar_button_sharedvideo').css({display: "inline-block"});
  351. } else {
  352. $('#toolbar_button_sharedvideo').css({display: "none"});
  353. }
  354. },
  355. // checks whether desktop sharing is enabled and whether
  356. // we have params to start automatically sharing
  357. checkAutoEnableDesktopSharing () {
  358. if (UIUtil.isButtonEnabled('desktop')
  359. && config.autoEnableDesktopSharing) {
  360. emitter.emit(UIEvents.TOGGLE_SCREENSHARING);
  361. }
  362. },
  363. // Shows or hides SIP calls button
  364. showSipCallButton (show) {
  365. if (APP.conference.sipGatewayEnabled()
  366. && UIUtil.isButtonEnabled('sip') && show) {
  367. $('#toolbar_button_sip').css({display: "inline-block"});
  368. } else {
  369. $('#toolbar_button_sip').css({display: "none"});
  370. }
  371. },
  372. // Shows or hides the dialpad button
  373. showDialPadButton (show) {
  374. if (UIUtil.isButtonEnabled('dialpad') && show) {
  375. $('#toolbar_button_dialpad').css({display: "inline-block"});
  376. } else {
  377. $('#toolbar_button_dialpad').css({display: "none"});
  378. }
  379. },
  380. /**
  381. * Displays user authenticated identity name(login).
  382. * @param authIdentity identity name to be displayed.
  383. */
  384. setAuthenticatedIdentity (authIdentity) {
  385. if (authIdentity) {
  386. let selector = $('#toolbar_auth_identity');
  387. selector.css({display: "list-item"});
  388. selector.text(authIdentity);
  389. } else {
  390. $('#toolbar_auth_identity').css({display: "none"});
  391. }
  392. },
  393. /**
  394. * Shows/hides login button.
  395. * @param show <tt>true</tt> to show
  396. */
  397. showLoginButton (show) {
  398. if (UIUtil.isButtonEnabled('authentication') && show) {
  399. $('#toolbar_button_login').css({display: "list-item"});
  400. } else {
  401. $('#toolbar_button_login').css({display: "none"});
  402. }
  403. },
  404. /**
  405. * Shows/hides logout button.
  406. * @param show <tt>true</tt> to show
  407. */
  408. showLogoutButton (show) {
  409. if (UIUtil.isButtonEnabled('authentication') && show) {
  410. $('#toolbar_button_logout').css({display: "list-item"});
  411. } else {
  412. $('#toolbar_button_logout').css({display: "none"});
  413. }
  414. },
  415. /**
  416. * Update the state of the button. The button has blue glow if desktop
  417. * streaming is active.
  418. */
  419. updateDesktopSharingButtonState () {
  420. let button = $("#toolbar_button_desktopsharing");
  421. if (APP.conference.isSharingScreen) {
  422. button.addClass("glow");
  423. } else {
  424. button.removeClass("glow");
  425. }
  426. },
  427. /**
  428. * Marks video icon as muted or not.
  429. * @param {boolean} muted if icon should look like muted or not
  430. */
  431. markVideoIconAsMuted (muted) {
  432. $('#toolbar_button_camera').toggleClass("icon-camera-disabled", muted);
  433. },
  434. /**
  435. * Marks video icon as disabled or not.
  436. * @param {boolean} disabled if icon should look like disabled or not
  437. */
  438. markVideoIconAsDisabled (disabled) {
  439. var $btn = $('#toolbar_button_camera');
  440. $btn
  441. .prop("disabled", disabled)
  442. .attr("data-i18n", disabled
  443. ? "[content]toolbar.cameraDisabled"
  444. : "[content]toolbar.videomute")
  445. .attr("shortcut", disabled ? "" : "toggleVideoPopover");
  446. disabled
  447. ? $btn.attr("disabled", "disabled")
  448. : $btn.removeAttr("disabled");
  449. APP.translation.translateElement($btn);
  450. disabled && this.markVideoIconAsMuted(disabled);
  451. },
  452. /**
  453. * Marks audio icon as muted or not.
  454. * @param {boolean} muted if icon should look like muted or not
  455. */
  456. markAudioIconAsMuted (muted) {
  457. $('#toolbar_button_mute').toggleClass("icon-microphone",
  458. !muted).toggleClass("icon-mic-disabled", muted);
  459. },
  460. /**
  461. * Marks audio icon as disabled or not.
  462. * @param {boolean} disabled if icon should look like disabled or not
  463. */
  464. markAudioIconAsDisabled (disabled) {
  465. var $btn = $('#toolbar_button_mute');
  466. $btn
  467. .prop("disabled", disabled)
  468. .attr("data-i18n", disabled
  469. ? "[content]toolbar.micDisabled"
  470. : "[content]toolbar.mute")
  471. .attr("shortcut", disabled ? "" : "mutePopover");
  472. disabled
  473. ? $btn.attr("disabled", "disabled")
  474. : $btn.removeAttr("disabled");
  475. APP.translation.translateElement($btn);
  476. disabled && this.markAudioIconAsMuted(disabled);
  477. },
  478. /**
  479. * Indicates if the toolbar is currently hovered.
  480. * @return {boolean} true if the toolbar is currently hovered,
  481. * false otherwise
  482. */
  483. isHovered() {
  484. var hovered = false;
  485. this.toolbarSelector.find('*').each(function () {
  486. let id = $(this).attr('id');
  487. if ($(`#${id}:hover`).length > 0) {
  488. hovered = true;
  489. // break each
  490. return false;
  491. }
  492. });
  493. if (hovered)
  494. return true;
  495. if ($("#bottomToolbar:hover").length > 0
  496. || $("#extendedToolbar:hover").length > 0
  497. || ExtendedToolbarToggler.isVisible()) {
  498. return true;
  499. }
  500. return false;
  501. },
  502. /**
  503. * Returns true if this toolbar is currently visible, or false otherwise.
  504. * @return <tt>true</tt> if currently visible, <tt>false</tt> - otherwise
  505. */
  506. isVisible() {
  507. return this.toolbarSelector.hasClass("slideInY");
  508. },
  509. /**
  510. * Hides the toolbar with animation or not depending on the animate
  511. * parameter.
  512. */
  513. hide() {
  514. this.toolbarSelector.toggleClass("slideInY").toggleClass("slideOutY");
  515. this.extendedToolbarSelector.toggleClass("slideInX")
  516. .toggleClass("slideOutX");
  517. },
  518. /**
  519. * Shows the toolbar with animation or not depending on the animate
  520. * parameter.
  521. */
  522. show() {
  523. if (this.toolbarSelector.hasClass("slideOutY"))
  524. this.toolbarSelector.toggleClass("slideOutY");
  525. if (this.extendedToolbarSelector.hasClass("slideOutX"))
  526. this.extendedToolbarSelector.toggleClass("slideOutX");
  527. this.toolbarSelector.toggleClass("slideInY");
  528. this.extendedToolbarSelector.toggleClass("slideInX");
  529. }
  530. };
  531. export default Toolbar;