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

Toolbar.js 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. /* global APP, $, config, interfaceConfig */
  2. /* jshint -W101 */
  3. var messageHandler = require("../util/MessageHandler");
  4. var BottomToolbar = require("./BottomToolbar");
  5. var PanelToggler = require("../side_pannels/SidePanelToggler");
  6. var Authentication = require("../authentication/Authentication");
  7. var UIUtil = require("../util/UIUtil");
  8. var AnalyticsAdapter = require("../../statistics/AnalyticsAdapter");
  9. var Feedback = require("../Feedback");
  10. var UIEvents = require("../../../service/UI/UIEvents");
  11. var roomUrl = null;
  12. var recordingToaster = null;
  13. var emitter = null;
  14. var buttonHandlers = {
  15. "toolbar_button_mute": function () {
  16. if (APP.conference.audioMuted) {
  17. AnalyticsAdapter.sendEvent('toolbar.audio.unmuted');
  18. emitter.emit(UIEvents.AUDIO_MUTED, false);
  19. } else {
  20. AnalyticsAdapter.sendEvent('toolbar.audio.muted');
  21. emitter.emit(UIEvents.AUDIO_MUTED, true);
  22. }
  23. },
  24. "toolbar_button_camera": function () {
  25. if (APP.conference.videoMuted) {
  26. AnalyticsAdapter.sendEvent('toolbar.video.enabled');
  27. emitter.emit(UIEvents.VIDEO_MUTED, false);
  28. } else {
  29. AnalyticsAdapter.sendEvent('toolbar.video.disabled');
  30. emitter.emit(UIEvents.VIDEO_MUTED, true);
  31. }
  32. },
  33. "toolbar_button_record": function () {
  34. AnalyticsAdapter.sendEvent('toolbar.recording.toggled');
  35. return toggleRecording();
  36. },
  37. "toolbar_button_security": function () {
  38. emitter.emit(UIEvents.ROOM_LOCK_CLICKED);
  39. },
  40. "toolbar_button_link": function () {
  41. AnalyticsAdapter.sendEvent('toolbar.invite.clicked');
  42. return Toolbar.openLinkDialog();
  43. },
  44. "toolbar_button_chat": function () {
  45. AnalyticsAdapter.sendEvent('toolbar.chat.toggled');
  46. return BottomToolbar.toggleChat();
  47. },
  48. "toolbar_button_prezi": function () {
  49. AnalyticsAdapter.sendEvent('toolbar.prezi.clicked');
  50. emitter.emit(UIEvents.PREZI_CLICKED);
  51. },
  52. "toolbar_button_etherpad": function () {
  53. AnalyticsAdapter.sendEvent('toolbar.etherpad.clicked');
  54. emitter.emit(UIEvents.ETHERPAD_CLICKED);
  55. },
  56. "toolbar_button_desktopsharing": function () {
  57. if (APP.desktopsharing.isUsingScreenStream) {
  58. AnalyticsAdapter.sendEvent('toolbar.screen.disabled');
  59. } else {
  60. AnalyticsAdapter.sendEvent('toolbar.screen.enabled');
  61. }
  62. return APP.desktopsharing.toggleScreenSharing();
  63. },
  64. "toolbar_button_fullScreen": function() {
  65. AnalyticsAdapter.sendEvent('toolbar.fullscreen.enabled');
  66. UIUtil.buttonClick("#toolbar_button_fullScreen", "icon-full-screen icon-exit-full-screen");
  67. return Toolbar.toggleFullScreen();
  68. },
  69. "toolbar_button_sip": function () {
  70. AnalyticsAdapter.sendEvent('toolbar.sip.clicked');
  71. return callSipButtonClicked();
  72. },
  73. "toolbar_button_dialpad": function () {
  74. AnalyticsAdapter.sendEvent('toolbar.sip.dialpad.clicked');
  75. return dialpadButtonClicked();
  76. },
  77. "toolbar_button_settings": function () {
  78. AnalyticsAdapter.sendEvent('toolbar.settings.toggled');
  79. PanelToggler.toggleSettingsMenu();
  80. },
  81. "toolbar_button_hangup": function () {
  82. AnalyticsAdapter.sendEvent('toolbar.hangup');
  83. return hangup();
  84. },
  85. "toolbar_button_login": function () {
  86. AnalyticsAdapter.sendEvent('toolbar.authenticate.login.clicked');
  87. Toolbar.authenticateClicked();
  88. },
  89. "toolbar_button_logout": function () {
  90. AnalyticsAdapter.sendEvent('toolbar.authenticate.logout.clicked');
  91. // Ask for confirmation
  92. messageHandler.openTwoButtonDialog(
  93. "dialog.logoutTitle",
  94. null,
  95. "dialog.logoutQuestion",
  96. null,
  97. false,
  98. "dialog.Yes",
  99. function (evt, yes) {
  100. if (yes) {
  101. APP.xmpp.logout(function (url) {
  102. if (url) {
  103. window.location.href = url;
  104. } else {
  105. hangup();
  106. }
  107. });
  108. }
  109. });
  110. }
  111. };
  112. var defaultToolbarButtons = {
  113. 'microphone': '#toolbar_button_mute',
  114. 'camera': '#toolbar_button_camera',
  115. 'desktop': '#toolbar_button_desktopsharing',
  116. 'security': '#toolbar_button_security',
  117. 'invite': '#toolbar_button_link',
  118. 'chat': '#toolbar_button_chat',
  119. 'prezi': '#toolbar_button_prezi',
  120. 'etherpad': '#toolbar_button_etherpad',
  121. 'fullscreen': '#toolbar_button_fullScreen',
  122. 'settings': '#toolbar_button_settings',
  123. 'hangup': '#toolbar_button_hangup'
  124. };
  125. /**
  126. * Hangs up this call.
  127. */
  128. function hangup() {
  129. var conferenceDispose = function () {
  130. APP.xmpp.disposeConference();
  131. if (config.enableWelcomePage) {
  132. setTimeout(function() {
  133. window.localStorage.welcomePageDisabled = false;
  134. window.location.pathname = "/";
  135. }, 3000);
  136. }
  137. };
  138. if (Feedback.isEnabled())
  139. {
  140. // If the user has already entered feedback, we'll show the window and
  141. // immidiately start the conference dispose timeout.
  142. if (Feedback.feedbackScore > 0) {
  143. Feedback.openFeedbackWindow();
  144. conferenceDispose();
  145. }
  146. // Otherwise we'll wait for user's feedback.
  147. else
  148. Feedback.openFeedbackWindow(conferenceDispose);
  149. }
  150. else {
  151. conferenceDispose();
  152. // If the feedback functionality isn't enabled we show a thank you
  153. // dialog.
  154. APP.UI.messageHandler.openMessageDialog(null, null, null,
  155. APP.translation.translateString("dialog.thankYou",
  156. {appName:interfaceConfig.APP_NAME}));
  157. }
  158. }
  159. /**
  160. * Starts or stops the recording for the conference.
  161. */
  162. function toggleRecording(predefinedToken) {
  163. APP.xmpp.toggleRecording(function (callback) {
  164. if (predefinedToken) {
  165. callback(UIUtil.escapeHtml(predefinedToken));
  166. return;
  167. }
  168. var msg = APP.translation.generateTranslationHTML(
  169. "dialog.recordingToken");
  170. var token = APP.translation.translateString("dialog.token");
  171. APP.UI.messageHandler.openTwoButtonDialog(null, null, null,
  172. '<h2>' + msg + '</h2>' +
  173. '<input name="recordingToken" type="text" ' +
  174. ' data-i18n="[placeholder]dialog.token" ' +
  175. 'placeholder="' + token + '" autofocus>',
  176. false,
  177. "dialog.Save",
  178. function (e, v, m, f) {
  179. if (v) {
  180. var token = f.recordingToken;
  181. if (token) {
  182. callback(UIUtil.escapeHtml(token));
  183. }
  184. }
  185. },
  186. null,
  187. function () { },
  188. ':input:first'
  189. );
  190. }, Toolbar.setRecordingButtonState);
  191. }
  192. function dialpadButtonClicked() {
  193. //TODO show the dialpad box
  194. }
  195. function callSipButtonClicked() {
  196. var defaultNumber
  197. = config.defaultSipNumber ? config.defaultSipNumber : '';
  198. var sipMsg = APP.translation.generateTranslationHTML(
  199. "dialog.sipMsg");
  200. messageHandler.openTwoButtonDialog(null, null, null,
  201. '<h2>' + sipMsg + '</h2>' +
  202. '<input name="sipNumber" type="text"' +
  203. ' value="' + defaultNumber + '" autofocus>',
  204. false,
  205. "dialog.Dial",
  206. function (e, v, m, f) {
  207. if (v) {
  208. var numberInput = f.sipNumber;
  209. if (numberInput) {
  210. APP.xmpp.dial(numberInput, 'fromnumber', APP.conference.roomName, APP.conference.sharedKey);
  211. }
  212. }
  213. },
  214. null, null, ':input:first'
  215. );
  216. }
  217. var Toolbar = {
  218. init (eventEmitter) {
  219. emitter = eventEmitter;
  220. UIUtil.hideDisabledButtons(defaultToolbarButtons);
  221. for(var k in buttonHandlers)
  222. $("#" + k).click(buttonHandlers[k]);
  223. },
  224. authenticateClicked () {
  225. Authentication.focusAuthenticationWindow();
  226. if (!APP.xmpp.isExternalAuthEnabled()) {
  227. Authentication.xmppAuthenticate();
  228. return;
  229. }
  230. // Get authentication URL
  231. if (!APP.xmpp.isMUCJoined()) {
  232. APP.xmpp.getLoginUrl(APP.conference.roomName, function (url) {
  233. // If conference has not been started yet - redirect to login page
  234. window.location.href = url;
  235. });
  236. } else {
  237. APP.xmpp.getPopupLoginUrl(APP.conference.roomName, function (url) {
  238. // Otherwise - open popup with authentication URL
  239. var authenticationWindow = Authentication.createAuthenticationWindow(
  240. function () {
  241. // On popup closed - retry room allocation
  242. APP.xmpp.allocateConferenceFocus(
  243. APP.conference.roomName,
  244. function () { console.info("AUTH DONE"); }
  245. );
  246. }, url);
  247. if (!authenticationWindow) {
  248. messageHandler.openMessageDialog(
  249. null, "dialog.popupError");
  250. }
  251. });
  252. }
  253. },
  254. /**
  255. * Updates the room invite url.
  256. */
  257. updateRoomUrl (newRoomUrl) {
  258. roomUrl = newRoomUrl;
  259. // If the invite dialog has been already opened we update the information.
  260. var inviteLink = document.getElementById('inviteLinkRef');
  261. if (inviteLink) {
  262. inviteLink.value = roomUrl;
  263. inviteLink.select();
  264. $('#inviteLinkRef').parent()
  265. .find('button[value=true]').prop('disabled', false);
  266. }
  267. },
  268. /**
  269. * Disables and enables some of the buttons.
  270. */
  271. setupButtonsFromConfig () {
  272. if (UIUtil.isButtonEnabled('prezi')) {
  273. $("#toolbar_button_prezi").css({display: "none"});
  274. }
  275. },
  276. /**
  277. * Opens the invite link dialog.
  278. */
  279. openLinkDialog () {
  280. var inviteAttributes;
  281. if (roomUrl === null) {
  282. inviteAttributes = 'data-i18n="[value]roomUrlDefaultMsg" value="' +
  283. APP.translation.translateString("roomUrlDefaultMsg") + '"';
  284. } else {
  285. inviteAttributes = "value=\"" + encodeURI(roomUrl) + "\"";
  286. }
  287. messageHandler.openTwoButtonDialog("dialog.shareLink",
  288. null, null,
  289. '<input id="inviteLinkRef" type="text" ' +
  290. inviteAttributes + ' onclick="this.select();" readonly>',
  291. false,
  292. "dialog.Invite",
  293. function (e, v) {
  294. if (v && roomUrl) {
  295. emitter.emit(UIEvents.USER_INVITED, roomUrl);
  296. }
  297. },
  298. function (event) {
  299. if (roomUrl) {
  300. document.getElementById('inviteLinkRef').select();
  301. } else {
  302. if (event && event.target)
  303. $(event.target)
  304. .find('button[value=true]').prop('disabled', true);
  305. }
  306. }
  307. );
  308. },
  309. /**
  310. * Toggles the application in and out of full screen mode
  311. * (a.k.a. presentation mode in Chrome).
  312. */
  313. toggleFullScreen () {
  314. var fsElement = document.documentElement;
  315. if (!document.mozFullScreen && !document.webkitIsFullScreen) {
  316. //Enter Full Screen
  317. if (fsElement.mozRequestFullScreen) {
  318. fsElement.mozRequestFullScreen();
  319. }
  320. else {
  321. fsElement.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
  322. }
  323. } else {
  324. //Exit Full Screen
  325. if (document.mozCancelFullScreen) {
  326. document.mozCancelFullScreen();
  327. } else {
  328. document.webkitCancelFullScreen();
  329. }
  330. }
  331. },
  332. /**
  333. * Unlocks the lock button state.
  334. */
  335. unlockLockButton () {
  336. if ($("#toolbar_button_security").hasClass("icon-security-locked"))
  337. UIUtil.buttonClick("#toolbar_button_security", "icon-security icon-security-locked");
  338. },
  339. /**
  340. * Updates the lock button state to locked.
  341. */
  342. lockLockButton () {
  343. if ($("#toolbar_button_security").hasClass("icon-security"))
  344. UIUtil.buttonClick("#toolbar_button_security", "icon-security icon-security-locked");
  345. },
  346. /**
  347. * Shows or hides authentication button
  348. * @param show <tt>true</tt> to show or <tt>false</tt> to hide
  349. */
  350. showAuthenticateButton (show) {
  351. if (UIUtil.isButtonEnabled('authentication') && show) {
  352. $('#authentication').css({display: "inline"});
  353. }
  354. else {
  355. $('#authentication').css({display: "none"});
  356. }
  357. },
  358. // Shows or hides the 'recording' button.
  359. showRecordingButton (show) {
  360. if (UIUtil.isButtonEnabled('recording') && show) {
  361. $('#toolbar_button_record').css({display: "inline-block"});
  362. }
  363. else {
  364. $('#toolbar_button_record').css({display: "none"});
  365. }
  366. },
  367. // Sets the state of the recording button
  368. setRecordingButtonState (recordingState) {
  369. var selector = $('#toolbar_button_record');
  370. if (recordingState === 'on') {
  371. selector.removeClass("icon-recEnable");
  372. selector.addClass("icon-recEnable active");
  373. $("#largeVideo").toggleClass("videoMessageFilter", true);
  374. var recordOnKey = "recording.on";
  375. $('#videoConnectionMessage').attr("data-i18n", recordOnKey);
  376. $('#videoConnectionMessage').text(APP.translation.translateString(recordOnKey));
  377. setTimeout(function(){
  378. $("#largeVideo").toggleClass("videoMessageFilter", false);
  379. $('#videoConnectionMessage').css({display: "none"});
  380. }, 1500);
  381. recordingToaster = messageHandler.notify(null, "recording.toaster", null,
  382. null, null, {timeOut: 0, closeButton: null, tapToDismiss: false});
  383. } else if (recordingState === 'off') {
  384. selector.removeClass("icon-recEnable active");
  385. selector.addClass("icon-recEnable");
  386. $("#largeVideo").toggleClass("videoMessageFilter", false);
  387. $('#videoConnectionMessage').css({display: "none"});
  388. if (recordingToaster)
  389. messageHandler.remove(recordingToaster);
  390. } else if (recordingState === 'pending') {
  391. selector.removeClass("icon-recEnable active");
  392. selector.addClass("icon-recEnable");
  393. $("#largeVideo").toggleClass("videoMessageFilter", true);
  394. var recordPendingKey = "recording.pending";
  395. $('#videoConnectionMessage').attr("data-i18n", recordPendingKey);
  396. $('#videoConnectionMessage').text(APP.translation.translateString(recordPendingKey));
  397. $('#videoConnectionMessage').css({display: "block"});
  398. }
  399. },
  400. // checks whether recording is enabled and whether we have params
  401. // to start automatically recording
  402. checkAutoRecord () {
  403. if (UIUtil.isButtonEnabled('recording') && config.autoRecord) {
  404. toggleRecording(config.autoRecordToken);
  405. }
  406. },
  407. // checks whether desktop sharing is enabled and whether
  408. // we have params to start automatically sharing
  409. checkAutoEnableDesktopSharing () {
  410. if (UIUtil.isButtonEnabled('desktop')
  411. && config.autoEnableDesktopSharing) {
  412. APP.desktopsharing.toggleScreenSharing();
  413. }
  414. },
  415. // Shows or hides SIP calls button
  416. showSipCallButton (show) {
  417. if (APP.xmpp.isSipGatewayEnabled() && UIUtil.isButtonEnabled('sip') && show) {
  418. $('#toolbar_button_sip').css({display: "inline-block"});
  419. } else {
  420. $('#toolbar_button_sip').css({display: "none"});
  421. }
  422. },
  423. // Shows or hides the dialpad button
  424. showDialPadButton (show) {
  425. if (UIUtil.isButtonEnabled('dialpad') && show) {
  426. $('#toolbar_button_dialpad').css({display: "inline-block"});
  427. } else {
  428. $('#toolbar_button_dialpad').css({display: "none"});
  429. }
  430. },
  431. /**
  432. * Displays user authenticated identity name(login).
  433. * @param authIdentity identity name to be displayed.
  434. */
  435. setAuthenticatedIdentity (authIdentity) {
  436. if (authIdentity) {
  437. var selector = $('#toolbar_auth_identity');
  438. selector.css({display: "list-item"});
  439. selector.text(authIdentity);
  440. } else {
  441. $('#toolbar_auth_identity').css({display: "none"});
  442. }
  443. },
  444. /**
  445. * Shows/hides login button.
  446. * @param show <tt>true</tt> to show
  447. */
  448. showLoginButton (show) {
  449. if (UIUtil.isButtonEnabled('authentication') && show) {
  450. $('#toolbar_button_login').css({display: "list-item"});
  451. } else {
  452. $('#toolbar_button_login').css({display: "none"});
  453. }
  454. },
  455. /**
  456. * Shows/hides logout button.
  457. * @param show <tt>true</tt> to show
  458. */
  459. showLogoutButton (show) {
  460. if (UIUtil.isButtonEnabled('authentication') && show) {
  461. $('#toolbar_button_logout').css({display: "list-item"});
  462. } else {
  463. $('#toolbar_button_logout').css({display: "none"});
  464. }
  465. },
  466. /**
  467. * Sets the state of the button. The button has blue glow if desktop
  468. * streaming is active.
  469. * @param active the state of the desktop streaming.
  470. */
  471. changeDesktopSharingButtonState (active) {
  472. var button = $("#toolbar_button_desktopsharing");
  473. if (active) {
  474. button.addClass("glow");
  475. } else {
  476. button.removeClass("glow");
  477. }
  478. }
  479. };
  480. export default Toolbar;