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

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