Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

Toolbar.js 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  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_dialpad": function () {
  56. return dialpadButtonClicked();
  57. },
  58. "toolbar_button_settings": function () {
  59. PanelToggler.toggleSettingsMenu();
  60. },
  61. "toolbar_button_hangup": function () {
  62. return hangup();
  63. },
  64. "toolbar_button_login": function () {
  65. Toolbar.authenticateClicked();
  66. },
  67. "toolbar_button_logout": function () {
  68. // Ask for confirmation
  69. messageHandler.openTwoButtonDialog(
  70. "dialog.logoutTitle",
  71. null,
  72. "dialog.logoutQuestion",
  73. null,
  74. false,
  75. "dialog.Yes",
  76. function (evt, yes) {
  77. if (yes) {
  78. APP.xmpp.logout(function (url) {
  79. if (url) {
  80. window.location.href = url;
  81. } else {
  82. hangup();
  83. }
  84. });
  85. }
  86. });
  87. }
  88. };
  89. function hangup() {
  90. APP.xmpp.disposeConference();
  91. if(config.enableWelcomePage)
  92. {
  93. setTimeout(function()
  94. {
  95. window.localStorage.welcomePageDisabled = false;
  96. window.location.pathname = "/";
  97. }, 10000);
  98. }
  99. var title = APP.translation.generateTranslatonHTML(
  100. "dialog.sessTerminated");
  101. var msg = APP.translation.generateTranslatonHTML(
  102. "dialog.hungUp");
  103. var button = APP.translation.generateTranslatonHTML(
  104. "dialog.joinAgain");
  105. var buttons = [];
  106. buttons.push({title: button, value: true});
  107. UI.messageHandler.openDialog(
  108. title,
  109. msg,
  110. true,
  111. buttons,
  112. function(event, value, message, formVals)
  113. {
  114. window.location.reload();
  115. return false;
  116. }
  117. );
  118. }
  119. /**
  120. * Starts or stops the recording for the conference.
  121. */
  122. function toggleRecording() {
  123. APP.xmpp.toggleRecording(function (callback) {
  124. var msg = APP.translation.generateTranslatonHTML(
  125. "dialog.recordingToken");
  126. var token = APP.translation.translateString("dialog.token");
  127. APP.UI.messageHandler.openTwoButtonDialog(null, null, null,
  128. '<h2>' + msg + '</h2>' +
  129. '<input name="recordingToken" type="text" ' +
  130. ' data-i18n="[placeholder]dialog.token" ' +
  131. 'placeholder="' + token + '" autofocus>',
  132. false,
  133. "dialog.Save",
  134. function (e, v, m, f) {
  135. if (v) {
  136. var token = f.recordingToken;
  137. if (token) {
  138. callback(UIUtil.escapeHtml(token));
  139. }
  140. }
  141. },
  142. null,
  143. function () { },
  144. ':input:first'
  145. );
  146. }, Toolbar.setRecordingButtonState, Toolbar.setRecordingButtonState);
  147. }
  148. /**
  149. * Locks / unlocks the room.
  150. */
  151. function lockRoom(lock) {
  152. var currentSharedKey = '';
  153. if (lock)
  154. currentSharedKey = sharedKey;
  155. APP.xmpp.lockRoom(currentSharedKey, function (res) {
  156. // password is required
  157. if (sharedKey)
  158. {
  159. console.log('set room password');
  160. Toolbar.lockLockButton();
  161. }
  162. else
  163. {
  164. console.log('removed room password');
  165. Toolbar.unlockLockButton();
  166. }
  167. }, function (err) {
  168. console.warn('setting password failed', err);
  169. messageHandler.showError("dialog.lockTitle",
  170. "dialog.lockMessage");
  171. Toolbar.setSharedKey('');
  172. }, function () {
  173. console.warn('room passwords not supported');
  174. messageHandler.showError("dialog.warning",
  175. "dialog.passwordNotSupported");
  176. Toolbar.setSharedKey('');
  177. });
  178. };
  179. /**
  180. * Invite participants to conference.
  181. */
  182. function inviteParticipants() {
  183. if (roomUrl === null)
  184. return;
  185. var sharedKeyText = "";
  186. if (sharedKey && sharedKey.length > 0) {
  187. sharedKeyText =
  188. APP.translation.translateString("email.sharedKey",
  189. {sharedKey: sharedKey});
  190. sharedKeyText = sharedKeyText.replace(/\n/g, "%0D%0A");
  191. }
  192. var supportedBrowsers = "Chromium, Google Chrome " +
  193. APP.translation.translateString("email.and") + " Opera";
  194. var conferenceName = roomUrl.substring(roomUrl.lastIndexOf('/') + 1);
  195. var subject = APP.translation.translateString("email.subject",
  196. {appName:interfaceConfig.APP_NAME, conferenceName: conferenceName});
  197. var body = APP.translation.translateString("email.body",
  198. {appName:interfaceConfig.APP_NAME, sharedKeyText: sharedKeyText,
  199. roomUrl: roomUrl, supportedBrowsers: supportedBrowsers});
  200. body = body.replace(/\n/g, "%0D%0A");
  201. if (window.localStorage.displayname) {
  202. body += "%0D%0A%0D%0A" + window.localStorage.displayname;
  203. }
  204. if (interfaceConfig.INVITATION_POWERED_BY) {
  205. body += "%0D%0A%0D%0A--%0D%0Apowered by jitsi.org";
  206. }
  207. window.open("mailto:?subject=" + subject + "&body=" + body, '_blank');
  208. }
  209. function dialpadButtonClicked()
  210. {
  211. //TODO show the dialpad window
  212. }
  213. function callSipButtonClicked()
  214. {
  215. var defaultNumber
  216. = config.defaultSipNumber ? config.defaultSipNumber : '';
  217. var sipMsg = APP.translation.generateTranslatonHTML(
  218. "dialog.sipMsg");
  219. messageHandler.openTwoButtonDialog(null, null, null,
  220. '<h2>' + sipMsg + '</h2>' +
  221. '<input name="sipNumber" type="text"' +
  222. ' value="' + defaultNumber + '" autofocus>',
  223. false,
  224. "dialog.Dial",
  225. function (e, v, m, f) {
  226. if (v) {
  227. var numberInput = f.sipNumber;
  228. if (numberInput) {
  229. APP.xmpp.dial(
  230. numberInput, 'fromnumber', UI.getRoomName(), sharedKey);
  231. }
  232. }
  233. },
  234. null, null, ':input:first'
  235. );
  236. }
  237. var Toolbar = (function (my) {
  238. my.init = function (ui) {
  239. for(var k in buttonHandlers)
  240. $("#" + k).click(buttonHandlers[k]);
  241. UI = ui;
  242. // Update login info
  243. APP.xmpp.addListener(
  244. AuthenticationEvents.IDENTITY_UPDATED,
  245. function (authenticationEnabled, userIdentity) {
  246. var loggedIn = false;
  247. if (userIdentity) {
  248. loggedIn = true;
  249. }
  250. Toolbar.showAuthenticateButton(authenticationEnabled);
  251. if (authenticationEnabled) {
  252. Toolbar.setAuthenticatedIdentity(userIdentity);
  253. Toolbar.showLoginButton(!loggedIn);
  254. Toolbar.showLogoutButton(loggedIn);
  255. }
  256. }
  257. );
  258. },
  259. /**
  260. * Sets shared key
  261. * @param sKey the shared key
  262. */
  263. my.setSharedKey = function (sKey) {
  264. sharedKey = sKey;
  265. };
  266. my.authenticateClicked = function () {
  267. Authentication.focusAuthenticationWindow();
  268. if (!APP.xmpp.isExternalAuthEnabled()) {
  269. Authentication.xmppAuthenticate();
  270. return;
  271. }
  272. // Get authentication URL
  273. if (!APP.xmpp.getMUCJoined()) {
  274. APP.xmpp.getLoginUrl(UI.getRoomName(), function (url) {
  275. // If conference has not been started yet - redirect to login page
  276. window.location.href = url;
  277. });
  278. } else {
  279. APP.xmpp.getPopupLoginUrl(UI.getRoomName(), function (url) {
  280. // Otherwise - open popup with authentication URL
  281. var authenticationWindow = Authentication.createAuthenticationWindow(
  282. function () {
  283. // On popup closed - retry room allocation
  284. APP.xmpp.allocateConferenceFocus(
  285. APP.UI.getRoomName(),
  286. function () { console.info("AUTH DONE"); }
  287. );
  288. }, url);
  289. if (!authenticationWindow) {
  290. messageHandler.openMessageDialog(
  291. null, "dialog.popupError");
  292. }
  293. });
  294. }
  295. };
  296. /**
  297. * Updates the room invite url.
  298. */
  299. my.updateRoomUrl = function (newRoomUrl) {
  300. roomUrl = newRoomUrl;
  301. // If the invite dialog has been already opened we update the information.
  302. var inviteLink = document.getElementById('inviteLinkRef');
  303. if (inviteLink) {
  304. inviteLink.value = roomUrl;
  305. inviteLink.select();
  306. $('#inviteLinkRef').parent()
  307. .find('button[value=true]').prop('disabled', false);
  308. }
  309. };
  310. /**
  311. * Disables and enables some of the buttons.
  312. */
  313. my.setupButtonsFromConfig = function () {
  314. if (config.disablePrezi)
  315. {
  316. $("#prezi_button").css({display: "none"});
  317. }
  318. };
  319. /**
  320. * Opens the lock room dialog.
  321. */
  322. my.openLockDialog = function () {
  323. // Only the focus is able to set a shared key.
  324. if (!APP.xmpp.isModerator()) {
  325. if (sharedKey) {
  326. messageHandler.openMessageDialog(null,
  327. "dialog.passwordError");
  328. } else {
  329. messageHandler.openMessageDialog(null, "dialog.passwordError2");
  330. }
  331. } else {
  332. if (sharedKey) {
  333. messageHandler.openTwoButtonDialog(null, null,
  334. "dialog.passwordCheck",
  335. null,
  336. false,
  337. "dialog.Remove",
  338. function (e, v) {
  339. if (v) {
  340. Toolbar.setSharedKey('');
  341. lockRoom(false);
  342. }
  343. });
  344. } else {
  345. var msg = APP.translation.generateTranslatonHTML(
  346. "dialog.passwordMsg");
  347. var yourPassword = APP.translation.translateString(
  348. "dialog.yourPassword");
  349. messageHandler.openTwoButtonDialog(null, null, null,
  350. '<h2>' + msg + '</h2>' +
  351. '<input name="lockKey" type="text"' +
  352. ' data-i18n="[placeholder]dialog.yourPassword" ' +
  353. 'placeholder="' + yourPassword + '" autofocus>',
  354. false,
  355. "dialog.Save",
  356. function (e, v, m, f) {
  357. if (v) {
  358. var lockKey = f.lockKey;
  359. if (lockKey) {
  360. Toolbar.setSharedKey(
  361. UIUtil.escapeHtml(lockKey));
  362. lockRoom(true);
  363. }
  364. }
  365. },
  366. null, null, 'input:first'
  367. );
  368. }
  369. }
  370. };
  371. /**
  372. * Opens the invite link dialog.
  373. */
  374. my.openLinkDialog = function () {
  375. var inviteAttreibutes;
  376. if (roomUrl === null) {
  377. inviteAttreibutes = 'data-i18n="[value]roomUrlDefaultMsg" value="' +
  378. APP.translation.translateString("roomUrlDefaultMsg") + '"';
  379. } else {
  380. inviteAttreibutes = "value=\"" + encodeURI(roomUrl) + "\"";
  381. }
  382. messageHandler.openTwoButtonDialog("dialog.shareLink",
  383. null, null,
  384. '<input id="inviteLinkRef" type="text" ' +
  385. inviteAttreibutes + ' onclick="this.select();" readonly>',
  386. false,
  387. "dialog.Invite",
  388. function (e, v) {
  389. if (v) {
  390. if (roomUrl) {
  391. inviteParticipants();
  392. }
  393. }
  394. },
  395. function (event) {
  396. if (roomUrl) {
  397. document.getElementById('inviteLinkRef').select();
  398. } else {
  399. if (event && event.target)
  400. $(event.target)
  401. .find('button[value=true]').prop('disabled', true);
  402. }
  403. }
  404. );
  405. };
  406. /**
  407. * Opens the settings dialog.
  408. * FIXME: not used ?
  409. */
  410. my.openSettingsDialog = function () {
  411. var settings1 = APP.translation.generateTranslatonHTML(
  412. "dialog.settings1");
  413. var settings2 = APP.translation.generateTranslatonHTML(
  414. "dialog.settings2");
  415. var settings3 = APP.translation.generateTranslatonHTML(
  416. "dialog.settings3");
  417. var yourPassword = APP.translation.translateString(
  418. "dialog.yourPassword");
  419. messageHandler.openTwoButtonDialog(null,
  420. '<h2>' + settings1 + '</h2>' +
  421. '<input type="checkbox" id="initMuted">' +
  422. settings2 + '<br/>' +
  423. '<input type="checkbox" id="requireNicknames">' +
  424. settings3 +
  425. '<input id="lockKey" type="text" placeholder="' + yourPassword +
  426. '" data-i18n="[placeholder]dialog.yourPassword" autofocus>',
  427. null,
  428. null,
  429. false,
  430. "dialog.Save",
  431. function () {
  432. document.getElementById('lockKey').focus();
  433. },
  434. function (e, v) {
  435. if (v) {
  436. if ($('#initMuted').is(":checked")) {
  437. // it is checked
  438. }
  439. if ($('#requireNicknames').is(":checked")) {
  440. // it is checked
  441. }
  442. /*
  443. var lockKey = document.getElementById('lockKey');
  444. if (lockKey.value) {
  445. setSharedKey(lockKey.value);
  446. lockRoom(true);
  447. }
  448. */
  449. }
  450. }
  451. );
  452. };
  453. /**
  454. * Toggles the application in and out of full screen mode
  455. * (a.k.a. presentation mode in Chrome).
  456. */
  457. my.toggleFullScreen = function () {
  458. var fsElement = document.documentElement;
  459. if (!document.mozFullScreen && !document.webkitIsFullScreen) {
  460. //Enter Full Screen
  461. if (fsElement.mozRequestFullScreen) {
  462. fsElement.mozRequestFullScreen();
  463. }
  464. else {
  465. fsElement.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
  466. }
  467. } else {
  468. //Exit Full Screen
  469. if (document.mozCancelFullScreen) {
  470. document.mozCancelFullScreen();
  471. } else {
  472. document.webkitCancelFullScreen();
  473. }
  474. }
  475. };
  476. /**
  477. * Unlocks the lock button state.
  478. */
  479. my.unlockLockButton = function () {
  480. if ($("#lockIcon").hasClass("icon-security-locked"))
  481. UIUtil.buttonClick("#lockIcon", "icon-security icon-security-locked");
  482. };
  483. /**
  484. * Updates the lock button state to locked.
  485. */
  486. my.lockLockButton = function () {
  487. if ($("#lockIcon").hasClass("icon-security"))
  488. UIUtil.buttonClick("#lockIcon", "icon-security icon-security-locked");
  489. };
  490. /**
  491. * Shows or hides authentication button
  492. * @param show <tt>true</tt> to show or <tt>false</tt> to hide
  493. */
  494. my.showAuthenticateButton = function (show) {
  495. if (show) {
  496. $('#authentication').css({display: "inline"});
  497. }
  498. else {
  499. $('#authentication').css({display: "none"});
  500. }
  501. };
  502. // Shows or hides the 'recording' button.
  503. my.showRecordingButton = function (show) {
  504. if (!config.enableRecording) {
  505. return;
  506. }
  507. if (show) {
  508. $('#recording').css({display: "inline"});
  509. }
  510. else {
  511. $('#recording').css({display: "none"});
  512. }
  513. };
  514. // Sets the state of the recording button
  515. my.setRecordingButtonState = function (isRecording) {
  516. var selector = $('#recordButton');
  517. if (isRecording) {
  518. selector.removeClass("icon-recEnable");
  519. selector.addClass("icon-recEnable active");
  520. } else {
  521. selector.removeClass("icon-recEnable active");
  522. selector.addClass("icon-recEnable");
  523. }
  524. };
  525. // Shows or hides SIP calls button
  526. my.showSipCallButton = function (show) {
  527. if (APP.xmpp.isSipGatewayEnabled() && show) {
  528. $('#sipCallButton').css({display: "inline-block"});
  529. } else {
  530. $('#sipCallButton').css({display: "none"});
  531. }
  532. };
  533. // Shows or hides the dialpad button
  534. my.showDialPadButton = function (show) {
  535. if (show) {
  536. $('#dialPadButton').css({display: "inline-block"});
  537. } else {
  538. $('#dialPadButton').css({display: "none"});
  539. }
  540. };
  541. /**
  542. * Displays user authenticated identity name(login).
  543. * @param authIdentity identity name to be displayed.
  544. */
  545. my.setAuthenticatedIdentity = function (authIdentity) {
  546. if (authIdentity) {
  547. var selector = $('#toolbar_auth_identity');
  548. selector.css({display: "list-item"});
  549. selector.text(authIdentity);
  550. } else {
  551. $('#toolbar_auth_identity').css({display: "none"});
  552. }
  553. };
  554. /**
  555. * Shows/hides login button.
  556. * @param show <tt>true</tt> to show
  557. */
  558. my.showLoginButton = function (show) {
  559. if (show) {
  560. $('#toolbar_button_login').css({display: "list-item"});
  561. } else {
  562. $('#toolbar_button_login').css({display: "none"});
  563. }
  564. };
  565. /**
  566. * Shows/hides logout button.
  567. * @param show <tt>true</tt> to show
  568. */
  569. my.showLogoutButton = function (show) {
  570. if (show) {
  571. $('#toolbar_button_logout').css({display: "list-item"});
  572. } else {
  573. $('#toolbar_button_logout').css({display: "none"});
  574. }
  575. };
  576. /**
  577. * Sets the state of the button. The button has blue glow if desktop
  578. * streaming is active.
  579. * @param active the state of the desktop streaming.
  580. */
  581. my.changeDesktopSharingButtonState = function (active) {
  582. var button = $("#desktopsharing > a");
  583. if (active)
  584. {
  585. button.addClass("glow");
  586. }
  587. else
  588. {
  589. button.removeClass("glow");
  590. }
  591. };
  592. return my;
  593. }(Toolbar || {}));
  594. module.exports = Toolbar;