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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. /* global APP,$, buttonClick, config, lockRoom,
  2. setSharedKey, Util */
  3. var messageHandler = require("../util/MessageHandler");
  4. var BottomToolbar = require("./BottomToolbar");
  5. var Prezi = require("../prezi/Prezi");
  6. var Etherpad = require("../etherpad/Etherpad");
  7. var PanelToggler = require("../side_pannels/SidePanelToggler");
  8. var Authentication = require("../authentication/Authentication");
  9. var UIUtil = require("../util/UIUtil");
  10. var AuthenticationEvents
  11. = require("../../../service/authentication/AuthenticationEvents");
  12. var roomUrl = null;
  13. var sharedKey = '';
  14. var UI = null;
  15. var buttonHandlers =
  16. {
  17. "toolbar_button_mute": function () {
  18. return APP.UI.toggleAudio();
  19. },
  20. "toolbar_button_camera": function () {
  21. return APP.UI.toggleVideo();
  22. },
  23. /*"toolbar_button_authentication": function () {
  24. return Toolbar.authenticateClicked();
  25. },*/
  26. "toolbar_button_record": function () {
  27. return toggleRecording();
  28. },
  29. "toolbar_button_security": function () {
  30. return Toolbar.openLockDialog();
  31. },
  32. "toolbar_button_link": function () {
  33. return Toolbar.openLinkDialog();
  34. },
  35. "toolbar_button_chat": function () {
  36. return BottomToolbar.toggleChat();
  37. },
  38. "toolbar_button_prezi": function () {
  39. return Prezi.openPreziDialog();
  40. },
  41. "toolbar_button_etherpad": function () {
  42. return Etherpad.toggleEtherpad(0);
  43. },
  44. "toolbar_button_desktopsharing": function () {
  45. return APP.desktopsharing.toggleScreenSharing();
  46. },
  47. "toolbar_button_fullScreen": function()
  48. {
  49. UIUtil.buttonClick("#fullScreen", "icon-full-screen icon-exit-full-screen");
  50. return Toolbar.toggleFullScreen();
  51. },
  52. "toolbar_button_sip": function () {
  53. return callSipButtonClicked();
  54. },
  55. "toolbar_button_settings": function () {
  56. PanelToggler.toggleSettingsMenu();
  57. },
  58. "toolbar_button_hangup": function () {
  59. return hangup();
  60. },
  61. "toolbar_button_login": function () {
  62. Toolbar.authenticateClicked();
  63. },
  64. "toolbar_button_logout": function () {
  65. // Ask for confirmation
  66. messageHandler.openTwoButtonDialog(
  67. "Logout",
  68. "Are you sure you want to logout and stop the conference ?",
  69. false, "Yes",
  70. function (evt, yes) {
  71. if (yes) {
  72. APP.xmpp.logout(function (url) {
  73. if (url) {
  74. window.location.href = url;
  75. } else {
  76. hangup();
  77. }
  78. });
  79. }
  80. });
  81. }
  82. };
  83. function hangup() {
  84. APP.xmpp.disposeConference();
  85. if(config.enableWelcomePage)
  86. {
  87. setTimeout(function()
  88. {
  89. window.localStorage.welcomePageDisabled = false;
  90. window.location.pathname = "/";
  91. }, 10000);
  92. }
  93. UI.messageHandler.openDialog(
  94. "Session Terminated",
  95. "You hung up the call",
  96. true,
  97. { "Join again": true },
  98. function(event, value, message, formVals)
  99. {
  100. window.location.reload();
  101. return false;
  102. }
  103. );
  104. }
  105. /**
  106. * Starts or stops the recording for the conference.
  107. */
  108. function toggleRecording() {
  109. APP.xmpp.toggleRecording(function (callback) {
  110. APP.UI.messageHandler.openTwoButtonDialog(null,
  111. '<h2>Enter recording token</h2>' +
  112. '<input id="recordingToken" type="text" ' +
  113. 'placeholder="token" autofocus>',
  114. false,
  115. "Save",
  116. function (e, v, m, f) {
  117. if (v) {
  118. var token = document.getElementById('recordingToken');
  119. if (token.value) {
  120. callback(UIUtil.escapeHtml(token.value));
  121. }
  122. }
  123. },
  124. function (event) {
  125. document.getElementById('recordingToken').focus();
  126. },
  127. function () {
  128. }
  129. );
  130. }, Toolbar.setRecordingButtonState, Toolbar.setRecordingButtonState);
  131. }
  132. /**
  133. * Locks / unlocks the room.
  134. */
  135. function lockRoom(lock) {
  136. var currentSharedKey = '';
  137. if (lock)
  138. currentSharedKey = sharedKey;
  139. APP.xmpp.lockRoom(currentSharedKey, function (res) {
  140. // password is required
  141. if (sharedKey)
  142. {
  143. console.log('set room password');
  144. Toolbar.lockLockButton();
  145. }
  146. else
  147. {
  148. console.log('removed room password');
  149. Toolbar.unlockLockButton();
  150. }
  151. }, function (err) {
  152. console.warn('setting password failed', err);
  153. messageHandler.showError('Lock failed',
  154. 'Failed to lock conference.',
  155. err);
  156. Toolbar.setSharedKey('');
  157. }, function () {
  158. console.warn('room passwords not supported');
  159. messageHandler.showError('Warning',
  160. 'Room passwords are currently not supported.');
  161. Toolbar.setSharedKey('');
  162. });
  163. };
  164. /**
  165. * Invite participants to conference.
  166. */
  167. function inviteParticipants() {
  168. if (roomUrl === null)
  169. return;
  170. var sharedKeyText = "";
  171. if (sharedKey && sharedKey.length > 0) {
  172. sharedKeyText =
  173. "This conference is password protected. Please use the " +
  174. "following pin when joining:%0D%0A%0D%0A" +
  175. sharedKey + "%0D%0A%0D%0A";
  176. }
  177. var conferenceName = roomUrl.substring(roomUrl.lastIndexOf('/') + 1);
  178. var subject = "Invitation to a " + interfaceConfig.APP_NAME + " (" + conferenceName + ")";
  179. var body = "Hey there, I%27d like to invite you to a " + interfaceConfig.APP_NAME +
  180. " conference I%27ve just set up.%0D%0A%0D%0A" +
  181. "Please click on the following link in order" +
  182. " to join the conference.%0D%0A%0D%0A" +
  183. roomUrl +
  184. "%0D%0A%0D%0A" +
  185. sharedKeyText +
  186. "Note that " + interfaceConfig.APP_NAME + " is currently" +
  187. " only supported by Chromium," +
  188. " Google Chrome and Opera, so you need" +
  189. " to be using one of these browsers.%0D%0A%0D%0A" +
  190. "Talk to you in a sec!";
  191. if (window.localStorage.displayname) {
  192. body += "%0D%0A%0D%0A" + window.localStorage.displayname;
  193. }
  194. if (interfaceConfig.INVITATION_POWERED_BY) {
  195. body += "%0D%0A%0D%0A--%0D%0Apowered by jitsi.org";
  196. }
  197. window.open("mailto:?subject=" + subject + "&body=" + body, '_blank');
  198. }
  199. function callSipButtonClicked()
  200. {
  201. var defaultNumber
  202. = config.defaultSipNumber ? config.defaultSipNumber : '';
  203. messageHandler.openTwoButtonDialog(null,
  204. '<h2>Enter SIP number</h2>' +
  205. '<input id="sipNumber" type="text"' +
  206. ' value="' + defaultNumber + '" autofocus>',
  207. false,
  208. "Dial",
  209. function (e, v, m, f) {
  210. if (v) {
  211. var numberInput = document.getElementById('sipNumber');
  212. if (numberInput.value) {
  213. APP.xmpp.dial(numberInput.value, 'fromnumber',
  214. UI.getRoomName(), sharedKey);
  215. }
  216. }
  217. },
  218. function (event) {
  219. document.getElementById('sipNumber').focus();
  220. }
  221. );
  222. }
  223. var Toolbar = (function (my) {
  224. my.init = function (ui) {
  225. for(var k in buttonHandlers)
  226. $("#" + k).click(buttonHandlers[k]);
  227. UI = ui;
  228. // Update login info
  229. APP.xmpp.addListener(
  230. AuthenticationEvents.IDENTITY_UPDATED,
  231. function (authenticationEnabled, userIdentity) {
  232. var loggedIn = false;
  233. if (userIdentity) {
  234. loggedIn = true;
  235. }
  236. //FIXME: XMPP authentication need improvements for "live" login
  237. if (!APP.xmpp.isExternalAuthEnabled() && !loggedIn)
  238. {
  239. authenticationEnabled = false;
  240. }
  241. Toolbar.showAuthenticateButton(authenticationEnabled);
  242. if (authenticationEnabled) {
  243. Toolbar.setAuthenticatedIdentity(userIdentity);
  244. Toolbar.showLoginButton(!loggedIn);
  245. Toolbar.showLogoutButton(loggedIn);
  246. }
  247. }
  248. );
  249. },
  250. /**
  251. * Sets shared key
  252. * @param sKey the shared key
  253. */
  254. my.setSharedKey = function (sKey) {
  255. sharedKey = sKey;
  256. };
  257. my.authenticateClicked = function () {
  258. Authentication.focusAuthenticationWindow();
  259. // Get authentication URL
  260. if (!APP.xmpp.getMUCJoined()) {
  261. APP.xmpp.getLoginUrl(UI.getRoomName(), function (url) {
  262. // If conference has not been started yet - redirect to login page
  263. window.location.href = url;
  264. });
  265. } else {
  266. APP.xmpp.getPopupLoginUrl(UI.getRoomName(), function (url) {
  267. // Otherwise - open popup with authentication URL
  268. var authenticationWindow = Authentication.createAuthenticationWindow(
  269. function () {
  270. // On popup closed - retry room allocation
  271. APP.xmpp.allocateConferenceFocus(
  272. APP.UI.getRoomName(),
  273. function () { console.info("AUTH DONE"); }
  274. );
  275. }, url);
  276. if (!authenticationWindow) {
  277. messageHandler.openMessageDialog(
  278. null, "Your browser is blocking popup windows from this site." +
  279. " Please enable popups in your browser security settings" +
  280. " and try again.");
  281. }
  282. });
  283. }
  284. };
  285. /**
  286. * Updates the room invite url.
  287. */
  288. my.updateRoomUrl = function (newRoomUrl) {
  289. roomUrl = newRoomUrl;
  290. // If the invite dialog has been already opened we update the information.
  291. var inviteLink = document.getElementById('inviteLinkRef');
  292. if (inviteLink) {
  293. inviteLink.value = roomUrl;
  294. inviteLink.select();
  295. document.getElementById('jqi_state0_buttonInvite').disabled = false;
  296. }
  297. };
  298. /**
  299. * Disables and enables some of the buttons.
  300. */
  301. my.setupButtonsFromConfig = function () {
  302. if (config.disablePrezi)
  303. {
  304. $("#prezi_button").css({display: "none"});
  305. }
  306. };
  307. /**
  308. * Opens the lock room dialog.
  309. */
  310. my.openLockDialog = function () {
  311. // Only the focus is able to set a shared key.
  312. if (!APP.xmpp.isModerator()) {
  313. if (sharedKey) {
  314. messageHandler.openMessageDialog(null,
  315. "This conversation is currently protected by" +
  316. " a password. Only the owner of the conference" +
  317. " could set a password.",
  318. false,
  319. "Password");
  320. } else {
  321. messageHandler.openMessageDialog(null,
  322. "This conversation isn't currently protected by" +
  323. " a password. Only the owner of the conference" +
  324. " could set a password.",
  325. false,
  326. "Password");
  327. }
  328. } else {
  329. if (sharedKey) {
  330. messageHandler.openTwoButtonDialog(null,
  331. "Are you sure you would like to remove your password?",
  332. false,
  333. "Remove",
  334. function (e, v) {
  335. if (v) {
  336. Toolbar.setSharedKey('');
  337. lockRoom(false);
  338. }
  339. });
  340. } else {
  341. messageHandler.openTwoButtonDialog(null,
  342. '<h2>Set a password to lock your room</h2>' +
  343. '<input id="lockKey" type="text"' +
  344. 'placeholder="your password" autofocus>',
  345. false,
  346. "Save",
  347. function (e, v) {
  348. if (v) {
  349. var lockKey = document.getElementById('lockKey');
  350. if (lockKey.value) {
  351. Toolbar.setSharedKey(UIUtil.escapeHtml(lockKey.value));
  352. lockRoom(true);
  353. }
  354. }
  355. },
  356. function () {
  357. document.getElementById('lockKey').focus();
  358. }
  359. );
  360. }
  361. }
  362. };
  363. /**
  364. * Opens the invite link dialog.
  365. */
  366. my.openLinkDialog = function () {
  367. var inviteLink;
  368. if (roomUrl === null) {
  369. inviteLink = "Your conference is currently being created...";
  370. } else {
  371. inviteLink = encodeURI(roomUrl);
  372. }
  373. messageHandler.openTwoButtonDialog(
  374. "Share this link with everyone you want to invite",
  375. '<input id="inviteLinkRef" type="text" value="' +
  376. inviteLink + '" onclick="this.select();" readonly>',
  377. false,
  378. "Invite",
  379. function (e, v) {
  380. if (v) {
  381. if (roomUrl) {
  382. inviteParticipants();
  383. }
  384. }
  385. },
  386. function () {
  387. if (roomUrl) {
  388. document.getElementById('inviteLinkRef').select();
  389. } else {
  390. document.getElementById('jqi_state0_buttonInvite')
  391. .disabled = true;
  392. }
  393. }
  394. );
  395. };
  396. /**
  397. * Opens the settings dialog.
  398. */
  399. my.openSettingsDialog = function () {
  400. messageHandler.openTwoButtonDialog(
  401. '<h2>Configure your conference</h2>' +
  402. '<input type="checkbox" id="initMuted">' +
  403. 'Participants join muted<br/>' +
  404. '<input type="checkbox" id="requireNicknames">' +
  405. 'Require nicknames<br/><br/>' +
  406. 'Set a password to lock your room:' +
  407. '<input id="lockKey" type="text" placeholder="your password"' +
  408. 'autofocus>',
  409. null,
  410. false,
  411. "Save",
  412. function () {
  413. document.getElementById('lockKey').focus();
  414. },
  415. function (e, v) {
  416. if (v) {
  417. if ($('#initMuted').is(":checked")) {
  418. // it is checked
  419. }
  420. if ($('#requireNicknames').is(":checked")) {
  421. // it is checked
  422. }
  423. /*
  424. var lockKey = document.getElementById('lockKey');
  425. if (lockKey.value) {
  426. setSharedKey(lockKey.value);
  427. lockRoom(true);
  428. }
  429. */
  430. }
  431. }
  432. );
  433. };
  434. /**
  435. * Toggles the application in and out of full screen mode
  436. * (a.k.a. presentation mode in Chrome).
  437. */
  438. my.toggleFullScreen = function () {
  439. var fsElement = document.documentElement;
  440. if (!document.mozFullScreen && !document.webkitIsFullScreen) {
  441. //Enter Full Screen
  442. if (fsElement.mozRequestFullScreen) {
  443. fsElement.mozRequestFullScreen();
  444. }
  445. else {
  446. fsElement.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
  447. }
  448. } else {
  449. //Exit Full Screen
  450. if (document.mozCancelFullScreen) {
  451. document.mozCancelFullScreen();
  452. } else {
  453. document.webkitCancelFullScreen();
  454. }
  455. }
  456. };
  457. /**
  458. * Unlocks the lock button state.
  459. */
  460. my.unlockLockButton = function () {
  461. if ($("#lockIcon").hasClass("icon-security-locked"))
  462. UIUtil.buttonClick("#lockIcon", "icon-security icon-security-locked");
  463. };
  464. /**
  465. * Updates the lock button state to locked.
  466. */
  467. my.lockLockButton = function () {
  468. if ($("#lockIcon").hasClass("icon-security"))
  469. UIUtil.buttonClick("#lockIcon", "icon-security icon-security-locked");
  470. };
  471. /**
  472. * Shows or hides authentication button
  473. * @param show <tt>true</tt> to show or <tt>false</tt> to hide
  474. */
  475. my.showAuthenticateButton = function (show) {
  476. if (show) {
  477. $('#authentication').css({display: "inline"});
  478. }
  479. else {
  480. $('#authentication').css({display: "none"});
  481. }
  482. };
  483. // Shows or hides the 'recording' button.
  484. my.showRecordingButton = function (show) {
  485. if (!config.enableRecording) {
  486. return;
  487. }
  488. if (show) {
  489. $('#recording').css({display: "inline"});
  490. }
  491. else {
  492. $('#recording').css({display: "none"});
  493. }
  494. };
  495. // Sets the state of the recording button
  496. my.setRecordingButtonState = function (isRecording) {
  497. if (isRecording) {
  498. $('#recordButton').removeClass("icon-recEnable");
  499. $('#recordButton').addClass("icon-recEnable active");
  500. } else {
  501. $('#recordButton').removeClass("icon-recEnable active");
  502. $('#recordButton').addClass("icon-recEnable");
  503. }
  504. };
  505. // Shows or hides SIP calls button
  506. my.showSipCallButton = function (show) {
  507. if (APP.xmpp.isSipGatewayEnabled() && show) {
  508. $('#sipCallButton').css({display: "inline-block"});
  509. } else {
  510. $('#sipCallButton').css({display: "none"});
  511. }
  512. };
  513. /**
  514. * Displays user authenticated identity name(login).
  515. * @param authIdentity identity name to be displayed.
  516. */
  517. my.setAuthenticatedIdentity = function (authIdentity) {
  518. if (authIdentity) {
  519. $('#toolbar_auth_identity').css({display: "list-item"});
  520. $('#toolbar_auth_identity').text(authIdentity);
  521. } else {
  522. $('#toolbar_auth_identity').css({display: "none"});
  523. }
  524. };
  525. /**
  526. * Shows/hides login button.
  527. * @param show <tt>true</tt> to show
  528. */
  529. my.showLoginButton = function (show) {
  530. if (show) {
  531. $('#toolbar_button_login').css({display: "list-item"});
  532. } else {
  533. $('#toolbar_button_login').css({display: "none"});
  534. }
  535. };
  536. /**
  537. * Shows/hides logout button.
  538. * @param show <tt>true</tt> to show
  539. */
  540. my.showLogoutButton = function (show) {
  541. if (show) {
  542. $('#toolbar_button_logout').css({display: "list-item"});
  543. } else {
  544. $('#toolbar_button_logout').css({display: "none"});
  545. }
  546. };
  547. /**
  548. * Sets the state of the button. The button has blue glow if desktop
  549. * streaming is active.
  550. * @param active the state of the desktop streaming.
  551. */
  552. my.changeDesktopSharingButtonState = function (active) {
  553. var button = $("#desktopsharing > a");
  554. if (active)
  555. {
  556. button.addClass("glow");
  557. }
  558. else
  559. {
  560. button.removeClass("glow");
  561. }
  562. };
  563. return my;
  564. }(Toolbar || {}));
  565. module.exports = Toolbar;