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

Toolbar.js 15KB

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