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

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