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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  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. UIUtil.hideDisabledButtons(defaultToolbarButtons);
  166. Object.keys(buttonHandlers).forEach(
  167. buttonId => $(`#${buttonId}`).click(buttonHandlers[buttonId])
  168. );
  169. },
  170. /**
  171. * Updates the room invite url.
  172. */
  173. updateRoomUrl (newRoomUrl) {
  174. roomUrl = newRoomUrl;
  175. // If the invite dialog has been already opened we update the information.
  176. let inviteLink = document.getElementById('inviteLinkRef');
  177. if (inviteLink) {
  178. inviteLink.value = roomUrl;
  179. inviteLink.select();
  180. $('#inviteLinkRef').parent()
  181. .find('button[value=true]').prop('disabled', false);
  182. }
  183. },
  184. /**
  185. * Unlocks the lock button state.
  186. */
  187. unlockLockButton () {
  188. if ($("#toolbar_button_security").hasClass("icon-security-locked"))
  189. UIUtil.buttonClick("#toolbar_button_security",
  190. "icon-security icon-security-locked");
  191. },
  192. /**
  193. * Updates the lock button state to locked.
  194. */
  195. lockLockButton () {
  196. if ($("#toolbar_button_security").hasClass("icon-security"))
  197. UIUtil.buttonClick("#toolbar_button_security",
  198. "icon-security icon-security-locked");
  199. },
  200. /**
  201. * Shows or hides authentication button
  202. * @param show <tt>true</tt> to show or <tt>false</tt> to hide
  203. */
  204. showAuthenticateButton (show) {
  205. if (UIUtil.isButtonEnabled('authentication') && show) {
  206. $('#authentication').css({display: "inline"});
  207. } else {
  208. $('#authentication').css({display: "none"});
  209. }
  210. },
  211. showEtherpadButton () {
  212. if (!$('#toolbar_button_etherpad').is(":visible")) {
  213. $('#toolbar_button_etherpad').css({display: 'inline-block'});
  214. }
  215. },
  216. // Shows or hides the 'shared video' button.
  217. showSharedVideoButton () {
  218. if (UIUtil.isButtonEnabled('sharedvideo')
  219. && config.disableThirdPartyRequests !== true) {
  220. $('#toolbar_button_sharedvideo').css({display: "inline-block"});
  221. } else {
  222. $('#toolbar_button_sharedvideo').css({display: "none"});
  223. }
  224. },
  225. // checks whether desktop sharing is enabled and whether
  226. // we have params to start automatically sharing
  227. checkAutoEnableDesktopSharing () {
  228. if (UIUtil.isButtonEnabled('desktop') && config.autoEnableDesktopSharing) {
  229. emitter.emit(UIEvents.TOGGLE_SCREENSHARING);
  230. }
  231. },
  232. // Shows or hides SIP calls button
  233. showSipCallButton (show) {
  234. if (APP.conference.sipGatewayEnabled() && UIUtil.isButtonEnabled('sip') && show) {
  235. $('#toolbar_button_sip').css({display: "inline-block"});
  236. } else {
  237. $('#toolbar_button_sip').css({display: "none"});
  238. }
  239. },
  240. // Shows or hides the dialpad button
  241. showDialPadButton (show) {
  242. if (UIUtil.isButtonEnabled('dialpad') && show) {
  243. $('#toolbar_button_dialpad').css({display: "inline-block"});
  244. } else {
  245. $('#toolbar_button_dialpad').css({display: "none"});
  246. }
  247. },
  248. /**
  249. * Displays user authenticated identity name(login).
  250. * @param authIdentity identity name to be displayed.
  251. */
  252. setAuthenticatedIdentity (authIdentity) {
  253. if (authIdentity) {
  254. let selector = $('#toolbar_auth_identity');
  255. selector.css({display: "list-item"});
  256. selector.text(authIdentity);
  257. } else {
  258. $('#toolbar_auth_identity').css({display: "none"});
  259. }
  260. },
  261. /**
  262. * Shows/hides login button.
  263. * @param show <tt>true</tt> to show
  264. */
  265. showLoginButton (show) {
  266. if (UIUtil.isButtonEnabled('authentication') && show) {
  267. $('#toolbar_button_login').css({display: "list-item"});
  268. } else {
  269. $('#toolbar_button_login').css({display: "none"});
  270. }
  271. },
  272. /**
  273. * Shows/hides logout button.
  274. * @param show <tt>true</tt> to show
  275. */
  276. showLogoutButton (show) {
  277. if (UIUtil.isButtonEnabled('authentication') && show) {
  278. $('#toolbar_button_logout').css({display: "list-item"});
  279. } else {
  280. $('#toolbar_button_logout').css({display: "none"});
  281. }
  282. },
  283. /**
  284. * Update the state of the button. The button has blue glow if desktop
  285. * streaming is active.
  286. */
  287. updateDesktopSharingButtonState () {
  288. let button = $("#toolbar_button_desktopsharing");
  289. if (APP.conference.isSharingScreen) {
  290. button.addClass("glow");
  291. } else {
  292. button.removeClass("glow");
  293. }
  294. },
  295. /**
  296. * Marks video icon as muted or not.
  297. * @param {boolean} muted if icon should look like muted or not
  298. */
  299. markVideoIconAsMuted (muted) {
  300. $('#toolbar_button_camera').toggleClass("icon-camera-disabled", muted);
  301. },
  302. /**
  303. * Marks audio icon as muted or not.
  304. * @param {boolean} muted if icon should look like muted or not
  305. */
  306. markAudioIconAsMuted (muted) {
  307. $('#toolbar_button_mute').toggleClass("icon-microphone", !muted).toggleClass("icon-mic-disabled", muted);
  308. }
  309. };
  310. export default Toolbar;