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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  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 recordingToaster = null;
  9. let emitter = null;
  10. /**
  11. * Opens the invite link dialog.
  12. */
  13. function openLinkDialog () {
  14. let inviteAttributes;
  15. if (roomUrl === null) {
  16. inviteAttributes = 'data-i18n="[value]roomUrlDefaultMsg" value="' +
  17. APP.translation.translateString("roomUrlDefaultMsg") + '"';
  18. } else {
  19. inviteAttributes = "value=\"" + encodeURI(roomUrl) + "\"";
  20. }
  21. messageHandler.openTwoButtonDialog(
  22. "dialog.shareLink", null, null,
  23. `<input id="inviteLinkRef" type="text" ${inviteAttributes} onclick="this.select();" readonly>`,
  24. false, "dialog.Invite",
  25. function (e, v) {
  26. if (v && roomUrl) {
  27. emitter.emit(UIEvents.USER_INVITED, roomUrl);
  28. }
  29. },
  30. function (event) {
  31. if (roomUrl) {
  32. document.getElementById('inviteLinkRef').select();
  33. } else {
  34. if (event && event.target) {
  35. $(event.target).find('button[value=true]').prop('disabled', true);
  36. }
  37. }
  38. }
  39. );
  40. }
  41. // Sets the state of the recording button
  42. function setRecordingButtonState (recordingState) {
  43. let selector = $('#toolbar_button_record');
  44. if (recordingState === 'on') {
  45. selector.removeClass("icon-recEnable");
  46. selector.addClass("icon-recEnable active");
  47. $("#largeVideo").toggleClass("videoMessageFilter", true);
  48. let recordOnKey = "recording.on";
  49. $('#videoConnectionMessage').attr("data-i18n", recordOnKey);
  50. $('#videoConnectionMessage').text(APP.translation.translateString(recordOnKey));
  51. setTimeout(function(){
  52. $("#largeVideo").toggleClass("videoMessageFilter", false);
  53. $('#videoConnectionMessage').css({display: "none"});
  54. }, 1500);
  55. recordingToaster = messageHandler.notify(
  56. null, "recording.toaster", null,
  57. null, null,
  58. {timeOut: 0, closeButton: null, tapToDismiss: false}
  59. );
  60. } else if (recordingState === 'off') {
  61. selector.removeClass("icon-recEnable active");
  62. selector.addClass("icon-recEnable");
  63. $("#largeVideo").toggleClass("videoMessageFilter", false);
  64. $('#videoConnectionMessage').css({display: "none"});
  65. if (recordingToaster) {
  66. messageHandler.remove(recordingToaster);
  67. }
  68. } else if (recordingState === 'pending') {
  69. selector.removeClass("icon-recEnable active");
  70. selector.addClass("icon-recEnable");
  71. $("#largeVideo").toggleClass("videoMessageFilter", true);
  72. let recordPendingKey = "recording.pending";
  73. $('#videoConnectionMessage').attr("data-i18n", recordPendingKey);
  74. $('#videoConnectionMessage').text(APP.translation.translateString(recordPendingKey));
  75. $('#videoConnectionMessage').css({display: "block"});
  76. }
  77. }
  78. const buttonHandlers = {
  79. "toolbar_button_mute": function () {
  80. if (APP.conference.audioMuted) {
  81. AnalyticsAdapter.sendEvent('toolbar.audio.unmuted');
  82. emitter.emit(UIEvents.AUDIO_MUTED, false);
  83. } else {
  84. AnalyticsAdapter.sendEvent('toolbar.audio.muted');
  85. emitter.emit(UIEvents.AUDIO_MUTED, true);
  86. }
  87. },
  88. "toolbar_button_camera": function () {
  89. if (APP.conference.videoMuted) {
  90. AnalyticsAdapter.sendEvent('toolbar.video.enabled');
  91. emitter.emit(UIEvents.VIDEO_MUTED, false);
  92. } else {
  93. AnalyticsAdapter.sendEvent('toolbar.video.disabled');
  94. emitter.emit(UIEvents.VIDEO_MUTED, true);
  95. }
  96. },
  97. "toolbar_button_record": function () {
  98. AnalyticsAdapter.sendEvent('toolbar.recording.toggled');
  99. emitter.emit(UIEvents.RECORDING_TOGGLE);
  100. },
  101. "toolbar_button_security": function () {
  102. emitter.emit(UIEvents.ROOM_LOCK_CLICKED);
  103. },
  104. "toolbar_button_link": function () {
  105. AnalyticsAdapter.sendEvent('toolbar.invite.clicked');
  106. openLinkDialog();
  107. },
  108. "toolbar_button_chat": function () {
  109. AnalyticsAdapter.sendEvent('toolbar.chat.toggled');
  110. emitter.emit(UIEvents.TOGGLE_CHAT);
  111. },
  112. "toolbar_button_prezi": function () {
  113. AnalyticsAdapter.sendEvent('toolbar.prezi.clicked');
  114. emitter.emit(UIEvents.PREZI_CLICKED);
  115. },
  116. "toolbar_button_etherpad": function () {
  117. AnalyticsAdapter.sendEvent('toolbar.etherpad.clicked');
  118. emitter.emit(UIEvents.ETHERPAD_CLICKED);
  119. },
  120. "toolbar_button_desktopsharing": function () {
  121. if (APP.desktopsharing.isUsingScreenStream) {
  122. AnalyticsAdapter.sendEvent('toolbar.screen.disabled');
  123. } else {
  124. AnalyticsAdapter.sendEvent('toolbar.screen.enabled');
  125. }
  126. emitter.emit(UIEvents.TOGGLE_SCREENSHARING);
  127. },
  128. "toolbar_button_fullScreen": function() {
  129. AnalyticsAdapter.sendEvent('toolbar.fullscreen.enabled');
  130. UIUtil.buttonClick("#toolbar_button_fullScreen", "icon-full-screen icon-exit-full-screen");
  131. emitter.emit(UIEvents.FULLSCREEN_TOGGLE);
  132. },
  133. "toolbar_button_sip": function () {
  134. AnalyticsAdapter.sendEvent('toolbar.sip.clicked');
  135. showSipNumberInput();
  136. },
  137. "toolbar_button_dialpad": function () {
  138. AnalyticsAdapter.sendEvent('toolbar.sip.dialpad.clicked');
  139. dialpadButtonClicked();
  140. },
  141. "toolbar_button_settings": function () {
  142. AnalyticsAdapter.sendEvent('toolbar.settings.toggled');
  143. emitter.emit(UIEvents.TOGGLE_SETTINGS);
  144. },
  145. "toolbar_button_hangup": function () {
  146. AnalyticsAdapter.sendEvent('toolbar.hangup');
  147. emitter.emit(UIEvents.HANGUP);
  148. },
  149. "toolbar_button_login": function () {
  150. AnalyticsAdapter.sendEvent('toolbar.authenticate.login.clicked');
  151. emitter.emit(UIEvents.AUTH_CLICKED);
  152. },
  153. "toolbar_button_logout": function () {
  154. AnalyticsAdapter.sendEvent('toolbar.authenticate.logout.clicked');
  155. // Ask for confirmation
  156. messageHandler.openTwoButtonDialog(
  157. "dialog.logoutTitle",
  158. null,
  159. "dialog.logoutQuestion",
  160. null,
  161. false,
  162. "dialog.Yes",
  163. function (evt, yes) {
  164. if (yes) {
  165. emitter.emit(UIEvents.LOGOUT);
  166. }
  167. }
  168. );
  169. }
  170. };
  171. const defaultToolbarButtons = {
  172. 'microphone': '#toolbar_button_mute',
  173. 'camera': '#toolbar_button_camera',
  174. 'desktop': '#toolbar_button_desktopsharing',
  175. 'security': '#toolbar_button_security',
  176. 'invite': '#toolbar_button_link',
  177. 'chat': '#toolbar_button_chat',
  178. 'prezi': '#toolbar_button_prezi',
  179. 'etherpad': '#toolbar_button_etherpad',
  180. 'fullscreen': '#toolbar_button_fullScreen',
  181. 'settings': '#toolbar_button_settings',
  182. 'hangup': '#toolbar_button_hangup'
  183. };
  184. function dialpadButtonClicked() {
  185. //TODO show the dialpad box
  186. }
  187. function showSipNumberInput () {
  188. let defaultNumber = config.defaultSipNumber
  189. ? config.defaultSipNumber
  190. : '';
  191. let sipMsg = APP.translation.generateTranslationHTML("dialog.sipMsg");
  192. messageHandler.openTwoButtonDialog(
  193. null, null, null,
  194. `<h2>${sipMsg}</h2>
  195. <input name="sipNumber" type="text" value="${defaultNumber}" autofocus>`,
  196. false, "dialog.Dial",
  197. function (e, v, m, f) {
  198. if (v && f.sipNumber) {
  199. emitter.emit(UIEvents.SIP_DIAL, f.sipNumber);
  200. }
  201. },
  202. null, null, ':input:first'
  203. );
  204. }
  205. const Toolbar = {
  206. init (eventEmitter) {
  207. emitter = eventEmitter;
  208. UIUtil.hideDisabledButtons(defaultToolbarButtons);
  209. Object.keys(buttonHandlers).forEach(
  210. buttonId => $(`#${buttonId}`).click(buttonHandlers[buttonId])
  211. );
  212. },
  213. /**
  214. * Updates the room invite url.
  215. */
  216. updateRoomUrl (newRoomUrl) {
  217. roomUrl = newRoomUrl;
  218. // If the invite dialog has been already opened we update the information.
  219. let inviteLink = document.getElementById('inviteLinkRef');
  220. if (inviteLink) {
  221. inviteLink.value = roomUrl;
  222. inviteLink.select();
  223. $('#inviteLinkRef').parent()
  224. .find('button[value=true]').prop('disabled', false);
  225. }
  226. },
  227. /**
  228. * Disables and enables some of the buttons.
  229. */
  230. setupButtonsFromConfig () {
  231. if (!UIUtil.isButtonEnabled('prezi')) {
  232. $("#toolbar_button_prezi").css({display: "none"});
  233. }
  234. },
  235. /**
  236. * Unlocks the lock button state.
  237. */
  238. unlockLockButton () {
  239. if ($("#toolbar_button_security").hasClass("icon-security-locked"))
  240. UIUtil.buttonClick("#toolbar_button_security", "icon-security icon-security-locked");
  241. },
  242. /**
  243. * Updates the lock button state to locked.
  244. */
  245. lockLockButton () {
  246. if ($("#toolbar_button_security").hasClass("icon-security"))
  247. UIUtil.buttonClick("#toolbar_button_security", "icon-security icon-security-locked");
  248. },
  249. /**
  250. * Shows or hides authentication button
  251. * @param show <tt>true</tt> to show or <tt>false</tt> to hide
  252. */
  253. showAuthenticateButton (show) {
  254. if (UIUtil.isButtonEnabled('authentication') && show) {
  255. $('#authentication').css({display: "inline"});
  256. } else {
  257. $('#authentication').css({display: "none"});
  258. }
  259. },
  260. showEtherpadButton () {
  261. if (!$('#toolbar_button_etherpad').is(":visible")) {
  262. $('#toolbar_button_etherpad').css({display: 'inline-block'});
  263. }
  264. },
  265. // Shows or hides the 'recording' button.
  266. showRecordingButton (show) {
  267. if (UIUtil.isButtonEnabled('recording') && show) {
  268. $('#toolbar_button_record').css({display: "inline-block"});
  269. } else {
  270. $('#toolbar_button_record').css({display: "none"});
  271. }
  272. },
  273. // checks whether recording is enabled and whether we have params
  274. // to start automatically recording
  275. checkAutoRecord () {
  276. if (UIUtil.isButtonEnabled('recording') && config.autoRecord) {
  277. emitter.emit(UIEvents.RECORDING_TOGGLE, UIUtil.escapeHtml(config.autoRecordToken));
  278. }
  279. },
  280. // checks whether desktop sharing is enabled and whether
  281. // we have params to start automatically sharing
  282. checkAutoEnableDesktopSharing () {
  283. if (UIUtil.isButtonEnabled('desktop') && config.autoEnableDesktopSharing) {
  284. emitter.emit(UIEvents.TOGGLE_SCREENSHARING);
  285. }
  286. },
  287. // Shows or hides SIP calls button
  288. showSipCallButton (show) {
  289. if (APP.conference.sipGatewayEnabled() && UIUtil.isButtonEnabled('sip') && show) {
  290. $('#toolbar_button_sip').css({display: "inline-block"});
  291. } else {
  292. $('#toolbar_button_sip').css({display: "none"});
  293. }
  294. },
  295. // Shows or hides the dialpad button
  296. showDialPadButton (show) {
  297. if (UIUtil.isButtonEnabled('dialpad') && show) {
  298. $('#toolbar_button_dialpad').css({display: "inline-block"});
  299. } else {
  300. $('#toolbar_button_dialpad').css({display: "none"});
  301. }
  302. },
  303. /**
  304. * Displays user authenticated identity name(login).
  305. * @param authIdentity identity name to be displayed.
  306. */
  307. setAuthenticatedIdentity (authIdentity) {
  308. if (authIdentity) {
  309. let selector = $('#toolbar_auth_identity');
  310. selector.css({display: "list-item"});
  311. selector.text(authIdentity);
  312. } else {
  313. $('#toolbar_auth_identity').css({display: "none"});
  314. }
  315. },
  316. /**
  317. * Shows/hides login button.
  318. * @param show <tt>true</tt> to show
  319. */
  320. showLoginButton (show) {
  321. if (UIUtil.isButtonEnabled('authentication') && show) {
  322. $('#toolbar_button_login').css({display: "list-item"});
  323. } else {
  324. $('#toolbar_button_login').css({display: "none"});
  325. }
  326. },
  327. /**
  328. * Shows/hides logout button.
  329. * @param show <tt>true</tt> to show
  330. */
  331. showLogoutButton (show) {
  332. if (UIUtil.isButtonEnabled('authentication') && show) {
  333. $('#toolbar_button_logout').css({display: "list-item"});
  334. } else {
  335. $('#toolbar_button_logout').css({display: "none"});
  336. }
  337. },
  338. /**
  339. * Sets the state of the button. The button has blue glow if desktop
  340. * streaming is active.
  341. * @param active the state of the desktop streaming.
  342. */
  343. changeDesktopSharingButtonState (active) {
  344. let button = $("#toolbar_button_desktopsharing");
  345. if (active) {
  346. button.addClass("glow");
  347. } else {
  348. button.removeClass("glow");
  349. }
  350. },
  351. updateRecordingState (state) {
  352. setRecordingButtonState(state);
  353. }
  354. };
  355. export default Toolbar;