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

Toolbar.js 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  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_etherpad": function () {
  113. AnalyticsAdapter.sendEvent('toolbar.etherpad.clicked');
  114. emitter.emit(UIEvents.ETHERPAD_CLICKED);
  115. },
  116. "toolbar_button_desktopsharing": function () {
  117. if (APP.conference.isSharingScreen) {
  118. AnalyticsAdapter.sendEvent('toolbar.screen.disabled');
  119. } else {
  120. AnalyticsAdapter.sendEvent('toolbar.screen.enabled');
  121. }
  122. emitter.emit(UIEvents.TOGGLE_SCREENSHARING);
  123. },
  124. "toolbar_button_fullScreen": function() {
  125. AnalyticsAdapter.sendEvent('toolbar.fullscreen.enabled');
  126. UIUtil.buttonClick("#toolbar_button_fullScreen", "icon-full-screen icon-exit-full-screen");
  127. emitter.emit(UIEvents.FULLSCREEN_TOGGLE);
  128. },
  129. "toolbar_button_sip": function () {
  130. AnalyticsAdapter.sendEvent('toolbar.sip.clicked');
  131. showSipNumberInput();
  132. },
  133. "toolbar_button_dialpad": function () {
  134. AnalyticsAdapter.sendEvent('toolbar.sip.dialpad.clicked');
  135. dialpadButtonClicked();
  136. },
  137. "toolbar_button_settings": function () {
  138. AnalyticsAdapter.sendEvent('toolbar.settings.toggled');
  139. emitter.emit(UIEvents.TOGGLE_SETTINGS);
  140. },
  141. "toolbar_button_hangup": function () {
  142. AnalyticsAdapter.sendEvent('toolbar.hangup');
  143. emitter.emit(UIEvents.HANGUP);
  144. },
  145. "toolbar_button_login": function () {
  146. AnalyticsAdapter.sendEvent('toolbar.authenticate.login.clicked');
  147. emitter.emit(UIEvents.AUTH_CLICKED);
  148. },
  149. "toolbar_button_logout": function () {
  150. AnalyticsAdapter.sendEvent('toolbar.authenticate.logout.clicked');
  151. // Ask for confirmation
  152. messageHandler.openTwoButtonDialog(
  153. "dialog.logoutTitle",
  154. null,
  155. "dialog.logoutQuestion",
  156. null,
  157. false,
  158. "dialog.Yes",
  159. function (evt, yes) {
  160. if (yes) {
  161. emitter.emit(UIEvents.LOGOUT);
  162. }
  163. }
  164. );
  165. }
  166. };
  167. const defaultToolbarButtons = {
  168. 'microphone': '#toolbar_button_mute',
  169. 'camera': '#toolbar_button_camera',
  170. 'desktop': '#toolbar_button_desktopsharing',
  171. 'security': '#toolbar_button_security',
  172. 'invite': '#toolbar_button_link',
  173. 'chat': '#toolbar_button_chat',
  174. 'etherpad': '#toolbar_button_etherpad',
  175. 'fullscreen': '#toolbar_button_fullScreen',
  176. 'settings': '#toolbar_button_settings',
  177. 'hangup': '#toolbar_button_hangup'
  178. };
  179. function dialpadButtonClicked() {
  180. //TODO show the dialpad box
  181. }
  182. function showSipNumberInput () {
  183. let defaultNumber = config.defaultSipNumber
  184. ? config.defaultSipNumber
  185. : '';
  186. let sipMsg = APP.translation.generateTranslationHTML("dialog.sipMsg");
  187. messageHandler.openTwoButtonDialog(
  188. null, null, null,
  189. `<h2>${sipMsg}</h2>
  190. <input name="sipNumber" type="text" value="${defaultNumber}" autofocus>`,
  191. false, "dialog.Dial",
  192. function (e, v, m, f) {
  193. if (v && f.sipNumber) {
  194. emitter.emit(UIEvents.SIP_DIAL, f.sipNumber);
  195. }
  196. },
  197. null, null, ':input:first'
  198. );
  199. }
  200. const Toolbar = {
  201. init (eventEmitter) {
  202. emitter = eventEmitter;
  203. UIUtil.hideDisabledButtons(defaultToolbarButtons);
  204. Object.keys(buttonHandlers).forEach(
  205. buttonId => $(`#${buttonId}`).click(buttonHandlers[buttonId])
  206. );
  207. },
  208. /**
  209. * Updates the room invite url.
  210. */
  211. updateRoomUrl (newRoomUrl) {
  212. roomUrl = newRoomUrl;
  213. // If the invite dialog has been already opened we update the information.
  214. let inviteLink = document.getElementById('inviteLinkRef');
  215. if (inviteLink) {
  216. inviteLink.value = roomUrl;
  217. inviteLink.select();
  218. $('#inviteLinkRef').parent()
  219. .find('button[value=true]').prop('disabled', false);
  220. }
  221. },
  222. /**
  223. * Unlocks the lock button state.
  224. */
  225. unlockLockButton () {
  226. if ($("#toolbar_button_security").hasClass("icon-security-locked"))
  227. UIUtil.buttonClick("#toolbar_button_security", "icon-security icon-security-locked");
  228. },
  229. /**
  230. * Updates the lock button state to locked.
  231. */
  232. lockLockButton () {
  233. if ($("#toolbar_button_security").hasClass("icon-security"))
  234. UIUtil.buttonClick("#toolbar_button_security", "icon-security icon-security-locked");
  235. },
  236. /**
  237. * Shows or hides authentication button
  238. * @param show <tt>true</tt> to show or <tt>false</tt> to hide
  239. */
  240. showAuthenticateButton (show) {
  241. if (UIUtil.isButtonEnabled('authentication') && show) {
  242. $('#authentication').css({display: "inline"});
  243. } else {
  244. $('#authentication').css({display: "none"});
  245. }
  246. },
  247. showEtherpadButton () {
  248. if (!$('#toolbar_button_etherpad').is(":visible")) {
  249. $('#toolbar_button_etherpad').css({display: 'inline-block'});
  250. }
  251. },
  252. // Shows or hides the 'recording' button.
  253. showRecordingButton (show) {
  254. if (UIUtil.isButtonEnabled('recording') && show) {
  255. $('#toolbar_button_record').css({display: "inline-block"});
  256. } else {
  257. $('#toolbar_button_record').css({display: "none"});
  258. }
  259. },
  260. // checks whether recording is enabled and whether we have params
  261. // to start automatically recording
  262. checkAutoRecord () {
  263. if (UIUtil.isButtonEnabled('recording') && config.autoRecord) {
  264. emitter.emit(UIEvents.RECORDING_TOGGLE, UIUtil.escapeHtml(config.autoRecordToken));
  265. }
  266. },
  267. // checks whether desktop sharing is enabled and whether
  268. // we have params to start automatically sharing
  269. checkAutoEnableDesktopSharing () {
  270. if (UIUtil.isButtonEnabled('desktop') && config.autoEnableDesktopSharing) {
  271. emitter.emit(UIEvents.TOGGLE_SCREENSHARING);
  272. }
  273. },
  274. // Shows or hides SIP calls button
  275. showSipCallButton (show) {
  276. if (APP.conference.sipGatewayEnabled() && UIUtil.isButtonEnabled('sip') && show) {
  277. $('#toolbar_button_sip').css({display: "inline-block"});
  278. } else {
  279. $('#toolbar_button_sip').css({display: "none"});
  280. }
  281. },
  282. // Shows or hides the dialpad button
  283. showDialPadButton (show) {
  284. if (UIUtil.isButtonEnabled('dialpad') && show) {
  285. $('#toolbar_button_dialpad').css({display: "inline-block"});
  286. } else {
  287. $('#toolbar_button_dialpad').css({display: "none"});
  288. }
  289. },
  290. /**
  291. * Displays user authenticated identity name(login).
  292. * @param authIdentity identity name to be displayed.
  293. */
  294. setAuthenticatedIdentity (authIdentity) {
  295. if (authIdentity) {
  296. let selector = $('#toolbar_auth_identity');
  297. selector.css({display: "list-item"});
  298. selector.text(authIdentity);
  299. } else {
  300. $('#toolbar_auth_identity').css({display: "none"});
  301. }
  302. },
  303. /**
  304. * Shows/hides login button.
  305. * @param show <tt>true</tt> to show
  306. */
  307. showLoginButton (show) {
  308. if (UIUtil.isButtonEnabled('authentication') && show) {
  309. $('#toolbar_button_login').css({display: "list-item"});
  310. } else {
  311. $('#toolbar_button_login').css({display: "none"});
  312. }
  313. },
  314. /**
  315. * Shows/hides logout button.
  316. * @param show <tt>true</tt> to show
  317. */
  318. showLogoutButton (show) {
  319. if (UIUtil.isButtonEnabled('authentication') && show) {
  320. $('#toolbar_button_logout').css({display: "list-item"});
  321. } else {
  322. $('#toolbar_button_logout').css({display: "none"});
  323. }
  324. },
  325. /**
  326. * Update the state of the button. The button has blue glow if desktop
  327. * streaming is active.
  328. */
  329. updateDesktopSharingButtonState () {
  330. let button = $("#toolbar_button_desktopsharing");
  331. if (APP.conference.isSharingScreen) {
  332. button.addClass("glow");
  333. } else {
  334. button.removeClass("glow");
  335. }
  336. },
  337. updateRecordingState (state) {
  338. setRecordingButtonState(state);
  339. },
  340. /**
  341. * Marks video icon as muted or not.
  342. * @param {boolean} muted if icon should look like muted or not
  343. */
  344. markVideoIconAsMuted (muted) {
  345. $('#toolbar_button_camera').toggleClass("icon-camera-disabled", muted);
  346. },
  347. /**
  348. * Marks audio icon as muted or not.
  349. * @param {boolean} muted if icon should look like muted or not
  350. */
  351. markAudioIconAsMuted (muted) {
  352. $('#toolbar_button_mute').toggleClass("icon-microphone", !muted).toggleClass("icon-mic-disabled", muted);
  353. }
  354. };
  355. export default Toolbar;