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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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(buttonHandlers[buttonId])
  183. );
  184. },
  185. /**
  186. * Enables / disables the toolbar.
  187. * @param {e} set to {true} to enable the toolbar or {false}
  188. * to disable it
  189. */
  190. enable (e) {
  191. this.enabled = e;
  192. if (!e && this.isVisible())
  193. this.hide(false);
  194. },
  195. /**
  196. * Indicates if the bottom toolbar is currently enabled.
  197. * @return {this.enabled}
  198. */
  199. isEnabled() {
  200. return this.enabled;
  201. },
  202. /**
  203. * Updates the room invite url.
  204. */
  205. updateRoomUrl (newRoomUrl) {
  206. roomUrl = newRoomUrl;
  207. // If the invite dialog has been already opened we update the
  208. // information.
  209. let inviteLink = document.getElementById('inviteLinkRef');
  210. if (inviteLink) {
  211. inviteLink.value = roomUrl;
  212. inviteLink.select();
  213. $('#inviteLinkRef').parent()
  214. .find('button[value=true]').prop('disabled', false);
  215. }
  216. },
  217. /**
  218. * Unlocks the lock button state.
  219. */
  220. unlockLockButton () {
  221. if ($("#toolbar_button_security").hasClass("icon-security-locked"))
  222. UIUtil.buttonClick("#toolbar_button_security",
  223. "icon-security icon-security-locked");
  224. },
  225. /**
  226. * Updates the lock button state to locked.
  227. */
  228. lockLockButton () {
  229. if ($("#toolbar_button_security").hasClass("icon-security"))
  230. UIUtil.buttonClick("#toolbar_button_security",
  231. "icon-security icon-security-locked");
  232. },
  233. /**
  234. * Shows or hides authentication button
  235. * @param show <tt>true</tt> to show or <tt>false</tt> to hide
  236. */
  237. showAuthenticateButton (show) {
  238. if (UIUtil.isButtonEnabled('authentication') && show) {
  239. $('#authentication').css({display: "inline"});
  240. } else {
  241. $('#authentication').css({display: "none"});
  242. }
  243. },
  244. showEtherpadButton () {
  245. if (!$('#toolbar_button_etherpad').is(":visible")) {
  246. $('#toolbar_button_etherpad').css({display: 'inline-block'});
  247. }
  248. },
  249. // Shows or hides the 'shared video' button.
  250. showSharedVideoButton () {
  251. if (UIUtil.isButtonEnabled('sharedvideo')
  252. && config.disableThirdPartyRequests !== true) {
  253. $('#toolbar_button_sharedvideo').css({display: "inline-block"});
  254. } else {
  255. $('#toolbar_button_sharedvideo').css({display: "none"});
  256. }
  257. },
  258. // checks whether desktop sharing is enabled and whether
  259. // we have params to start automatically sharing
  260. checkAutoEnableDesktopSharing () {
  261. if (UIUtil.isButtonEnabled('desktop')
  262. && config.autoEnableDesktopSharing) {
  263. emitter.emit(UIEvents.TOGGLE_SCREENSHARING);
  264. }
  265. },
  266. // Shows or hides SIP calls button
  267. showSipCallButton (show) {
  268. if (APP.conference.sipGatewayEnabled()
  269. && UIUtil.isButtonEnabled('sip') && show) {
  270. $('#toolbar_button_sip').css({display: "inline-block"});
  271. } else {
  272. $('#toolbar_button_sip').css({display: "none"});
  273. }
  274. },
  275. // Shows or hides the dialpad button
  276. showDialPadButton (show) {
  277. if (UIUtil.isButtonEnabled('dialpad') && show) {
  278. $('#toolbar_button_dialpad').css({display: "inline-block"});
  279. } else {
  280. $('#toolbar_button_dialpad').css({display: "none"});
  281. }
  282. },
  283. /**
  284. * Displays user authenticated identity name(login).
  285. * @param authIdentity identity name to be displayed.
  286. */
  287. setAuthenticatedIdentity (authIdentity) {
  288. if (authIdentity) {
  289. let selector = $('#toolbar_auth_identity');
  290. selector.css({display: "list-item"});
  291. selector.text(authIdentity);
  292. } else {
  293. $('#toolbar_auth_identity').css({display: "none"});
  294. }
  295. },
  296. /**
  297. * Shows/hides login button.
  298. * @param show <tt>true</tt> to show
  299. */
  300. showLoginButton (show) {
  301. if (UIUtil.isButtonEnabled('authentication') && show) {
  302. $('#toolbar_button_login').css({display: "list-item"});
  303. } else {
  304. $('#toolbar_button_login').css({display: "none"});
  305. }
  306. },
  307. /**
  308. * Shows/hides logout button.
  309. * @param show <tt>true</tt> to show
  310. */
  311. showLogoutButton (show) {
  312. if (UIUtil.isButtonEnabled('authentication') && show) {
  313. $('#toolbar_button_logout').css({display: "list-item"});
  314. } else {
  315. $('#toolbar_button_logout').css({display: "none"});
  316. }
  317. },
  318. /**
  319. * Update the state of the button. The button has blue glow if desktop
  320. * streaming is active.
  321. */
  322. updateDesktopSharingButtonState () {
  323. let button = $("#toolbar_button_desktopsharing");
  324. if (APP.conference.isSharingScreen) {
  325. button.addClass("glow");
  326. } else {
  327. button.removeClass("glow");
  328. }
  329. },
  330. /**
  331. * Marks video icon as muted or not.
  332. * @param {boolean} muted if icon should look like muted or not
  333. */
  334. markVideoIconAsMuted (muted) {
  335. $('#toolbar_button_camera').toggleClass("icon-camera-disabled", muted);
  336. },
  337. /**
  338. * Marks audio icon as muted or not.
  339. * @param {boolean} muted if icon should look like muted or not
  340. */
  341. markAudioIconAsMuted (muted) {
  342. $('#toolbar_button_mute').toggleClass("icon-microphone",
  343. !muted).toggleClass("icon-mic-disabled", muted);
  344. },
  345. /**
  346. * Indicates if the toolbar is currently hovered.
  347. * @return {true} if the toolbar is currently hovered, {false} otherwise
  348. */
  349. isHovered() {
  350. this.toolbarSelector.find('*').each(function () {
  351. let id = $(this).attr('id');
  352. if ($(`#${id}:hover`).length > 0) {
  353. return true;
  354. }
  355. });
  356. if ($("#bottomToolbar:hover").length > 0) {
  357. return true;
  358. }
  359. return false;
  360. },
  361. /**
  362. * Returns true if this toolbar is currently visible, or false otherwise.
  363. * @return <tt>true</tt> if currently visible, <tt>false</tt> - otherwise
  364. */
  365. isVisible() {
  366. return this.toolbarSelector.is(":visible");
  367. },
  368. /**
  369. * Hides the toolbar with animation or not depending on the animate
  370. * parameter.
  371. */
  372. hide() {
  373. this.toolbarSelector.hide(
  374. "slide", { direction: "up", duration: 300});
  375. },
  376. /**
  377. * Shows the toolbar with animation or not depending on the animate
  378. * parameter.
  379. */
  380. show() {
  381. this.toolbarSelector.show(
  382. "slide", { direction: "up", duration: 300});
  383. }
  384. };
  385. export default Toolbar;