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

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