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

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