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

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